Skip to content

Commit f040cb2

Browse files
fix: address PR review feedback on sitemap endpoint
- Remove LastModificationDate from root URL node (setting it to UtcNow on every cache expiry is an SEO anti-pattern; omitting it is cleaner than a stale value) - Fix misleading startup comment: validation errors are logged and startup continues, not fail-fast - Add test: GenerateSitemapXml_DoesNotIncludeSitemapRoute to prevent regression on sitemap self-listing filter
1 parent ea2174a commit f040cb2

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

EssentialCSharp.Web.Tests/SitemapXmlHelpersTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,27 @@ public async Task GenerateSitemapXml_DoesNotIncludeErrorRoutes()
187187
await Assert.That(allUrls).DoesNotContain(url => url.Contains("/Error", StringComparison.OrdinalIgnoreCase));
188188
}
189189

190+
[Test]
191+
public async Task GenerateSitemapXml_DoesNotIncludeSitemapRoute()
192+
{
193+
// Arrange
194+
var siteMappings = new List<SiteMapping>();
195+
var baseUrl = "https://test.example.com/";
196+
197+
// Act
198+
var routeConfigurationService = _Factory.Services.GetRequiredService<IRouteConfigurationService>();
199+
SitemapXmlHelpers.GenerateSitemapXml(
200+
siteMappings,
201+
routeConfigurationService,
202+
baseUrl,
203+
out var nodes);
204+
205+
var allUrls = nodes.Select(n => n.Url).ToList();
206+
207+
// /sitemap.xml should not list itself
208+
await Assert.That(allUrls).DoesNotContain(url => url.Contains("sitemap", StringComparison.OrdinalIgnoreCase));
209+
}
210+
190211
[Test]
191212
public async Task GenerateSitemapXml_UsesLastModifiedDateFromSiteMapping()
192213
{

EssentialCSharp.Web/Helpers/SitemapXmlHelpers.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ public static void GenerateSitemapXml(IEnumerable<SiteMapping> siteMappings, IRo
2525
// Routes should end up with leading slash
2626
baseUrl = baseUrl.TrimEnd('/');
2727

28-
// Start with the root URL
28+
// Start with the root URL — no LastModificationDate: it doesn't change per-request
2929
nodes = new() {
3030
new($"{baseUrl}/")
3131
{
32-
LastModificationDate = newDateTime,
3332
ChangeFrequency = ChangeFrequency.Daily,
3433
Priority = 1.0M
3534
}

EssentialCSharp.Web/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ await McpJsonRpcResponseWriter.WriteErrorAsync(
571571

572572
app.MapFallbackToController("Index", "Home");
573573

574-
// Validate sitemap data at startup to fail fast on bad content
574+
// Validate sitemap data at startup — logs errors but allows startup to continue
575575
var siteMappingService = app.Services.GetRequiredService<ISiteMappingService>();
576576
var logger = app.Services.GetRequiredService<ILogger<Program>>();
577577

0 commit comments

Comments
 (0)