remove HTML archives pages, leave only the sitemaps.

This commit is contained in:
fiatjaf
2024-06-12 15:30:41 -03:00
parent a7d29b151a
commit 1eb3c45755
4 changed files with 21 additions and 114 deletions

View File

@@ -11,17 +11,13 @@ import (
"github.com/nbd-wtf/go-nostr/nip19"
)
const (
NPUBS_ARCHIVE = iota
RELAYS_ARCHIVE = iota
)
func renderArchive(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.URL.Path, "@.", r.Header.Get("user-agent"))
code := r.URL.Path[1:]
hostname := code[2:]
resultsPerPage := 50
isSitemap := false
if strings.HasSuffix(hostname, ".xml") {
isSitemap = true
resultsPerPage = 5000
}
lastIndex := strings.LastIndex(r.URL.Path, "/")
page := 1
@@ -37,42 +33,29 @@ func renderArchive(w http.ResponseWriter, r *http.Request) {
prefix := ""
pathPrefix := ""
title := ""
area := ""
var area int
if strings.HasPrefix(r.URL.Path[1:], "npubs-archive") {
area = "npubs-archive"
} else if strings.HasPrefix(r.URL.Path[1:], "relays-archive") {
area = "relays-archive"
}
if area == "npubs-archive" {
area = NPUBS_ARCHIVE
prefix = "pa:"
pathPrefix = ""
title = "Nostr npubs archive"
} else {
} else if strings.HasPrefix(r.URL.Path[1:], "relays-archive") {
area = RELAYS_ARCHIVE
prefix = "ra:"
pathPrefix = "r/"
title = "Nostr relays archive"
}
keys := cache.GetPaginatedKeys(prefix, page, resultsPerPage)
keys := cache.GetPaginatedKeys(prefix, page, 5000)
data := []string{}
for i := 0; i < len(keys); i++ {
if area == "npubs-archive" {
switch area {
case NPUBS_ARCHIVE:
npub, _ := nip19.EncodePublicKey(keys[i][3:])
data = append(data, npub)
} else {
case RELAYS_ARCHIVE:
data = append(data, trimProtocol(keys[i][3:]))
}
}
prevPage := page - 1
nextPage := page + 1
if len(keys) == 0 {
prevPage = 0
nextPage = 0
}
// Generate a random duration between 2 and 6 hours
minHours := 2
maxHours := 6
@@ -87,26 +70,12 @@ func renderArchive(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "max-age=60")
}
if !isSitemap {
archiveTemplate(ArchivePageParams{
HeadParams: HeadParams{IsProfile: false},
Title: title,
PathPrefix: pathPrefix,
Data: data,
ModifiedAt: modifiedAt,
PaginationUrl: area,
NextPage: nextPage,
PrevPage: prevPage,
}).Render(r.Context(), w)
} else {
w.Header().Add("content-type", "text/xml")
w.Write([]byte(XML_HEADER))
SitemapTemplate.Render(w, &SitemapPage{
Host: s.Domain,
ModifiedAt: modifiedAt,
PathPrefix: pathPrefix,
Data: data,
})
}
w.Header().Add("content-type", "text/xml")
w.Write([]byte(XML_HEADER))
SitemapTemplate.Render(w, &SitemapPage{
Host: s.Domain,
ModifiedAt: modifiedAt,
PathPrefix: pathPrefix,
Data: data,
})
}