mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-29 00:47:03 +02:00
feat(v2): pluginify pages (#1278)
* feat(v2): convert pages into a plugin * fix: update tests
This commit is contained in:
parent
2da59ed4af
commit
398d7c7ae4
21 changed files with 287 additions and 257 deletions
|
@ -10,7 +10,6 @@ const {normalizeUrl} = require('./utils');
|
|||
async function loadRoutes({
|
||||
siteConfig = {},
|
||||
docsMetadatas = {},
|
||||
pagesMetadatas = [],
|
||||
pluginRouteConfigs = [],
|
||||
}) {
|
||||
const imports = [
|
||||
|
@ -19,7 +18,6 @@ async function loadRoutes({
|
|||
`import Loading from '@theme/Loading';`,
|
||||
`import Doc from '@theme/Doc';`,
|
||||
`import DocBody from '@theme/DocBody';`,
|
||||
`import Pages from '@theme/Pages';`,
|
||||
`import NotFound from '@theme/NotFound';`,
|
||||
];
|
||||
|
||||
|
@ -64,29 +62,6 @@ async function loadRoutes({
|
|||
.join(',')}],
|
||||
}`;
|
||||
|
||||
// Pages.
|
||||
function genPagesRoute(metadata) {
|
||||
const {permalink, source} = metadata;
|
||||
addRoutesPath(permalink);
|
||||
return `
|
||||
{
|
||||
path: '${permalink}',
|
||||
exact: true,
|
||||
component: Loadable({
|
||||
loader: () => import('${source}'),
|
||||
loading: Loading,
|
||||
render(loaded, props) {
|
||||
let Content = loaded.default;
|
||||
return (
|
||||
<Pages {...props} metadata={${JSON.stringify(metadata)}}>
|
||||
<Content {...props} metadata={${JSON.stringify(metadata)}} />
|
||||
</Pages>
|
||||
);
|
||||
}
|
||||
})
|
||||
}`;
|
||||
}
|
||||
|
||||
const notFoundRoute = `
|
||||
{
|
||||
path: '*',
|
||||
|
@ -131,9 +106,7 @@ ${modules
|
|||
${imports.join('\n')}
|
||||
|
||||
const routes = [
|
||||
// Docs.${pagesMetadatas.map(genPagesRoute).join(',')},
|
||||
|
||||
// Pages.${docsRoutes},
|
||||
// Docs.${docsRoutes},
|
||||
|
||||
// Plugins.${routes.join(',')},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue