Skip to content

Make sitemap lastmod dates accurate for static and content routes#1129

Open
BenjaminMichaelis wants to merge 1 commit into
mainfrom
benjaminmichaelis/sitemap-modified-dates
Open

Make sitemap lastmod dates accurate for static and content routes#1129
BenjaminMichaelis wants to merge 1 commit into
mainfrom
benjaminmichaelis/sitemap-modified-dates

Conversation

@BenjaminMichaelis
Copy link
Copy Markdown
Member

Why

Sitemap lastmod was only reliable for chapter/content URLs. Static routes and the root entry were either missing lastmod or could drift from real content changes, which weakens sitemap freshness signals.

What changed

  • Added static-route lastmod support in sitemap generation via an optional route-to-date lookup.
  • Set root / lastmod from /home when available.
  • Wired HomeController to compute static route lastmod from source file timestamps.
  • Expanded /home dependencies to include Models/AnnouncementCatalog.cs so announcement-content updates are reflected.
  • Added a warning log when a mapped sitemap source file is missing to avoid silent drift.
  • Added test coverage for mapped static route lastmod behavior while preserving chapter/root assertions.

Notes for reviewers

  • The static route dependency map is intentionally explicit (not auto-discovered) to keep behavior predictable and low-complexity.
  • Unmapped routes still appear in sitemap; they simply omit lastmod until intentionally mapped.

Add file-backed lastmod support for static routes and root sitemap entry, while preserving chapter page lastmod behavior from SiteMapping data.

Harden static route dependency tracking by mapping /home to AnnouncementCatalog, documenting the dependency map contract, and warning when mapped files are missing.

Expand sitemap helper tests to cover mapped static route lastmod application alongside existing root and chapter lastmod checks.
Copilot AI review requested due to automatic review settings May 18, 2026 04:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves sitemap freshness signals by allowing lastmod to be populated for static/controller routes (and the root /) using an optional route-to-last-modified lookup, with HomeController computing those dates from source file timestamps.

Changes:

  • Added a new GenerateSitemapXml overload that accepts an optional static-route lastmod dictionary and applies it to controller routes and the root node (via /home).
  • Implemented static route dependency mapping + file timestamp aggregation in HomeController.SitemapXml(), including warning logs for missing mapped files.
  • Added tests covering static-route lastmod behavior and root / inheritance from /home.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
EssentialCSharp.Web/Helpers/SitemapXmlHelpers.cs Adds optional static-route lastmod lookup and applies it to generated sitemap nodes (including /).
EssentialCSharp.Web/Controllers/HomeController.cs Computes static-route lastmod from mapped source file timestamps and logs missing mapped files.
EssentialCSharp.Web.Tests/SitemapXmlHelpersTests.cs Adds coverage for static-route lastmod application and root node behavior.

Comment on lines +20 to +24
["/home"] = ["Views\\Home\\Home.cshtml", "Models\\AnnouncementCatalog.cs"],
["/about"] = ["Views\\Home\\About.cshtml"],
["/announcements"] = ["Views\\Home\\Announcements.cshtml", "Models\\AnnouncementCatalog.cs"],
["/termsofservice"] = ["Views\\Home\\TermsOfService.cshtml"],
["/guidelines"] = ["Views\\Home\\Guidelines.cshtml", "Guidelines\\guidelines.json"]
Comment on lines 38 to +48
// Start with the root URL — no LastModificationDate: it doesn't change per-request
var rootNode = new SitemapNode($"{baseUrl}/")
{
ChangeFrequency = ChangeFrequency.Daily,
Priority = 1.0M
};

if (TryGetRouteLastModified(staticRouteLastModifiedDates, "/home") is DateTime homeLastModified)
{
rootNode.LastModificationDate = homeLastModified;
}
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