From 9b4253d4c22ceb4113112945dda2baf5651fe617 Mon Sep 17 00:00:00 2001 From: workprentice <257153108+workprentice@users.noreply.github.com> Date: Fri, 21 Aug 2026 12:16:26 +0000 Subject: [PATCH] seo: roll up sitemap lastmod from newest descendant on branch pages Section, taxonomy, term, and home pages in the sitemap were reporting only their own _index.md git-commit date, not the newest date among the content they render. This produced demonstrably wrong lastmod values -- e.g. /blog/ claimed 2024-05-16 while its newest post published 2026-08-14, a 2+ year gap on a page that changes constantly. Google treats sitemap lastmod reliability as a sitewide signal (Gary Illyes, 2026-07-16): once it catches enough wrong dates it stops trusting lastmod across the whole site, not just the offending URLs. A stale date on a high-traffic index page like /blog/ is worse than omitting lastmod entirely. Fix: for Kind in (home, section, taxonomy, term), compute lastmod as max(own .Lastmod, newest .RegularPagesRecursive .Lastmod) before emitting it. Leaf pages are untouched -- old-but-honest leaves like /tutorials/glossary/* and static pages like /trademark/ keep their real dates. Verified in an isolated Hugo harness: nested sections roll up transitively, taxonomy/term pages roll up across tagged content, a section with no children keeps its own date, and leaf pages are unaffected. --- layouts/_default/sitemap.xml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/layouts/_default/sitemap.xml b/layouts/_default/sitemap.xml index 39dd94da0dff..9e01e7995d29 100644 --- a/layouts/_default/sitemap.xml +++ b/layouts/_default/sitemap.xml @@ -2,9 +2,15 @@ xmlns:xhtml="http://www.w3.org/1999/xhtml"> {{ range .Data.Pages }} {{ if not (or .Params.private .Params.block_external_search_index .Params.redirect_to .Params.redirect_url (not (partial "taxonomy-indexable.html" .))) }} + {{ $lastmod := .Lastmod }} + {{ if in (slice "home" "section" "taxonomy" "term") .Kind }} + {{ range .RegularPagesRecursive }} + {{ if .Lastmod.After $lastmod }}{{ $lastmod = .Lastmod }}{{ end }} + {{ end }} + {{ end }} - {{ .Site.Params.canonicalURL }}{{ .RelPermalink }}{{ if not .Lastmod.IsZero }} - {{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}{{ end }}{{ with .Sitemap.ChangeFreq }} + {{ .Site.Params.canonicalURL }}{{ .RelPermalink }}{{ if not $lastmod.IsZero }} + {{ safeHTML ( $lastmod.Format "2006-01-02T15:04:05-07:00" ) }}{{ end }}{{ with .Sitemap.ChangeFreq }} {{ . }}{{ end }}{{ if ge .Sitemap.Priority 0.0 }} {{ .Sitemap.Priority }}{{ end }}{{ if .IsTranslated }}{{ range .Translations }}