mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-16 17:52:29 +02:00
refactor: use alias for docs & eslint
This commit is contained in:
parent
8538a10a66
commit
d36c17f368
3 changed files with 20 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
||||||
import toSlug from './toSlug.js';
|
import toSlug from './toSlug';
|
||||||
|
|
||||||
function anchors(md) {
|
function anchors(md) {
|
||||||
const originalRender = md.renderer.rules.heading_open;
|
const originalRender = md.renderer.rules.heading_open;
|
||||||
|
|
|
@ -1,21 +1,23 @@
|
||||||
const path = require('path');
|
|
||||||
const {fileToComponentName} = require('./utils');
|
const {fileToComponentName} = require('./utils');
|
||||||
|
|
||||||
async function genRoutesConfig({docsData, docsDir, pagesData}) {
|
async function genRoutesConfig({docsData, pagesData}) {
|
||||||
function genDocsRoute({path: docsPath, source}) {
|
function genDocsRoute({path: docsPath, source}) {
|
||||||
const componentName = fileToComponentName(source);
|
const componentName = fileToComponentName(source);
|
||||||
return `
|
return `
|
||||||
{
|
{
|
||||||
path: ${JSON.stringify(docsPath)},
|
path: ${JSON.stringify(docsPath)},
|
||||||
exact: true,
|
exact: true,
|
||||||
component: () => <Docs><${componentName} /></Docs>
|
component: () => (
|
||||||
|
<Docs>
|
||||||
|
<${componentName} />
|
||||||
|
</Docs>
|
||||||
|
)
|
||||||
}`;
|
}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function genDocsImport({source}) {
|
function genDocsImport({source}) {
|
||||||
const filePath = path.resolve(docsDir, source);
|
|
||||||
const componentName = fileToComponentName(source);
|
const componentName = fileToComponentName(source);
|
||||||
return `import ${componentName} from ${JSON.stringify(filePath)}`;
|
return `import ${componentName} from '@docs/${source}';`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function genPagesRoute({path: pagesPath, source}) {
|
function genPagesRoute({path: pagesPath, source}) {
|
||||||
|
@ -30,7 +32,7 @@ async function genRoutesConfig({docsData, docsDir, pagesData}) {
|
||||||
|
|
||||||
function genPagesImport({source}) {
|
function genPagesImport({source}) {
|
||||||
const componentName = fileToComponentName(source);
|
const componentName = fileToComponentName(source);
|
||||||
return `import ${componentName} from '@pages/${source}'`;
|
return `import ${componentName} from '@pages/${source}';`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const notFoundRoute = `,
|
const notFoundRoute = `,
|
||||||
|
|
|
@ -4,7 +4,15 @@ const path = require('path');
|
||||||
const mdLoader = require.resolve('./loader/markdown');
|
const mdLoader = require.resolve('./loader/markdown');
|
||||||
|
|
||||||
module.exports = function createBaseConfig(props) {
|
module.exports = function createBaseConfig(props) {
|
||||||
const {siteConfig, outDir, themePath, siteDir, baseUrl} = props;
|
const {
|
||||||
|
siteConfig,
|
||||||
|
outDir,
|
||||||
|
themePath,
|
||||||
|
docsDir,
|
||||||
|
pagesDir,
|
||||||
|
siteDir,
|
||||||
|
baseUrl
|
||||||
|
} = props;
|
||||||
|
|
||||||
const config = new Config();
|
const config = new Config();
|
||||||
const isProd = process.env.NODE_ENV === 'production';
|
const isProd = process.env.NODE_ENV === 'production';
|
||||||
|
@ -23,7 +31,8 @@ module.exports = function createBaseConfig(props) {
|
||||||
.set('symlinks', true)
|
.set('symlinks', true)
|
||||||
.alias.set('@theme', themePath)
|
.alias.set('@theme', themePath)
|
||||||
.set('@site', siteDir)
|
.set('@site', siteDir)
|
||||||
.set('@pages', path.resolve(siteDir, 'pages'))
|
.set('@docs', docsDir)
|
||||||
|
.set('@pages', pagesDir)
|
||||||
.set('@generated', path.resolve(__dirname, '../core/generated'))
|
.set('@generated', path.resolve(__dirname, '../core/generated'))
|
||||||
.set('@core', path.resolve(__dirname, '../core'))
|
.set('@core', path.resolve(__dirname, '../core'))
|
||||||
.end();
|
.end();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue