From 6287739bec17d2e76a73c686d83d2ffd5f1564cf Mon Sep 17 00:00:00 2001 From: Endi Date: Tue, 23 Jul 2019 05:53:30 +0700 Subject: [PATCH] feat(v2): shorter chunk naming for pages (#1688) * refactor(v2): dont show absolute path for pages chunk/source naming * test n changelog --- CHANGELOG-2.x.md | 1 + .../src/__tests__/index.test.js | 6 +++--- packages/docusaurus-plugin-content-pages/src/index.js | 8 ++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG-2.x.md b/CHANGELOG-2.x.md index 4c603cfd59..87dc33e65b 100644 --- a/CHANGELOG-2.x.md +++ b/CHANGELOG-2.x.md @@ -2,6 +2,7 @@ ## Unreleased +- Shorter chunk naming for pages. Instead of absolute path, we use relative path from site directory - Use contenthash instead of chunkhash for better long term caching ## 2.0.0-alpha.23 diff --git a/packages/docusaurus-plugin-content-pages/src/__tests__/index.test.js b/packages/docusaurus-plugin-content-pages/src/__tests__/index.test.js index abf97fbe1e..4c4e2e7dd8 100644 --- a/packages/docusaurus-plugin-content-pages/src/__tests__/index.test.js +++ b/packages/docusaurus-plugin-content-pages/src/__tests__/index.test.js @@ -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'), }, ]); }); diff --git a/packages/docusaurus-plugin-content-pages/src/index.js b/packages/docusaurus-plugin-content-pages/src/index.js index 38d1b789ec..7982a4b436 100644 --- a/packages/docusaurus-plugin-content-pages/src/index.js +++ b/packages/docusaurus-plugin-content-pages/src/index.js @@ -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, }; }); },