mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07:26 +02:00
perf(v2): smaller bundlesize by embedding metadata to content (#2088)
* wip embed metadata to content * embed metadata in blog as well * refactor * update test * yarn lock * avoid overwriting file everytime we run new nodejs process * nits
This commit is contained in:
parent
32c9d07b90
commit
7f8aca2ddc
16 changed files with 236 additions and 200 deletions
|
@ -16,9 +16,22 @@ import {
|
|||
normalizeUrl,
|
||||
posixPath,
|
||||
objectWithKeySorted,
|
||||
aliasedSitePath,
|
||||
} from '../index';
|
||||
|
||||
describe('load utils', () => {
|
||||
test('aliasedSitePath', () => {
|
||||
const asserts = {
|
||||
'user/website/docs/asd.md': '@site/docs/asd.md',
|
||||
'user/website/versioned_docs/foo/bar.md':
|
||||
'@site/versioned_docs/foo/bar.md',
|
||||
'user/docs/test.md': '@site/../docs/test.md',
|
||||
};
|
||||
Object.keys(asserts).forEach(file => {
|
||||
expect(aliasedSitePath(file, 'user/website')).toBe(asserts[file]);
|
||||
});
|
||||
});
|
||||
|
||||
test('posixPath', () => {
|
||||
const asserts = {
|
||||
'c:/aaaa\\bbbb': 'c:/aaaa/bbbb',
|
||||
|
|
|
@ -252,3 +252,13 @@ export function normalizeUrl(rawUrls: string[]): string {
|
|||
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias filepath relative to site directory, very useful so that we don't expose user's site structure.
|
||||
* Example: some/path/to/website/docs/foo.md -> @site/docs/foo.md
|
||||
*/
|
||||
export function aliasedSitePath(filePath: string, siteDir: string) {
|
||||
const relativePath = path.relative(siteDir, filePath);
|
||||
// Cannot use path.join() as it resolves '../' and removes the '@site'. Let webpack loader resolve it.
|
||||
return `@site/${relativePath}`;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue