Make sitemap lastmod dates accurate for static and content routes#1129
Open
BenjaminMichaelis wants to merge 1 commit into
Open
Make sitemap lastmod dates accurate for static and content routes#1129BenjaminMichaelis wants to merge 1 commit into
BenjaminMichaelis wants to merge 1 commit into
Conversation
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.
Contributor
There was a problem hiding this comment.
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
GenerateSitemapXmloverload that accepts an optional static-routelastmoddictionary 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
lastmodbehavior 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Sitemap
lastmodwas only reliable for chapter/content URLs. Static routes and the root entry were either missinglastmodor could drift from real content changes, which weakens sitemap freshness signals.What changed
lastmodsupport in sitemap generation via an optional route-to-date lookup./lastmodfrom/homewhen available.HomeControllerto compute static routelastmodfrom source file timestamps./homedependencies to includeModels/AnnouncementCatalog.csso announcement-content updates are reflected.lastmodbehavior while preserving chapter/root assertions.Notes for reviewers
lastmoduntil intentionally mapped.