mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 06:14:22 +01:00
sitemaps of sitemaps of profile sitemaps.
This commit is contained in:
1
main.go
1
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)
|
||||
|
||||
@@ -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
29
render_sitemap_index.go
Normal 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,
|
||||
})
|
||||
}
|
||||
13
xml-pages.go
13
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
|
||||
|
||||
7
xml/sitemap-index.xml
Normal file
7
xml/sitemap-index.xml
Normal 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>
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user