diff --git a/archive.templ b/archive.templ
deleted file mode 100644
index 20c9c45..0000000
--- a/archive.templ
+++ /dev/null
@@ -1,48 +0,0 @@
-package main
-
-import "fmt"
-
-templ archiveTemplate(params ArchivePageParams) {
-
-
-
-
- { params.Title }
- @headCommonTemplate(params.HeadParams)
-
-
- @topTemplate(params.HeadParams)
-
-
-
-
-
-
{ params.Title }
-
-
- for _, v:= range params.Data {
-
- { v }
-
- }
-
-
-
-
-
- @footerTemplate()
-
-
-}
diff --git a/main.go b/main.go
index aeeec1d..07532a7 100644
--- a/main.go
+++ b/main.go
@@ -125,8 +125,6 @@ func main() {
mux.HandleFunc("/relays-archive.xml", renderArchive)
mux.HandleFunc("/npubs-archive.xml", renderArchive)
mux.HandleFunc("/services/oembed", renderOEmbed)
- mux.HandleFunc("/relays-archive/", renderArchive)
- mux.HandleFunc("/npubs-archive/", renderArchive)
mux.HandleFunc("/njump/image/", renderImage)
mux.HandleFunc("/njump/proxy/", proxy)
mux.HandleFunc("/robots.txt", renderRobots)
diff --git a/pages.go b/pages.go
index e113ae7..c61a8af 100644
--- a/pages.go
+++ b/pages.go
@@ -92,18 +92,6 @@ type AboutParams struct {
HeadParams
}
-type ArchivePageParams struct {
- HeadParams
-
- Title string
- PathPrefix string
- Data []string
- ModifiedAt string
- PaginationUrl string
- NextPage int
- PrevPage int
-}
-
type EmbeddedNoteParams struct {
Content template.HTML
CreatedAt string
diff --git a/render_archive.go b/render_archive.go
index 77600e2..18960ec 100644
--- a/render_archive.go
+++ b/render_archive.go
@@ -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,
+ })
}