add sitemap.xml
This commit is contained in:
1 parent
d856b03dde
commit
0d79b1fbc1
1 file changed
+32
@@ -398,6 +398,37 @@ func (s *Server) linuxHandler(w http.ResponseWriter, r *http.Request) {
|
||||
s.renderTemplate(w, "linux.html", data)
|
||||
}
|
||||
|
||||
// sitemapHandler serves the XML sitemap
|
||||
func (s *Server) sitemapHandler(w http.ResponseWriter, r *http.Request) {
|
||||
baseURL := "https://" + s.config.Domain
|
||||
pages := []struct {
|
||||
Path string
|
||||
Priority string
|
||||
ChangeFreq string
|
||||
}{
|
||||
{"/", "1.0", "weekly"},
|
||||
{"/diensten", "0.9", "monthly"},
|
||||
{"/linux", "0.8", "monthly"},
|
||||
{"/over-mij", "0.7", "monthly"},
|
||||
{"/contact", "0.5", "yearly"},
|
||||
}
|
||||
|
||||
var sb strings.Builder
|
||||
sb.WriteString(`<?xml version="1.0" encoding="UTF-8"?>` + "\n")
|
||||
sb.WriteString(`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">` + "\n")
|
||||
for _, p := range pages {
|
||||
sb.WriteString(" <url>\n")
|
||||
fmt.Fprintf(&sb, " <loc>%s%s</loc>\n", baseURL, p.Path)
|
||||
fmt.Fprintf(&sb, " <changefreq>%s</changefreq>\n", p.ChangeFreq)
|
||||
fmt.Fprintf(&sb, " <priority>%s</priority>\n", p.Priority)
|
||||
sb.WriteString(" </url>\n")
|
||||
}
|
||||
sb.WriteString(`</urlset>` + "\n")
|
||||
|
||||
w.Header().Set("Content-Type", "application/xml; charset=utf-8")
|
||||
w.Write([]byte(sb.String()))
|
||||
}
|
||||
|
||||
// setupRoutes configures all HTTP routes
|
||||
func (s *Server) setupRoutes() {
|
||||
// Static files
|
||||
@@ -414,6 +445,7 @@ func (s *Server) setupRoutes() {
|
||||
http.HandleFunc("/over-mij", s.aboutHandler)
|
||||
http.HandleFunc("/diensten", s.dienstenHandler)
|
||||
http.HandleFunc("/linux", s.linuxHandler)
|
||||
http.HandleFunc("/sitemap.xml", s.sitemapHandler)
|
||||
http.HandleFunc("/health", s.healthHandler)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user