mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-14 08:42:31 +02:00
fix(v2): do not create route for document that serve as docs home page (#2861)
This commit is contained in:
parent
6797af660f
commit
e68b81bc33
3 changed files with 36 additions and 52 deletions
|
@ -70,8 +70,6 @@ export default function pluginContentDocs(
|
|||
opts: Partial<PluginOptions>,
|
||||
): Plugin<LoadedContent | null> {
|
||||
const options = {...DEFAULT_OPTIONS, ...opts};
|
||||
const homePageDocsRoutePath =
|
||||
options.routeBasePath === '' ? '/' : options.routeBasePath;
|
||||
|
||||
if (options.admonitions) {
|
||||
options.remarkPlugins = options.remarkPlugins.concat([
|
||||
|
@ -98,6 +96,24 @@ export default function pluginContentDocs(
|
|||
} = versioning;
|
||||
const versionsNames = versions.map((version) => `version-${version}`);
|
||||
|
||||
// Docs home page.
|
||||
const homePageDocsRoutePath =
|
||||
options.routeBasePath === '' ? '/' : options.routeBasePath;
|
||||
const isDocsHomePagePath = (permalink: string) => {
|
||||
const documentIdMatch = new RegExp(
|
||||
`^\/(?:${homePageDocsRoutePath}\/)?(?:(?:${versions.join(
|
||||
'|',
|
||||
)}|next)\/)?(.*)`,
|
||||
'i',
|
||||
).exec(permalink);
|
||||
|
||||
if (documentIdMatch) {
|
||||
return documentIdMatch[1] === options.homePageId;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
return {
|
||||
name: 'docusaurus-plugin-content-docs',
|
||||
|
||||
|
@ -268,10 +284,14 @@ export default function pluginContentDocs(
|
|||
);
|
||||
}
|
||||
|
||||
const {title, permalink, sidebar_label} = linkMetadata;
|
||||
|
||||
return {
|
||||
type: 'link',
|
||||
label: linkMetadata.sidebar_label || linkMetadata.title,
|
||||
href: linkMetadata.permalink,
|
||||
label: sidebar_label || title,
|
||||
href: isDocsHomePagePath(permalink)
|
||||
? permalink.replace(`/${options.homePageId}`, '')
|
||||
: permalink,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -361,7 +381,6 @@ export default function pluginContentDocs(
|
|||
baseUrl,
|
||||
homePageDocsRoutePath,
|
||||
versionDocsPathPrefix,
|
||||
options.homePageId,
|
||||
]);
|
||||
const docsBaseMetadataPath = await createData(
|
||||
`${docuHash(metadataItem.source)}-base.json`,
|
||||
|
@ -404,12 +423,9 @@ export default function pluginContentDocs(
|
|||
|
||||
return (
|
||||
routes
|
||||
// Do not create a route for a page created specifically for docs home page.
|
||||
.filter(
|
||||
({path}) =>
|
||||
path.substr(path.lastIndexOf('/') + 1) !==
|
||||
REVERSED_DOCS_HOME_PAGE_ID,
|
||||
)
|
||||
// Do not create a route for a document serve as docs home page.
|
||||
// TODO: need way to do this filtering when generating routes for better perf.
|
||||
.filter(({path}) => !isDocsHomePagePath(path))
|
||||
.sort((a, b) => (a.path > b.path ? 1 : b.path > a.path ? -1 : 0))
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue