diff --git a/main.go b/main.go index 07532a7..53726f0 100644 --- a/main.go +++ b/main.go @@ -124,6 +124,7 @@ func main() { mux.Handle("/njump/static/", http.StripPrefix("/njump/", http.FileServer(http.FS(static)))) mux.HandleFunc("/relays-archive.xml", renderArchive) mux.HandleFunc("/npubs-archive.xml", renderArchive) + mux.HandleFunc("/npubs-sitemaps.xml", renderSitemapIndex) mux.HandleFunc("/services/oembed", renderOEmbed) mux.HandleFunc("/njump/image/", renderImage) mux.HandleFunc("/njump/proxy/", proxy) diff --git a/render_robots.go b/render_robots.go index 8f39dd5..e2d08b6 100644 --- a/render_robots.go +++ b/render_robots.go @@ -11,6 +11,7 @@ func renderRobots(w http.ResponseWriter, r *http.Request) { Allow: / Sitemap: https://%s/npubs-archive.xml +Sitemap: https://%s/npubs-sitemaps.xml Sitemap: https://%s/relays-archive.xml -`, s.Domain, s.Domain) +`, s.Domain, s.Domain, s.Domain) } diff --git a/render_sitemap_index.go b/render_sitemap_index.go new file mode 100644 index 0000000..d48670f --- /dev/null +++ b/render_sitemap_index.go @@ -0,0 +1,29 @@ +package main + +import ( + "net/http" + + "github.com/nbd-wtf/go-nostr/nip19" +) + +func renderSitemapIndex(w http.ResponseWriter, r *http.Request) { + npubs := make([]string, 0, 5000) + keys := cache.GetPaginatedKeys("pa:", 1, 5000) + for _, key := range keys { + npub, _ := nip19.EncodePublicKey(key[3:]) + npubs = append(npubs, npub) + } + + if len(npubs) != 0 { + w.Header().Set("Cache-Control", "max-age=3600") + } else { + w.Header().Set("Cache-Control", "max-age=60") + } + + w.Header().Add("content-type", "text/xml") + w.Write([]byte(XML_HEADER)) + SitemapIndexTemplate.Render(w, &SitemapIndexPage{ + Host: s.Domain, + Npubs: npubs, + }) +} diff --git a/xml-pages.go b/xml-pages.go index b102bdd..ced2e50 100644 --- a/xml-pages.go +++ b/xml-pages.go @@ -34,6 +34,19 @@ type SitemapPage struct { func (*SitemapPage) TemplateText() string { return tmplSitemap } +var ( + //go:embed xml/sitemap-index.xml + tmplSitemapIndex string + SitemapIndexTemplate = tmpl.MustCompile(&SitemapIndexPage{}) +) + +type SitemapIndexPage struct { + Host string + Npubs []string +} + +func (*SitemapIndexPage) TemplateText() string { return tmplSitemapIndex } + var ( //go:embed xml/rss.xml tmplRSS string diff --git a/xml/sitemap-index.xml b/xml/sitemap-index.xml new file mode 100644 index 0000000..dfa6a8d --- /dev/null +++ b/xml/sitemap-index.xml @@ -0,0 +1,7 @@ + +{{- range $npub := .Npubs }} + + https://{{$.Host}}/{{$npub}}.xml + +{{- end}} + diff --git a/xml/sitemap.xml b/xml/sitemap.xml index ae17b15..d3d1f75 100644 --- a/xml/sitemap.xml +++ b/xml/sitemap.xml @@ -6,7 +6,7 @@ daily 0.8 -{{end}} +{{- end}} {{if not (eq "" .RelayHostname)}} https://{{.Host}}/r/{{.RelayHostname}} @@ -14,7 +14,7 @@ daily 0.8 -{{end}} +{{- end}} {{range $i, $ee := .LastNotes}} https://{{$.Host}}/{{$ee.Nevent}} @@ -22,7 +22,7 @@ never 0.5 -{{end}} +{{- end}} {{range $element := .Data }} https://{{$.Host}}/{{$.PathPrefix}}{{$element}} @@ -30,5 +30,5 @@ daily 0.5 -{{end}} +{{- end}}