Skip to content

Fix sitemap <lastmod> missing when metadata.updated_at is absent#145

Merged
eelcoj merged 2 commits intoRails-Designer:mainfrom
m-lague:fix/sitemap-lastmod-fallback
Feb 25, 2026
Merged

Fix sitemap <lastmod> missing when metadata.updated_at is absent#145
eelcoj merged 2 commits intoRails-Designer:mainfrom
m-lague:fix/sitemap-lastmod-fallback

Conversation

@m-lague
Copy link
Contributor

@m-lague m-lague commented Feb 22, 2026

Fixes #143

When a resource doesn't have metadata.updated_at, the rescue block
was evaluating Time.current.iso8601 but not passing it to with.lastmod,
so <lastmod> was silently omitted from the sitemap.

Adding with.lastmod Time.current.iso8601 in the rescue branch ensures
the tag is always written, either with the resource's own date or with
the current build time as fallback.

Also added updated_at to a dummy post to cover both cases in the tests:

  • resource with updated_at<lastmod> uses that date
  • resource without updated_at<lastmod> falls back to current time

Two new tests added in test/perron/site/builder/sitemap_test.rb, both passing:

  • test_sitemap_uses_resource_updated_at_as_lastmod_when_present
  • test_sitemap_falls_back_to_current_time_as_lastmod_when_updated_at_is_missing

@eelcoj
Copy link
Contributor

eelcoj commented Feb 23, 2026

Thanks for this @m-lague ❤️

Dug a bit into the lastmod tag.

Google: Google’s latest guidelines emphasize that using the lastmod tag helps the search engine prioritize crawling and indexing pages with fresh content. In its XML sitemap documentation, Google says: “Google uses the value if it’s consistently and verifiably (for example, by comparing to the last modification of the page) accurate.”
Google also clarified how to view lastmod dates for page updates: “The value should reflect the date and time of the last significant update to the page. For example, an update to the main content, the structured data, or links on the page is generally considered significant, however an update to the copyright date is not.”
Bing: In February 2023, Bing also highlighted the critical nature of the lastmod tag in XML sitemaps, advising site owners to ensure this tag accurately reflects content updates.

So

resource without updated_at → falls back to current time

Given above this is not correct behaviour. So while on this, I think it would be good to fix this as it could/would harm sites using Perron's sitemaps.

Other relevant links:

@m-lague
Copy link
Contributor Author

m-lague commented Feb 23, 2026

Yes, I had indeed noted this point and wanted to discuss it.

As you pointed out, having all <lastmod> set to the same date and time
is not ideal for Google (maybe it's acceptable on the first build 🤷🏻‍♂️).

So maybe we should remove the line entirely :

with.lastmod Time.current.iso8601 

and instead add a note in the documentation stating that updated_at
is required on resources where <lastmod> should be present in the sitemap?

@eelcoj
Copy link
Contributor

eelcoj commented Feb 23, 2026

That is the way to go, indeed. No updated_at value should mean no lastmod tag. 👍

I will add a note about updating the sitemap docs to mention updated_at usage. ✔️

@eelcoj eelcoj merged commit ec8d3e8 into Rails-Designer:main Feb 25, 2026
3 checks passed
@eelcoj
Copy link
Contributor

eelcoj commented Feb 25, 2026

@m-lague I updated the PR to remove the lastmod and merged as I am working on related changes and didn't want you to fight merge conflicts. 😬

Thanks for your first contribution to Perron! ❤️

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.

Sitemap: <lastmod> is omitted when metadata.updated_at is missing (rescue doesn't write tag)

2 participants