feat(v2): shorter chunk naming for pages (#1688)

* refactor(v2): dont show absolute path for pages chunk/source naming

* test n changelog
This commit is contained in:
Endi 2019-07-23 05:53:30 +07:00 committed by Yangshun Tay
parent f1a504e813
commit 6287739bec
3 changed files with 10 additions and 5 deletions

View file

@ -22,15 +22,15 @@ describe('docusaurus-plugin-content-pages', () => {
siteConfig,
});
const pagesMetadatas = await plugin.loadContent();
const pagesDir = plugin.contentPath;
const pagesPath = path.relative(siteDir, plugin.contentPath);
expect(pagesMetadatas).toEqual([
{
permalink: '/',
source: path.join(pagesDir, 'index.js'),
source: path.join('@site', pagesPath, 'index.js'),
},
{
permalink: '/hello/world',
source: path.join(pagesDir, 'hello', 'world.js'),
source: path.join('@site', pagesPath, 'hello', 'world.js'),
},
]);
});

View file

@ -33,7 +33,7 @@ module.exports = function(context, opts) {
async loadContent() {
const {include} = options;
const {siteConfig} = context;
const {siteConfig, siteDir} = context;
const pagesDir = contentPath;
if (!fs.existsSync(pagesDir)) {
@ -47,11 +47,15 @@ module.exports = function(context, opts) {
return pagesFiles.map(relativeSource => {
const source = path.join(pagesDir, relativeSource);
const aliasedSource = path.join(
'@site',
path.relative(siteDir, source),
);
const pathName = encodePath(fileToPath(relativeSource));
// Default Language.
return {
permalink: pathName.replace(/^\//, baseUrl),
source,
source: aliasedSource,
};
});
},