Skip to content

Commit

Permalink
fix(v2): don't include 404 page in sitemaps (#2616)
Browse files Browse the repository at this point in the history
* fix(v2): don't include 404 page in sitemaps

Signed-off-by: Reece Dunham <me@rdil.rocks>

* fix: improve implementation as requested

Signed-off-by: Reece Dunham <me@rdil.rocks>

* Fix issue with baseUrls
  • Loading branch information
RDIL authored Apr 18, 2020
1 parent 14f4ef8 commit 614adca
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,22 @@ describe('createSitemap', () => {
expect(() => {
createSitemap({} as any, [], {} as any);
}).toThrowErrorMatchingInlineSnapshot(
`"Url in docusaurus.config.js cannot be empty/undefined"`,
`"url in docusaurus.config.js cannot be empty/undefined"`,
);
});

test('exclusion of 404 page', () => {
const sitemap = createSitemap(
{
url: 'https://example.com',
} as DocusaurusConfig,
['/', '/404.html', '/mypage'],
{
cacheTime: 600,
changefreq: 'daily',
priority: 0.7,
},
);
expect(sitemap.toString()).not.toContain('404');
});
});
20 changes: 11 additions & 9 deletions packages/docusaurus-plugin-sitemap/src/createSitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ export default function createSitemap(
) {
const {url: hostname} = siteConfig;
if (!hostname) {
throw new Error('Url in docusaurus.config.js cannot be empty/undefined');
throw new Error('url in docusaurus.config.js cannot be empty/undefined');
}

const urls = routesPaths.map(
(routesPath) =>
({
url: routesPath,
changefreq: options.changefreq,
priority: options.priority,
} as SitemapItemOptions),
);
const urls = routesPaths
.filter((route: string) => !route.endsWith('404.html'))
.map(
(routesPath) =>
({
url: routesPath,
changefreq: options.changefreq,
priority: options.priority,
} as SitemapItemOptions),
);

return sitemap.createSitemap({
hostname,
Expand Down

0 comments on commit 614adca

Please sign in to comment.