fix(v2): do not show plugin data path (#1861)

* fix(v2): do not show plugin data path

* test fix

* nits
This commit is contained in:
Endi 2019-10-21 00:58:22 +07:00 committed by Yangshun Tay
parent 5bd6284f18
commit 2c1012b9ec
10 changed files with 58 additions and 31 deletions

View file

@ -13,6 +13,7 @@ import {LoadContext} from '@docusaurus/types';
describe('loadDocs', () => {
test('simple website', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'website');
const generatedFilesDir: string = path.resolve(siteDir, '.docusaurus');
const siteConfig = {
title: 'Hello',
baseUrl: '/',
@ -21,6 +22,7 @@ describe('loadDocs', () => {
const context = {
siteDir,
siteConfig,
generatedFilesDir,
} as LoadContext;
const sidebarPath = path.join(siteDir, 'sidebars.json');
const pluginPath = 'docs';

View file

@ -53,6 +53,10 @@ export default function pluginContentDocs(
const options = {...DEFAULT_OPTIONS, ...opts};
const contentPath = path.resolve(context.siteDir, options.path);
let sourceToPermalink: SourceToPermalink = {};
const dataDir = path.join(
context.generatedFilesDir,
'docusaurus-plugin-content-docs',
);
return {
name: 'docusaurus-plugin-content-docs',
@ -210,6 +214,8 @@ export default function pluginContentDocs(
const {docLayoutComponent, docItemComponent, routeBasePath} = options;
const {addRoute, createData} = actions;
const aliasedSource = (source: string) =>
`@docusaurus-plugin-content-docs/${path.relative(dataDir, source)}`;
const routes = await Promise.all(
Object.values(content.docsMetadata).map(async metadataItem => {
@ -223,7 +229,7 @@ export default function pluginContentDocs(
exact: true,
modules: {
content: metadataItem.source,
metadata: metadataPath,
metadata: aliasedSource(metadataPath),
},
};
}),
@ -248,7 +254,7 @@ export default function pluginContentDocs(
component: docLayoutComponent,
routes,
modules: {
docsMetadata: docsBaseMetadataPath,
docsMetadata: aliasedSource(docsBaseMetadataPath),
},
});
},
@ -257,6 +263,11 @@ export default function pluginContentDocs(
const {getBabelLoader, getCacheLoader} = utils;
const {rehypePlugins, remarkPlugins} = options;
return {
resolve: {
alias: {
'@docusaurus-plugin-content-docs': dataDir,
},
},
module: {
rules: [
{