mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-30 06:50:36 +02:00
feat(v2): docs version configuration: lastVersion, version.{path,label} (#3357)
* add new docs versioning options * Add some tests for new versioning options * Add some docs for version configurations * try to fix broken link detection after /docs/ root paths have been removed on deploy previews * improve dev/deploypreview versioning configurations * disable custom current version path, as it produces broken links * readVersionDocs should not be order sensitive * fix versions page according to versioning config * fix versions page according to versioning config
This commit is contained in:
parent
4bfc3bbbe7
commit
ae877f2990
15 changed files with 387 additions and 79 deletions
|
@ -94,7 +94,63 @@ describe('simple site', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata simple site with base url', () => {
|
||||
test('readVersionsMetadata simple site with current version config', () => {
|
||||
const versionsMetadata = readVersionsMetadata({
|
||||
options: {
|
||||
...defaultOptions,
|
||||
versions: {
|
||||
current: {
|
||||
label: 'current-label',
|
||||
path: 'current-path',
|
||||
},
|
||||
},
|
||||
},
|
||||
context: {
|
||||
...defaultContext,
|
||||
baseUrl: '/myBaseUrl',
|
||||
},
|
||||
});
|
||||
|
||||
expect(versionsMetadata).toEqual([
|
||||
{
|
||||
...vCurrent,
|
||||
versionPath: '/myBaseUrl/docs/current-path',
|
||||
versionLabel: 'current-label',
|
||||
routePriority: undefined,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata simple site with unknown lastVersion should throw', () => {
|
||||
expect(() =>
|
||||
readVersionsMetadata({
|
||||
options: {...defaultOptions, lastVersion: 'unknownVersionName'},
|
||||
context: defaultContext,
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Docs option lastVersion=unknownVersionName is invalid. Available version names are: current"`,
|
||||
);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata simple site with unknown version configurations should throw', () => {
|
||||
expect(() =>
|
||||
readVersionsMetadata({
|
||||
options: {
|
||||
...defaultOptions,
|
||||
versions: {
|
||||
current: {label: 'current'},
|
||||
unknownVersionName1: {label: 'unknownVersionName1'},
|
||||
unknownVersionName2: {label: 'unknownVersionName2'},
|
||||
},
|
||||
},
|
||||
context: defaultContext,
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Docs versions option provided configuration for unknown versions: unknownVersionName1,unknownVersionName2. Available version names are: current"`,
|
||||
);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata simple site with disableVersioning while single version should throw', () => {
|
||||
expect(() =>
|
||||
readVersionsMetadata({
|
||||
options: {...defaultOptions, disableVersioning: true},
|
||||
|
@ -105,7 +161,7 @@ describe('simple site', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata simple site with base url', () => {
|
||||
test('readVersionsMetadata simple site without including current version should throw', () => {
|
||||
expect(() =>
|
||||
readVersionsMetadata({
|
||||
options: {...defaultOptions, includeCurrentVersion: false},
|
||||
|
@ -205,6 +261,42 @@ describe('versioned site, pluginId=default', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata versioned site with version options', () => {
|
||||
const versionsMetadata = readVersionsMetadata({
|
||||
options: {
|
||||
...defaultOptions,
|
||||
lastVersion: '1.0.0',
|
||||
versions: {
|
||||
current: {
|
||||
path: 'current-path',
|
||||
},
|
||||
'1.0.0': {
|
||||
label: '1.0.0-label',
|
||||
},
|
||||
},
|
||||
},
|
||||
context: defaultContext,
|
||||
});
|
||||
|
||||
expect(versionsMetadata).toEqual([
|
||||
{...vCurrent, versionPath: '/docs/current-path'},
|
||||
{
|
||||
...v101,
|
||||
isLast: false,
|
||||
routePriority: undefined,
|
||||
versionPath: '/docs/1.0.1',
|
||||
},
|
||||
{
|
||||
...v100,
|
||||
isLast: true,
|
||||
routePriority: -1,
|
||||
versionLabel: '1.0.0-label',
|
||||
versionPath: '/docs',
|
||||
},
|
||||
vwithSlugs,
|
||||
]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata versioned site with disableVersioning', () => {
|
||||
const versionsMetadata = readVersionsMetadata({
|
||||
options: {...defaultOptions, disableVersioning: true},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue