Skip to content

@astrojs/sitemap: <lastmod> is missing from sitemap-index.xml entries #16838

@jdevalk

Description

@jdevalk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugAn edge case that only affects very specific usage (priority)fix pending verificationReporter needs to verify the triage bot fix workspkg: integrationRelated to any renderer integration (scope)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions