From f902beffd36f5eb07b305d0e9ba5a9faa21fb720 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Wed, 18 Aug 2021 14:47:31 +0200 Subject: [PATCH] Sitemap indices with LastMod --- sitemap.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sitemap.go b/sitemap.go index 97a497b..598a64f 100644 --- a/sitemap.go +++ b/sitemap.go @@ -5,6 +5,7 @@ import ( "database/sql" "encoding/xml" "net/http" + "time" "github.com/araddon/dateparse" "github.com/snabb/sitemap" @@ -23,9 +24,11 @@ func (a *goBlog) serveSitemap(w http.ResponseWriter, r *http.Request) { // Create sitemap sm := sitemap.NewSitemapIndex() // Add blog sitemap indices + now := time.Now().UTC() for _, bc := range a.cfg.Blogs { sm.Add(&sitemap.URL{ - Loc: a.getFullAddress(bc.getRelativePath(sitemapBlogPath)), + Loc: a.getFullAddress(bc.getRelativePath(sitemapBlogPath)), + LastMod: &now, }) } // Write sitemap @@ -37,14 +40,18 @@ func (a *goBlog) serveSitemapBlog(w http.ResponseWriter, r *http.Request) { sm := sitemap.NewSitemapIndex() // Add blog sitemaps b := r.Context().Value(blogKey).(string) + now := time.Now().UTC() sm.Add(&sitemap.URL{ - Loc: a.getFullAddress(a.getRelativePath(b, sitemapBlogFeaturesPath)), + Loc: a.getFullAddress(a.getRelativePath(b, sitemapBlogFeaturesPath)), + LastMod: &now, }) sm.Add(&sitemap.URL{ - Loc: a.getFullAddress(a.getRelativePath(b, sitemapBlogArchivesPath)), + Loc: a.getFullAddress(a.getRelativePath(b, sitemapBlogArchivesPath)), + LastMod: &now, }) sm.Add(&sitemap.URL{ - Loc: a.getFullAddress(a.getRelativePath(b, sitemapBlogPostsPath)), + Loc: a.getFullAddress(a.getRelativePath(b, sitemapBlogPostsPath)), + LastMod: &now, }) // Write sitemap a.writeSitemapXML(w, sm)