mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-30 06:50:36 +02:00
fix(v2): don't include 404 page in sitemaps (#2616)
* 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
This commit is contained in:
parent
14f4ef875a
commit
614adca45f
2 changed files with 27 additions and 10 deletions
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue