sitemaps of sitemaps of profile sitemaps.

This commit is contained in:
fiatjaf
2024-06-16 16:27:24 -03:00
parent d7bdded88f
commit ab34bde883
6 changed files with 56 additions and 5 deletions

View File

@@ -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)

View File

@@ -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)
}

29
render_sitemap_index.go Normal file
View File

@@ -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,
})
}

View File

@@ -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

7
xml/sitemap-index.xml Normal file
View File

@@ -0,0 +1,7 @@
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{{- range $npub := .Npubs }}
<sitemap>
<loc>https://{{$.Host}}/{{$npub}}.xml</loc>
</sitemap>
{{- end}}
</sitemapindex>

View File

@@ -6,7 +6,7 @@
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
{{end}}
{{- end}}
{{if not (eq "" .RelayHostname)}}
<url>
<loc>https://{{.Host}}/r/{{.RelayHostname}}</loc>
@@ -14,7 +14,7 @@
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
{{end}}
{{- end}}
{{range $i, $ee := .LastNotes}}
<url>
<loc>https://{{$.Host}}/{{$ee.Nevent}}</loc>
@@ -22,7 +22,7 @@
<changefreq>never</changefreq>
<priority>0.5</priority>
</url>
{{end}}
{{- end}}
{{range $element := .Data }}
<url>
<loc>https://{{$.Host}}/{{$.PathPrefix}}{{$element}}</loc>
@@ -30,5 +30,5 @@
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
{{end}}
{{- end}}
</urlset>