mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-10 06:42:31 +02:00
feat: prototype custom pages site generation
This commit is contained in:
parent
cf08a20737
commit
bc7b2835b0
8 changed files with 78 additions and 9 deletions
|
@ -1,7 +1,7 @@
|
|||
const path = require('path');
|
||||
const {fileToComponentName} = require('./utils');
|
||||
|
||||
async function genRoutesConfig({docsData, docsDir}) {
|
||||
async function genRoutesConfig({docsData, docsDir, pagesDir, pagesData}) {
|
||||
function genDocsRoute({path: docsPath, source}) {
|
||||
const componentName = fileToComponentName(source);
|
||||
return `
|
||||
|
@ -17,6 +17,20 @@ async function genRoutesConfig({docsData, docsDir}) {
|
|||
return `import ${componentName} from ${JSON.stringify(filePath)}`;
|
||||
}
|
||||
|
||||
function genPagesRoute({path: pagesPath, source}) {
|
||||
const componentName = fileToComponentName(source);
|
||||
return `
|
||||
{
|
||||
path: ${JSON.stringify(pagesPath)},
|
||||
component: ${componentName}
|
||||
}`;
|
||||
}
|
||||
|
||||
function genPagesImport({source}) {
|
||||
const componentName = fileToComponentName(source);
|
||||
return `import ${componentName} from '@pages/${source}'`;
|
||||
}
|
||||
|
||||
const notFoundRoute = `,
|
||||
{
|
||||
path: '*',
|
||||
|
@ -27,9 +41,10 @@ async function genRoutesConfig({docsData, docsDir}) {
|
|||
`import React from 'react';\n` +
|
||||
`import Docs from '@theme/Docs';\n` +
|
||||
`import NotFound from '@theme/NotFound';\n` +
|
||||
`${pagesData.map(genPagesImport).join('\n')}\n` +
|
||||
`${docsData.map(genDocsImport).join('\n')}\n` +
|
||||
`const routes = [${docsData
|
||||
.map(genDocsRoute)
|
||||
`const routes = [${docsData.map(genDocsRoute).join(',')},${pagesData
|
||||
.map(genPagesRoute)
|
||||
.join(',')}${notFoundRoute}\n];\n` +
|
||||
`export default routes;\n`
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue