mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-31 09:57: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
|
@ -11,7 +11,6 @@ const path = require('path');
|
|||
const loadConfig = require('./config');
|
||||
const loadDocs = require('./docs');
|
||||
const loadEnv = require('./env');
|
||||
const loadPages = require('./pages');
|
||||
const loadTheme = require('./theme');
|
||||
const {generate} = require('./utils');
|
||||
const loadRoutes = require('./routes');
|
||||
|
@ -71,25 +70,16 @@ module.exports = async function load(siteDir) {
|
|||
},
|
||||
);
|
||||
|
||||
// Pages.
|
||||
const pagesDir = path.resolve(siteDir, 'pages');
|
||||
const pagesMetadatas = await loadPages({pagesDir, env, siteConfig});
|
||||
await generate(
|
||||
generatedFilesDir,
|
||||
'pagesMetadatas.js',
|
||||
`export default ${JSON.stringify(pagesMetadatas, null, 2)};`,
|
||||
);
|
||||
|
||||
// Process plugins.
|
||||
const pluginConfigs = siteConfig.plugins || [];
|
||||
const context = {env, siteDir, siteConfig};
|
||||
|
||||
// Initialize plugins.
|
||||
const plugins = pluginConfigs.map(({name, options: opts}) => {
|
||||
const plugins = pluginConfigs.map(({name, options}) => {
|
||||
// TODO: Resolve using node_modules as well.
|
||||
// eslint-disable-next-line
|
||||
const Plugin = require(path.resolve(__dirname, '../../plugins', name));
|
||||
return new Plugin(opts, context);
|
||||
return new Plugin(options, context);
|
||||
});
|
||||
|
||||
// Plugin lifecycle - loadContents().
|
||||
|
@ -156,7 +146,6 @@ module.exports = async function load(siteDir) {
|
|||
const {routesConfig, routesPaths} = await loadRoutes({
|
||||
siteConfig,
|
||||
docsMetadatas,
|
||||
pagesMetadatas,
|
||||
pluginRouteConfigs,
|
||||
});
|
||||
await generate(generatedFilesDir, 'routes.js', routesConfig);
|
||||
|
@ -189,10 +178,6 @@ module.exports = async function load(siteDir) {
|
|||
name: 'docsSidebars',
|
||||
path: '@generated/docsSidebars',
|
||||
},
|
||||
{
|
||||
name: 'pagesMetadatas',
|
||||
path: '@generated/pagesMetadatas',
|
||||
},
|
||||
],
|
||||
});
|
||||
await generate(generatedFilesDir, 'metadata.js', metadataFile);
|
||||
|
@ -204,8 +189,6 @@ module.exports = async function load(siteDir) {
|
|||
docsMetadatas,
|
||||
docsSidebars,
|
||||
env,
|
||||
pagesDir,
|
||||
pagesMetadatas,
|
||||
outDir,
|
||||
themePath,
|
||||
baseUrl,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue