sitemap should support hash router?

This commit is contained in:
sebastien 2024-02-22 18:46:45 +01:00
parent a1b9ba6f23
commit 547d8abc68
1 changed files with 13 additions and 5 deletions

View File

@ -53,7 +53,7 @@ export default async function createSitemap(
head: {[location: string]: HelmetServerState},
options: PluginOptions,
): Promise<string | null> {
const {url: hostname} = siteConfig;
const {url: hostname, router} = siteConfig;
if (!hostname) {
throw new Error('URL in docusaurus.config.js cannot be empty/undefined.');
}
@ -77,12 +77,20 @@ export default async function createSitemap(
const sitemapStream = new SitemapStream({hostname});
includedRoutes.forEach((routePath) =>
sitemapStream.write({
url: applyTrailingSlash(routePath, {
const createSitemapUrl = (routePath: string): string => {
const routerPrefix = router === 'hash' ? '/#' : '';
return (
routerPrefix +
applyTrailingSlash(routePath, {
trailingSlash: siteConfig.trailingSlash,
baseUrl: siteConfig.baseUrl,
}),
})
);
};
includedRoutes.forEach((routePath) =>
sitemapStream.write({
url: createSitemapUrl(routePath),
changefreq,
priority,
}),