mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-13 23:07:58 +02:00
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:
parent
f1a504e813
commit
6287739bec
3 changed files with 10 additions and 5 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
## Unreleased
|
## 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
|
- Use contenthash instead of chunkhash for better long term caching
|
||||||
|
|
||||||
## 2.0.0-alpha.23
|
## 2.0.0-alpha.23
|
||||||
|
|
|
@ -22,15 +22,15 @@ describe('docusaurus-plugin-content-pages', () => {
|
||||||
siteConfig,
|
siteConfig,
|
||||||
});
|
});
|
||||||
const pagesMetadatas = await plugin.loadContent();
|
const pagesMetadatas = await plugin.loadContent();
|
||||||
const pagesDir = plugin.contentPath;
|
const pagesPath = path.relative(siteDir, plugin.contentPath);
|
||||||
expect(pagesMetadatas).toEqual([
|
expect(pagesMetadatas).toEqual([
|
||||||
{
|
{
|
||||||
permalink: '/',
|
permalink: '/',
|
||||||
source: path.join(pagesDir, 'index.js'),
|
source: path.join('@site', pagesPath, 'index.js'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
permalink: '/hello/world',
|
permalink: '/hello/world',
|
||||||
source: path.join(pagesDir, 'hello', 'world.js'),
|
source: path.join('@site', pagesPath, 'hello', 'world.js'),
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
|
@ -33,7 +33,7 @@ module.exports = function(context, opts) {
|
||||||
|
|
||||||
async loadContent() {
|
async loadContent() {
|
||||||
const {include} = options;
|
const {include} = options;
|
||||||
const {siteConfig} = context;
|
const {siteConfig, siteDir} = context;
|
||||||
const pagesDir = contentPath;
|
const pagesDir = contentPath;
|
||||||
|
|
||||||
if (!fs.existsSync(pagesDir)) {
|
if (!fs.existsSync(pagesDir)) {
|
||||||
|
@ -47,11 +47,15 @@ module.exports = function(context, opts) {
|
||||||
|
|
||||||
return pagesFiles.map(relativeSource => {
|
return pagesFiles.map(relativeSource => {
|
||||||
const source = path.join(pagesDir, relativeSource);
|
const source = path.join(pagesDir, relativeSource);
|
||||||
|
const aliasedSource = path.join(
|
||||||
|
'@site',
|
||||||
|
path.relative(siteDir, source),
|
||||||
|
);
|
||||||
const pathName = encodePath(fileToPath(relativeSource));
|
const pathName = encodePath(fileToPath(relativeSource));
|
||||||
// Default Language.
|
// Default Language.
|
||||||
return {
|
return {
|
||||||
permalink: pathName.replace(/^\//, baseUrl),
|
permalink: pathName.replace(/^\//, baseUrl),
|
||||||
source,
|
source: aliasedSource,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue