Skip to content

Commit 9afa6c7

Browse files
author
Jan Nielsen
committed
Add support for language exclusion in sitemap.xml
This PR adds the ability to exclude specific languages from sitemap.xml generation. ### What’s new: - New property `DisallowLanguages` in `SitemapXmlSettings` - `SitemapModelFactory` and alternate URL logic now respects this setting - Default behavior remains unchanged (no exclusions) ### Why: In some scenarios, site owners may want to: - Prevent certain language versions from being listed in sitemaps (e.g. test/staging content) - Avoid conflicting SEO signals when the same languages are excluded in `robots.txt` This setting provides fine-grained control and separates concerns between `robots.txt` and sitemap configuration. Closes #7777
1 parent 197deaa commit 9afa6c7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Libraries/Nop.Core/Domain/Common/SitemapXmlSettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,9 @@ public SitemapXmlSettings()
7171
/// Gets or sets the wait time (in seconds) before the operation can be started again
7272
/// </summary>
7373
public int SitemapBuildOperationDelay { get; set; }
74+
75+
/// <summary>
76+
/// Disallow languages
77+
/// </summary>
78+
public List<int> DisallowLanguages { get; set; } = new();
7479
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,8 @@ var name when name.Equals(nameof(ProductTag), StringComparison.InvariantCultureI
887887

888888
var updatedOn = dateTimeUpdatedOn ?? DateTime.UtcNow;
889889
var languages = _localizationSettings.SeoFriendlyUrlsForLanguagesEnabled
890-
? await _languageService.GetAllLanguagesAsync(storeId: store.Id)
890+
? (await _languageService.GetAllLanguagesAsync(storeId: store.Id))
891+
.Where(lang => !_sitemapXmlSettings.DisallowLanguages.Contains(lang.Id)).ToList()
891892
: null;
892893

893894
if (languages == null || languages.Count == 1)

0 commit comments

Comments
 (0)