mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-27 13:38:33 +02:00
feat(v2): absolute slugs and slug resolution system (#3084)
* rework slug to allow absolute slugs and slug resolution * add slug metadata tests * refactor docs metadata test + fix slug bugs * fix tests * fix docs tests failing due to randomness + update snapshot * add test for addLeadingSlash
This commit is contained in:
parent
6730590c1e
commit
f4434b2e42
39 changed files with 791 additions and 255 deletions
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import getSlug from '../slug';
|
||||
|
||||
describe('getSlug', () => {
|
||||
test('should default to dirname/id', () => {
|
||||
expect(getSlug({baseID: 'doc', dirName: '/dir'})).toEqual('/dir/doc');
|
||||
expect(getSlug({baseID: 'doc', dirName: '/dir/subdir'})).toEqual(
|
||||
'/dir/subdir/doc',
|
||||
);
|
||||
});
|
||||
|
||||
test('should handle current dir', () => {
|
||||
expect(getSlug({baseID: 'doc', dirName: '.'})).toEqual('/doc');
|
||||
expect(getSlug({baseID: 'doc', dirName: '/'})).toEqual('/doc');
|
||||
});
|
||||
|
||||
test('should resolve absolute slug frontmatter', () => {
|
||||
expect(
|
||||
getSlug({baseID: 'any', dirName: '.', frontmatterSlug: '/abc/def'}),
|
||||
).toEqual('/abc/def');
|
||||
expect(
|
||||
getSlug({baseID: 'any', dirName: './any', frontmatterSlug: '/abc/def'}),
|
||||
).toEqual('/abc/def');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
dirName: './any/any',
|
||||
frontmatterSlug: '/abc/def',
|
||||
}),
|
||||
).toEqual('/abc/def');
|
||||
});
|
||||
|
||||
test('should resolve relative slug frontmatter', () => {
|
||||
expect(
|
||||
getSlug({baseID: 'any', dirName: '.', frontmatterSlug: 'abc/def'}),
|
||||
).toEqual('/abc/def');
|
||||
expect(
|
||||
getSlug({baseID: 'any', dirName: '/dir', frontmatterSlug: 'abc/def'}),
|
||||
).toEqual('/dir/abc/def');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
dirName: 'unslashedDir',
|
||||
frontmatterSlug: 'abc/def',
|
||||
}),
|
||||
).toEqual('/unslashedDir/abc/def');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
dirName: 'dir/subdir',
|
||||
frontmatterSlug: 'abc/def',
|
||||
}),
|
||||
).toEqual('/dir/subdir/abc/def');
|
||||
expect(
|
||||
getSlug({baseID: 'any', dirName: '/dir', frontmatterSlug: './abc/def'}),
|
||||
).toEqual('/dir/abc/def');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
dirName: '/dir',
|
||||
frontmatterSlug: './abc/../def',
|
||||
}),
|
||||
).toEqual('/dir/def');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
dirName: '/dir/subdir',
|
||||
frontmatterSlug: '../abc/def',
|
||||
}),
|
||||
).toEqual('/dir/abc/def');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
dirName: '/dir/subdir',
|
||||
frontmatterSlug: '../../../../../abc/../def',
|
||||
}),
|
||||
).toEqual('/def');
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue