Menu

1 / 5

Sitemap lastmod from git history in Astro, and the Vercel shallow clone trap

DEV Community: astro·Seppe Gadeyne·4 days ago
#1bnnRPYj
#devtoastro#devto#dev#date#build
Reading 0:00
15s threshold

Google's sitemap docs say it uses <lastmod> "if it's consistently and verifiably (for example by comparing to the last modification of the page) accurate." Most static sites fail that test in one of two ways: they leave lastmod out, or they stamp every URL with the build time. A build-time date changes on every deploy, so it says nothing about the page.

On straffesites.com, a static Astro site with Content Collections (MDX and JSON in Git, deployed on Vercel), every sitemap entry now carries the date of the last commit that touched the content of that page. This article shows the code, the one Vercel setting that makes it work, and the trap I hit on the first deploy: a shallow clone that silently gives almost every file the same date.

Versions used: Astro 7.2.8, @astrojs/sitemap 3.7.3, Node 26, git 2.43.

The idea: one git log per build

Git already knows when each file last changed.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.