diff --git a/main.go b/main.go index 1e597a8..619ac39 100644 --- a/main.go +++ b/main.go @@ -35,6 +35,7 @@ var ( func updateArchives(ctx context.Context) { for { loadNpubsArchive(ctx) + loadRelaysArchive(ctx) // Wait for 24 hours before executing the function again time.Sleep(24 * time.Hour) } @@ -79,7 +80,8 @@ func main() { http.HandleFunc("/njump/image/", generate) http.HandleFunc("/njump/proxy/", proxy) http.Handle("/njump/static/", http.StripPrefix("/njump/", http.FileServer(http.FS(static)))) - http.HandleFunc("/npubs-archive/", renderProfilesArchive) + http.HandleFunc("/npubs-archive/", renderArchive) + http.HandleFunc("/relays-archive/", renderArchive) http.HandleFunc("/", render) log.Print("listening at http://0.0.0.0:" + s.Port) diff --git a/render_profiles_archive.go b/render_archive.go similarity index 52% rename from render_profiles_archive.go rename to render_archive.go index f2851f0..acb61df 100644 --- a/render_profiles_archive.go +++ b/render_archive.go @@ -9,8 +9,8 @@ import ( "github.com/nbd-wtf/go-nostr/nip19" ) -func renderProfilesArchive(w http.ResponseWriter, r *http.Request) { - resultsPerPage := 100 +func renderArchive(w http.ResponseWriter, r *http.Request) { + resultsPerPage := 50 lastIndex := strings.LastIndex(r.URL.Path, "/") page := 1 if lastIndex != -1 { @@ -23,11 +23,26 @@ func renderProfilesArchive(w http.ResponseWriter, r *http.Request) { } } - keys := cache.GetPaginatedkeys("pa", page, resultsPerPage) - npubs := []string{} + prefix := "" + title := "" + area := strings.Split(r.URL.Path[1:], "/")[0] + if area == "npubs-archive" { + prefix = "pa" + title = "Nostr npubs archive" + } else { + prefix = "ra" + title = "Nostr relays archive" + } + + keys := cache.GetPaginatedkeys(prefix, page, resultsPerPage) + data := []string{} for i := 0; i < len(keys); i++ { - npub, _ := nip19.EncodePublicKey(keys[i]) - npubs = append(npubs, npub) + if area == "npubs-archive" { + npub, _ := nip19.EncodePublicKey(keys[i]) + data = append(data, npub) + } else { + data = append(data, keys[i]) + } } prevPage := page - 1 @@ -38,12 +53,14 @@ func renderProfilesArchive(w http.ResponseWriter, r *http.Request) { } params := map[string]any{ + "title": title, + "data": data, + "pagination_url": area , "nextPage": fmt.Sprint(nextPage), "prevPage": fmt.Sprint(prevPage), - "data": npubs, } - w.Header().Set("Cache-Control", "max-age=604800") + w.Header().Set("Cache-Control", "max-age=86400") if err := tmpl.ExecuteTemplate(w, "archive.html", params); err != nil { log.Error().Err(err).Msg("error rendering") diff --git a/templates/archive.html b/templates/archive.html index b2a61c6..a675910 100644 --- a/templates/archive.html +++ b/templates/archive.html @@ -2,7 +2,7 @@
-