mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-21 04:57:05 +02:00
feat(v2): code-split metadata out of routes (#1359)
* move assets-manifest to generatedFilesDir * rename generateChunkName -> genChunkName * implement docuHash and genComponentName * feat(v2): code-split routes and metadata * don't code split component code out * simplify metadata path * nits * fix test * address review
This commit is contained in:
parent
866f66241b
commit
f0dc68d01a
11 changed files with 249 additions and 121 deletions
|
@ -8,8 +8,9 @@
|
|||
import path from 'path';
|
||||
import {
|
||||
fileToPath,
|
||||
fileToComponentName,
|
||||
generateChunkName,
|
||||
docuHash,
|
||||
genComponentName,
|
||||
genChunkName,
|
||||
idx,
|
||||
getSubFolder,
|
||||
normalizeUrl,
|
||||
|
@ -30,21 +31,36 @@ describe('load utils', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('fileToComponentName', () => {
|
||||
test('genComponentName', () => {
|
||||
const asserts = {
|
||||
'index.md': 'MDIndex',
|
||||
'hello/index.md': 'MDHelloIndex',
|
||||
'foo.md': 'MDFoo',
|
||||
'foo-bar.md': 'MDFooBar',
|
||||
'index.js': 'JSIndex',
|
||||
'foobar.js': 'JSFoobar',
|
||||
'docusaurus/index.js': 'JSDocusaurusIndex',
|
||||
'234.md': 'MD234',
|
||||
'2018-07-08-test.md': 'MD20180708Test',
|
||||
'%asd.md': 'MDAsd',
|
||||
'/': 'Index',
|
||||
'/foo-bar': 'FooBar096',
|
||||
'/foo/bar': 'FooBar1Df',
|
||||
'/blog/2017/12/14/introducing-docusaurus':
|
||||
'Blog20171214IntroducingDocusaurus8D2',
|
||||
'/blog/2017/12/14-introducing-docusaurus':
|
||||
'Blog20171214IntroducingDocusaurus0Bc',
|
||||
'/blog/201712/14-introducing-docusaurus':
|
||||
'Blog20171214IntroducingDocusaurusA93',
|
||||
};
|
||||
Object.keys(asserts).forEach(file => {
|
||||
expect(fileToComponentName(file)).toBe(asserts[file]);
|
||||
expect(genComponentName(file)).toBe(asserts[file]);
|
||||
});
|
||||
});
|
||||
|
||||
test('docuHash', () => {
|
||||
const asserts = {
|
||||
'': '-d41',
|
||||
'/': 'Index',
|
||||
'/foo-bar': 'foo-bar-096',
|
||||
'/foo/bar': 'foo-bar-1df',
|
||||
'/endi/lie': 'endi-lie-9fa',
|
||||
'/endi-lie': 'endi-lie-fd3',
|
||||
'/yangshun/tay': 'yangshun-tay-48d',
|
||||
'/yangshun-tay': 'yangshun-tay-f3b',
|
||||
};
|
||||
Object.keys(asserts).forEach(file => {
|
||||
expect(docuHash(file)).toBe(asserts[file]);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -64,7 +80,7 @@ describe('load utils', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('generateChunkName', () => {
|
||||
test('genChunkName', () => {
|
||||
const asserts = {
|
||||
'/docs/adding-blog': 'docs-adding-blog-062',
|
||||
'/docs/versioning': 'docs-versioning-8a8',
|
||||
|
@ -76,7 +92,7 @@ describe('load utils', () => {
|
|||
'/blog': 'blog-c06',
|
||||
};
|
||||
Object.keys(asserts).forEach(str => {
|
||||
expect(generateChunkName(str)).toBe(asserts[str]);
|
||||
expect(genChunkName(str)).toBe(asserts[str]);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue