From 17c00167f33a5a83aa62ad9794a620b969831dac Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Fri, 23 Feb 2024 15:59:09 +0200 Subject: [PATCH] Correct usage of sitemap index --- .../Controllers/ReportController.cs | 8 ++------ .../Models/Sitemaps/Sitemap.cs | 10 ++++++++++ .../Models/Sitemaps/SitemapIndex.cs | 12 ++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 src/BUTR.CrashReportServer/Models/Sitemaps/Sitemap.cs create mode 100644 src/BUTR.CrashReportServer/Models/Sitemaps/SitemapIndex.cs diff --git a/src/BUTR.CrashReportServer/Controllers/ReportController.cs b/src/BUTR.CrashReportServer/Controllers/ReportController.cs index 134c0cd..e65e064 100644 --- a/src/BUTR.CrashReportServer/Controllers/ReportController.cs +++ b/src/BUTR.CrashReportServer/Controllers/ReportController.cs @@ -197,15 +197,11 @@ public IActionResult Sitemap() var count = _dbContext.Set().Count(); var sitemaps = count % 50000; - - var sitemap = new Urlset + var sitemap = new SitemapIndex { - Url = Enumerable.Range(0, sitemaps).Select(x => new Url + Sitemap = Enumerable.Range(0, sitemaps).Select(x => new Sitemap { Location = $"{_options.BaseUri}/{x}", - TimeStamp = DateTime.UtcNow, - Priority = 0.5, - ChangeFrequency = ChangeFrequency.Never, }).ToList(), }; return Ok(sitemap); diff --git a/src/BUTR.CrashReportServer/Models/Sitemaps/Sitemap.cs b/src/BUTR.CrashReportServer/Models/Sitemaps/Sitemap.cs new file mode 100644 index 0000000..4a208f3 --- /dev/null +++ b/src/BUTR.CrashReportServer/Models/Sitemaps/Sitemap.cs @@ -0,0 +1,10 @@ +using System.Xml.Serialization; + +namespace BUTR.CrashReportServer.Models.Sitemaps; + +[XmlRoot(ElementName="sitemap", Namespace="http://www.sitemaps.org/schemas/sitemap/0.9")] +public class Sitemap +{ + [XmlElement(ElementName="loc", Namespace="http://www.sitemaps.org/schemas/sitemap/0.9")] + public string Location { get; set; } +} \ No newline at end of file diff --git a/src/BUTR.CrashReportServer/Models/Sitemaps/SitemapIndex.cs b/src/BUTR.CrashReportServer/Models/Sitemaps/SitemapIndex.cs new file mode 100644 index 0000000..5363793 --- /dev/null +++ b/src/BUTR.CrashReportServer/Models/Sitemaps/SitemapIndex.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using System.Xml.Serialization; + +namespace BUTR.CrashReportServer.Models.Sitemaps; + +[XmlRoot(ElementName="sitemapindex", Namespace="http://www.sitemaps.org/schemas/sitemap/0.9")] +public class SitemapIndex +{ + + [XmlElement(ElementName="sitemap", Namespace="http://www.sitemaps.org/schemas/sitemap/0.9")] + public List Sitemap { get; set; } +} \ No newline at end of file