Skip to content

Commit 34700c8

Browse files
authored
Merge pull request #342 from pluginpal/feature/filter-duplicates-from-sitemap
fix: filter duplicate URLs from the sitemap XML
2 parents b9c0ed1 + 758e029 commit 34700c8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

.changeset/cold-nights-invent.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webtools-addon-sitemap": patch
3+
---
4+
5+
fix: filter duplicate URLs from the sitemap XML

packages/addons/sitemap/server/services/core.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,17 @@ const createSitemapEntries = async () => {
193193
}
194194
}
195195

196-
return sitemapEntries;
196+
// Filter out duplicates.
197+
const allSitemapUrls = new Set();
198+
const uniqueSitemapEntries = sitemapEntries.filter((entry) => {
199+
if (allSitemapUrls.has(entry.url)) {
200+
return false;
201+
}
202+
allSitemapUrls.add(entry.url);
203+
return true;
204+
});
205+
206+
return uniqueSitemapEntries;
197207
};
198208

199209
/**

0 commit comments

Comments
 (0)