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:
Endi 2019-12-06 12:34:21 +07:00 committed by GitHub
parent 32c9d07b90
commit 7f8aca2ddc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 236 additions and 200 deletions

View file

@ -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',

View file

@ -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}`;
}