Skip to content

Sitemap: real lastmod dates, no duplicates, no tag pages - #645

Merged
compscidr merged 1 commit into
mainfrom
fix/sitemap
Oct 3, 2026
Merged

compscidr merged 1 commit into
mainfrom
fix/sitemap

Conversation

@compscidr

Copy link
Copy Markdown
Collaborator

Problem

On a live site (648 URLs):

  • Every entry except posts had lastmod set to the time of the request, because go-sitemap-generator fills in time.Now() when no date is given. Search engines learn to ignore a lastmod that always says "just now".
  • /posts was listed twice: once as a page, once as a post type listing.
  • 527 of the 648 URLs were tag pages, which only re-list posts already in the sitemap.

Changes

  • Sitemap builds the XML with encoding/xml, as the RSS feed does. lastmod is the page's own update time, or the newest post's for the home page and post listings; it is omitted when not known.
  • Each URL is listed once.
  • Tag pages are no longer listed. They still exist and are still indexable.
  • changefreq and priority are dropped; Google and Bing ignore both.
  • Removes go-sitemap-generator and its two transitive dependencies.

Testing

TestSitemap now also asserts the home and listing lastmod values, a single /posts entry, and no /tag/ URLs. go test ./... passes.

🤖 Generated with Claude Code

The sitemap library stamped the time of the request as lastmod on every
entry that had no date, which was everything but posts. The handler now
builds the XML with encoding/xml, as the RSS feed does: pages carry
their own update time, the home page and post listings carry their
newest post's, and an entry with no known date has no lastmod.

Each URL is listed once (a listing and its page shared a path), tag
pages are left out since they only re-list posts already present, and
changefreq/priority are dropped as search engines ignore them. Removes
go-sitemap-generator and its two dependencies.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 3, 2026 06:48
@codecov

codecov Bot commented Oct 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
blog/blog.go 87.50% 3 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The sitemap rewrite is self-contained, logically correct, consistent with the existing RSS pattern, cleanly removes the dependency, and is backed by comprehensive updated tests with no issues found.

Review effort: Balanced
Findings: None

What changed in this PR

This PR rewrites /sitemap.xml generation to fix three problems observed on a live site: lastmod being set to the request time for everything except posts, /posts being listed twice, and tag pages dominating the sitemap (527 of 648 URLs). It replaces the go-sitemap-generator dependency with a hand-built encoding/xml approach matching the existing RSS feed pattern.

Changes:

  • Build the sitemap XML directly with encoding/xml; set lastmod to each page's own update time (or the newest post's for the home page and listings), omitting it when unknown instead of defaulting to time.Now().
  • Deduplicate URLs by site-relative path and stop listing tag pages, changefreq, and priority.
  • Remove go-sitemap-generator and its transitive dependencies; expand TestSitemap to assert the new behavior.
File Description
blog/​blog.go Replaces stm-based sitemap with encoding/xml structs, single GetPosts call, path-based dedup, listing/home lastmod from newest post, and tag-page removal.
blog/​blog_test.go Adds a /posts page to test dedup; asserts home/listing lastmod, single /posts entry, and absence of /tag/ URLs.
go.mod Drops the go-sitemap-generator direct dependency and two now-unused indirect deps.
go.sum Removes checksums for the dropped dependency and its transitive deps.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@compscidr
compscidr merged commit 1962d3d into main Oct 3, 2026
3 of 4 checks passed
@compscidr
compscidr deleted the fix/sitemap branch October 3, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants