Skip to content

Commit 4f3616d

Browse files
slorberclaude
andcommitted
refactor(sitemap): remove the empty sitemap guards that sitemap v10 makes useless
sitemap v10 no longer throws EmptySitemap, and createSitemap() already returns null before serializing an empty list of items. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d9610db commit 4f3616d

3 files changed

Lines changed: 0 additions & 18 deletions

File tree

‎packages/docusaurus-plugin-sitemap/src/__tests__/xml.test.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ import type {LastModOption, SitemapItem} from '../types';
1313
const options = {lastmod: 'datetime'} as const;
1414

1515
describe('createSitemap', () => {
16-
it('no items', async () => {
17-
const items: SitemapItem[] = [];
18-
19-
await expect(
20-
sitemapItemsToXmlString(items, options),
21-
).rejects.toThrowErrorMatchingInlineSnapshot(
22-
`[Error: Can't generate a sitemap with no items]`,
23-
);
24-
});
25-
2616
it('simple item', async () => {
2717
const items: SitemapItem[] = [{url: 'https://docusaurus.io/docs/doc1'}];
2818

‎packages/docusaurus-plugin-sitemap/src/createSitemap.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ function createDefaultCreateSitemapItems(
4343
): CreateSitemapItemsFn {
4444
return async (params) => {
4545
const sitemapRoutes = getSitemapRoutes({...params, ...internalParams});
46-
if (sitemapRoutes.length === 0) {
47-
return [];
48-
}
4946
return Promise.all(
5047
sitemapRoutes.map((route) =>
5148
createSitemapItem({

‎packages/docusaurus-plugin-sitemap/src/xml.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ export async function sitemapItemsToXmlString(
1212
items: SitemapItem[],
1313
options: {lastmod: LastModOption | null},
1414
): Promise<string> {
15-
if (items.length === 0) {
16-
// Fail fast with a clearer error than the lib's EmptySitemap error
17-
throw new Error("Can't generate a sitemap with no items");
18-
}
19-
2015
// We could generate the XML ourselves, but we keep using the lib on purpose
2116
// Users can return undocumented fields from createSitemapItems()
2217
// (links, img, video, news...) that the lib serializes

0 commit comments

Comments
 (0)