Astro Info
Astro v6.3.7
Node v25.6.0
System macOS (arm64)
Package Manager npm
Output static
Adapter none
Integrations @astrojs/sitemap
Also reproduces with the current release, @astrojs/sitemap@3.7.2.
Describe the Bug
@astrojs/sitemap computes a per-URL <lastmod> for pages (via the serialize option) and writes it into the child sitemaps — but it never writes <lastmod> into the <sitemap> entries of sitemap-index.xml.
An index entry gets a <lastmod> only if you separately set the global lastmod option, and even then every entry gets the same date. There is no way to make the index reflect the actual content dates that already exist in the child sitemaps it points to.
Minimal config:
sitemap({
serialize(item) {
item.lastmod = '2024-09-15T00:00:00.000Z';
return item;
},
})
Built dist/sitemap-0.xml — every URL is dated, as expected:
<url><loc>https://example.com/</loc><lastmod>2024-09-15T00:00:00.000Z</lastmod></url>
<url><loc>https://example.com/about/</loc><lastmod>2024-09-15T00:00:00.000Z</lastmod></url>
Built dist/sitemap-index.xml — the <sitemap> entry has no <lastmod> at all:
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>https://example.com/sitemap-0.xml</loc></sitemap>
</sitemapindex>
The freshness data is already computed — it is just dropped on the way into the index.
<lastmod> on a sitemap index <sitemap> entry is part of the sitemaps.org protocol, and Google documents using it to decide which child sitemaps to recrawl. This matters most with chunks: a crawler should be able to tell that the posts sitemap changed while the videos sitemap did not — but with every entry dateless (or sharing one global date), it cannot.
What's the expected result?
Each <sitemap> entry in sitemap-index.xml should carry the most recent <lastmod> of the URLs in the child sitemap it points to:
<sitemap><loc>https://example.com/sitemap-0.xml</loc><lastmod>2024-09-15T00:00:00.000Z</lastmod></sitemap>
When a child sitemap has no per-URL lastmod, the entry should fall back to the configured global lastmod option (current behavior preserved).
Link to Minimal Reproducible Example
https://github.com/jdevalk/astro-sitemap-index-lastmod-repro
npm install && npm run build, then compare dist/sitemap-0.xml (dated) with dist/sitemap-index.xml (no dates).
Participation
Astro Info
Also reproduces with the current release,
@astrojs/sitemap@3.7.2.Describe the Bug
@astrojs/sitemapcomputes a per-URL<lastmod>for pages (via theserializeoption) and writes it into the child sitemaps — but it never writes<lastmod>into the<sitemap>entries ofsitemap-index.xml.An index entry gets a
<lastmod>only if you separately set the globallastmodoption, and even then every entry gets the same date. There is no way to make the index reflect the actual content dates that already exist in the child sitemaps it points to.Minimal config:
Built
dist/sitemap-0.xml— every URL is dated, as expected:Built
dist/sitemap-index.xml— the<sitemap>entry has no<lastmod>at all:The freshness data is already computed — it is just dropped on the way into the index.
<lastmod>on a sitemap index<sitemap>entry is part of the sitemaps.org protocol, and Google documents using it to decide which child sitemaps to recrawl. This matters most withchunks: a crawler should be able to tell that thepostssitemap changed while thevideossitemap did not — but with every entry dateless (or sharing one global date), it cannot.What's the expected result?
Each
<sitemap>entry insitemap-index.xmlshould carry the most recent<lastmod>of the URLs in the child sitemap it points to:When a child sitemap has no per-URL
lastmod, the entry should fall back to the configured globallastmodoption (current behavior preserved).Link to Minimal Reproducible Example
https://github.com/jdevalk/astro-sitemap-index-lastmod-repro
npm install && npm run build, then comparedist/sitemap-0.xml(dated) withdist/sitemap-index.xml(no dates).Participation