mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-30 23:08:54 +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(() => {
|
expect(() => {
|
||||||
createSitemap({} as any, [], {} as any);
|
createSitemap({} as any, [], {} as any);
|
||||||
}).toThrowErrorMatchingInlineSnapshot(
|
}).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;
|
const {url: hostname} = siteConfig;
|
||||||
if (!hostname) {
|
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(
|
const urls = routesPaths
|
||||||
(routesPath) =>
|
.filter((route: string) => !route.endsWith('404.html'))
|
||||||
({
|
.map(
|
||||||
url: routesPath,
|
(routesPath) =>
|
||||||
changefreq: options.changefreq,
|
({
|
||||||
priority: options.priority,
|
url: routesPath,
|
||||||
} as SitemapItemOptions),
|
changefreq: options.changefreq,
|
||||||
);
|
priority: options.priority,
|
||||||
|
} as SitemapItemOptions),
|
||||||
|
);
|
||||||
|
|
||||||
return sitemap.createSitemap({
|
return sitemap.createSitemap({
|
||||||
hostname,
|
hostname,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue