Skip to content

Commit eb19466

Browse files
committed
#1713 Multiple XML sitemap files
1 parent 4486dc2 commit eb19466

File tree

9 files changed

+247
-96
lines changed

9 files changed

+247
-96
lines changed

src/Libraries/Nop.Services/Seo/ISitemapGenerator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ public partial interface ISitemapGenerator
1313
/// See http://en.wikipedia.org/wiki/Sitemaps for more information.
1414
/// </summary>
1515
/// <param name="urlHelper">URL helper</param>
16+
/// <param name="id">Sitemap identifier</param>
1617
/// <returns>Sitemap.xml as string</returns>
17-
string Generate(UrlHelper urlHelper);
18+
string Generate(UrlHelper urlHelper, int? id);
1819

1920
/// <summary>
2021
/// This will build an xml sitemap for better index with search engines.
2122
/// See http://en.wikipedia.org/wiki/Sitemaps for more information.
2223
/// </summary>
2324
/// <param name="urlHelper">URL helper</param>
25+
/// <param name="id">Sitemap identifier</param>
2426
/// <param name="stream">Stream of sitemap.</param>
25-
void Generate(UrlHelper urlHelper, Stream stream);
27+
void Generate(UrlHelper urlHelper, Stream stream, int? id);
2628

2729
}
2830
}

src/Libraries/Nop.Services/Seo/SitemapGenerator.cs

Lines changed: 225 additions & 82 deletions
Large diffs are not rendered by default.

src/Presentation/Nop.Web/Controllers/CommonController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,12 @@ public virtual ActionResult Sitemap()
376376
[NopHttpsRequirement(SslRequirement.No)]
377377
//available even when a store is closed
378378
[StoreClosed(true)]
379-
public virtual ActionResult SitemapXml()
379+
public virtual ActionResult SitemapXml(int? id)
380380
{
381381
if (!_commonSettings.SitemapEnabled)
382382
return RedirectToRoute("HomePage");
383383

384-
var siteMap = _commonModelFactory.PrepareSitemapXml(this.Url);
384+
var siteMap = _commonModelFactory.PrepareSitemapXml(this.Url, id);
385385
return Content(siteMap, "text/xml");
386386
}
387387

src/Presentation/Nop.Web/Factories/CommonModelFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,13 +497,13 @@ public virtual SitemapModel PrepareSitemapModel()
497497
return cachedModel;
498498
}
499499

500-
public virtual string PrepareSitemapXml(UrlHelper url)
500+
public virtual string PrepareSitemapXml(UrlHelper url, int? id)
501501
{
502-
string cacheKey = string.Format(ModelCacheEventConsumer.SITEMAP_SEO_MODEL_KEY,
502+
string cacheKey = string.Format(ModelCacheEventConsumer.SITEMAP_SEO_MODEL_KEY, id,
503503
_workContext.WorkingLanguage.Id,
504504
string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()),
505505
_storeContext.CurrentStore.Id);
506-
var siteMap = _cacheManager.Get(cacheKey, () => _sitemapGenerator.Generate(url));
506+
var siteMap = _cacheManager.Get(cacheKey, () => _sitemapGenerator.Generate(url, id));
507507
return siteMap;
508508
}
509509

src/Presentation/Nop.Web/Factories/ICommonModelFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ContactVendorModel PrepareContactVendorModel(ContactVendorModel model, Vendor ve
2929

3030
SitemapModel PrepareSitemapModel();
3131

32-
string PrepareSitemapXml(UrlHelper url);
32+
string PrepareSitemapXml(UrlHelper url, int? id);
3333

3434
StoreThemeSelectorModel PrepareStoreThemeSelectorModel();
3535

src/Presentation/Nop.Web/Infrastructure/Cache/ModelCacheEventConsumer.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,11 +750,12 @@ public ModelCacheEventConsumer(CatalogSettings catalogSettings)
750750
/// Key for sitemap on the sitemap SEO page
751751
/// </summary>
752752
/// <remarks>
753-
/// {0} : language id
754-
/// {1} : roles of the current user
755-
/// {2} : current store ID
753+
/// {0} : sitemap identifier
754+
/// {1} : language id
755+
/// {2} : roles of the current user
756+
/// {3} : current store ID
756757
/// </remarks>
757-
public const string SITEMAP_SEO_MODEL_KEY = "Nop.pres.sitemap.seo-{0}-{1}-{2}";
758+
public const string SITEMAP_SEO_MODEL_KEY = "Nop.pres.sitemap.seo-{0}-{1}-{2}-{3}";
758759
public const string SITEMAP_PATTERN_KEY = "Nop.pres.sitemap";
759760

760761
/// <summary>

src/Presentation/Nop.Web/Infrastructure/RouteProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,11 @@ public void RegisterRoutes(RouteCollection routes)
702702
"sitemap.xml",
703703
new { controller = "Common", action = "SitemapXml" },
704704
new[] { "Nop.Web.Controllers" });
705+
routes.MapLocalizedRoute("sitemap-indexed.xml",
706+
"sitemap-{Id}.xml",
707+
new { controller = "Common", action = "SitemapXml" },
708+
new { Id = @"\d+" },
709+
new[] { "Nop.Web.Controllers" });
705710

706711
//store closed
707712
routes.MapLocalizedRoute("StoreClosed",

src/Presentation/Nop.Web/Web.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
9797
<validation validateIntegratedModeConfiguration="false" />
9898
<handlers>
99-
<add name="SitemapXml" path="sitemap.xml" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
99+
<add name="SitemapXml" path="sitemap*.xml" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
100100
<add name="RobotsTxt" path="robots.txt" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
101101
<add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
102102
<add name="DenyAccessToPluginDLLs" verb="*" path="*.dll" type="System.Web.HttpForbiddenHandler" />

src/Tests/Nop.Web.MVC.Tests/Public/Infrastructure/RoutesTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public void Common_routes()
166166
"~/contactvendor/1".ShouldMapTo<CommonController>(c => c.ContactVendor(1));
167167
"~/contactus".ShouldMapTo<CommonController>(c => c.ContactUs());
168168
"~/sitemap".ShouldMapTo<CommonController>(c => c.Sitemap());
169-
"~/sitemap.xml".ShouldMapTo<CommonController>(c => c.SitemapXml());
169+
"~/sitemap.xml".ShouldMapTo<CommonController>(c => c.SitemapXml(null));
170170
}
171171

172172
[Test]

0 commit comments

Comments
 (0)