@docusaurus/plugin-content-docs 2.0.0-beta.2 → 2.0.0-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/categoryGeneratedIndex.d.ts +12 -0
- package/lib/categoryGeneratedIndex.js +37 -0
- package/lib/cli.d.ts +3 -2
- package/lib/cli.js +57 -72
- package/lib/client/docsClientUtils.d.ts +9 -28
- package/lib/client/docsClientUtils.js +34 -43
- package/lib/client/index.d.ts +81 -0
- package/lib/client/index.js +67 -0
- package/lib/constants.d.ts +4 -0
- package/lib/constants.js +4 -1
- package/lib/docs.d.ts +34 -7
- package/lib/docs.js +202 -79
- package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docusaurus.config.js → lib/frontMatter.d.ts} +4 -8
- package/lib/{docFrontMatter.js → frontMatter.js} +23 -4
- package/lib/globalData.d.ts +3 -3
- package/lib/globalData.js +35 -6
- package/lib/index.d.ts +3 -3
- package/lib/index.js +124 -154
- package/lib/lastUpdate.d.ts +4 -6
- package/lib/lastUpdate.js +22 -26
- package/lib/markdown/index.d.ts +3 -6
- package/lib/markdown/index.js +3 -3
- package/lib/markdown/linkify.d.ts +1 -1
- package/lib/markdown/linkify.js +6 -3
- package/lib/numberPrefix.d.ts +1 -1
- package/lib/numberPrefix.js +16 -21
- package/lib/options.d.ts +3 -5
- package/lib/options.js +56 -23
- package/lib/props.d.ts +7 -2
- package/lib/props.js +84 -14
- package/lib/routes.d.ts +29 -0
- package/lib/routes.js +96 -0
- package/lib/server-export.d.ts +9 -0
- package/lib/server-export.js +22 -0
- package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +1 -6
- package/lib/sidebars/generator.js +209 -0
- package/lib/sidebars/index.d.ts +13 -0
- package/lib/sidebars/index.js +92 -0
- package/lib/sidebars/normalization.d.ts +13 -0
- package/lib/sidebars/normalization.js +59 -0
- package/lib/sidebars/postProcessor.d.ts +11 -0
- package/lib/sidebars/postProcessor.js +81 -0
- package/lib/sidebars/processor.d.ts +10 -0
- package/lib/sidebars/processor.js +79 -0
- package/lib/sidebars/types.d.ts +183 -0
- package/lib/{docFrontMatter.d.ts → sidebars/types.js} +2 -2
- package/lib/sidebars/utils.d.ts +55 -0
- package/lib/sidebars/utils.js +259 -0
- package/lib/sidebars/validation.d.ts +11 -0
- package/lib/sidebars/validation.js +143 -0
- package/lib/slug.d.ts +5 -4
- package/lib/slug.js +28 -18
- package/{src/__tests__/__fixtures__/sidebars/sidebars-first-level-not-category.js → lib/tags.d.ts} +3 -14
- package/lib/tags.js +21 -0
- package/lib/translations.d.ts +3 -3
- package/lib/translations.js +100 -93
- package/lib/types.d.ts +13 -185
- package/lib/versions/files.d.ts +50 -0
- package/lib/versions/files.js +141 -0
- package/lib/versions/index.d.ts +36 -0
- package/lib/versions/index.js +154 -0
- package/lib/versions/validation.d.ts +17 -0
- package/lib/versions/validation.js +71 -0
- package/package.json +44 -30
- package/src/categoryGeneratedIndex.ts +60 -0
- package/src/cli.ts +88 -114
- package/src/client/docsClientUtils.ts +44 -71
- package/src/client/index.ts +158 -0
- package/src/constants.ts +4 -2
- package/src/docs.ts +281 -83
- package/src/frontMatter.ts +63 -0
- package/src/globalData.ts +57 -7
- package/src/index.ts +183 -224
- package/src/lastUpdate.ts +27 -38
- package/src/markdown/index.ts +10 -16
- package/src/markdown/linkify.ts +7 -4
- package/src/numberPrefix.ts +19 -26
- package/src/options.ts +61 -29
- package/src/plugin-content-docs.d.ts +569 -93
- package/src/props.ts +121 -21
- package/src/routes.ts +159 -0
- package/src/server-export.ts +22 -0
- package/src/sidebars/README.md +10 -0
- package/src/sidebars/generator.ts +292 -0
- package/src/sidebars/index.ts +118 -0
- package/src/sidebars/normalization.ts +91 -0
- package/src/sidebars/postProcessor.ts +112 -0
- package/src/sidebars/processor.ts +123 -0
- package/src/sidebars/types.ts +280 -0
- package/src/sidebars/utils.ts +393 -0
- package/src/sidebars/validation.ts +179 -0
- package/src/slug.ts +41 -22
- package/src/tags.ts +20 -0
- package/src/translations.ts +155 -124
- package/src/types.ts +17 -250
- package/src/versions/files.ts +216 -0
- package/src/versions/index.ts +246 -0
- package/src/versions/validation.ts +115 -0
- package/lib/.tsbuildinfo +0 -1
- package/lib/sidebarItemsGenerator.js +0 -211
- package/lib/sidebars.d.ts +0 -43
- package/lib/sidebars.js +0 -320
- package/lib/theme/hooks/useDocs.d.ts +0 -20
- package/lib/theme/hooks/useDocs.js +0 -72
- package/lib/versions.d.ts +0 -16
- package/lib/versions.js +0 -319
- package/src/__tests__/__fixtures__/bad-id-site/docs/invalid-id.md +0 -5
- package/src/__tests__/__fixtures__/bad-slug-on-doc-home-site/docs/docWithSlug.md +0 -5
- package/src/__tests__/__fixtures__/empty-site/docusaurus.config.js +0 -16
- package/src/__tests__/__fixtures__/empty-site/sidebars.json +0 -1
- package/src/__tests__/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -34
- package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-category.js +0 -44
- package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -20
- package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed.json +0 -21
- package/src/__tests__/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -10
- package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-link.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-unknown-type.json +0 -14
- package/src/__tests__/__fixtures__/sidebars/sidebars-wrong-field.json +0 -20
- package/src/__tests__/__fixtures__/sidebars/sidebars.json +0 -20
- package/src/__tests__/__fixtures__/simple-site/docs/foo/bar.md +0 -69
- package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +0 -70
- package/src/__tests__/__fixtures__/simple-site/docs/headingAsTitle.md +0 -1
- package/src/__tests__/__fixtures__/simple-site/docs/hello.md +0 -53
- package/src/__tests__/__fixtures__/simple-site/docs/ipsum.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/lorem.md +0 -6
- package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/absoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/relativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/resolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/tryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docusaurus.config.js +0 -14
- package/src/__tests__/__fixtures__/simple-site/sidebars.json +0 -23
- package/src/__tests__/__fixtures__/simple-site/wrong-sidebars.json +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/0-getting-started.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/1-installation.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/00_api-overview.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/0 --- Client API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/1 --- Server API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/0. Plugin API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/1. Theme API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/_category_.yml +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/03_api-end.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/_category_.json +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/0-guide2.5.md +0 -8
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/02-guide2.md +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/_category_.json +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/a-guide4.md +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/b-guide5.md +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/guide3.md +0 -8
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/z-guide1.md +0 -8
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars.js +0 -23
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js +0 -16
- package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-1.md +0 -7
- package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-2.md +0 -8
- package/src/__tests__/__fixtures__/site-with-doc-label/docusaurus.config.js +0 -14
- package/src/__tests__/__fixtures__/site-with-doc-label/sidebars.json +0 -14
- package/src/__tests__/__fixtures__/versioned-site/community/team.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/community_sidebars.json +0 -3
- package/src/__tests__/__fixtures__/versioned-site/community_versioned_docs/version-1.0.0/team.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/community_versioned_sidebars/version-1.0.0-sidebars.json +0 -3
- package/src/__tests__/__fixtures__/versioned-site/community_versions.json +0 -1
- package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +0 -4
- package/src/__tests__/__fixtures__/versioned-site/docs/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/absoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/relativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/resolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/tryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docusaurus.config.js +0 -18
- package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs-community/current/team.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/sidebars.json +0 -10
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/bar.md +0 -4
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/baz.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/foo/bar.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootAbsoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootRelativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootResolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootTryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/absoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/relativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/resolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/tryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.0-sidebars.json +0 -11
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +0 -10
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-withSlugs-sidebars.json +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versions.json +0 -5
- package/src/__tests__/__snapshots__/cli.test.ts.snap +0 -90
- package/src/__tests__/__snapshots__/index.test.ts.snap +0 -1916
- package/src/__tests__/__snapshots__/sidebars.test.ts.snap +0 -218
- package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -487
- package/src/__tests__/cli.test.ts +0 -333
- package/src/__tests__/docFrontMatter.test.ts +0 -244
- package/src/__tests__/docs.test.ts +0 -878
- package/src/__tests__/index.test.ts +0 -1871
- package/src/__tests__/lastUpdate.test.ts +0 -69
- package/src/__tests__/numberPrefix.test.ts +0 -199
- package/src/__tests__/options.test.ts +0 -231
- package/src/__tests__/sidebarItemsGenerator.test.ts +0 -336
- package/src/__tests__/sidebars.test.ts +0 -639
- package/src/__tests__/slug.test.ts +0 -109
- package/src/__tests__/translations.test.ts +0 -159
- package/src/__tests__/versions.test.ts +0 -741
- package/src/client/__tests__/docsClientUtils.test.ts +0 -371
- package/src/docFrontMatter.ts +0 -41
- package/src/markdown/__tests__/__fixtures__/docs/doc-localized.md +0 -1
- package/src/markdown/__tests__/__fixtures__/docs/doc1.md +0 -13
- package/src/markdown/__tests__/__fixtures__/docs/doc2.md +0 -12
- package/src/markdown/__tests__/__fixtures__/docs/doc4.md +0 -19
- package/src/markdown/__tests__/__fixtures__/docs/doc5.md +0 -6
- package/src/markdown/__tests__/__fixtures__/docs/subdir/doc3.md +0 -3
- package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/doc2.md +0 -7
- package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/subdir/doc1.md +0 -3
- package/src/markdown/__tests__/__snapshots__/linkify.test.ts.snap +0 -82
- package/src/markdown/__tests__/linkify.test.ts +0 -190
- package/src/sidebarItemsGenerator.ts +0 -307
- package/src/sidebars.ts +0 -522
- package/src/theme/hooks/useDocs.ts +0 -99
- package/src/versions.ts +0 -572
- package/tsconfig.json +0 -9
- package/types.d.ts +0 -13
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import fs from 'fs';
|
|
9
|
-
import path from 'path';
|
|
10
|
-
import shell from 'shelljs';
|
|
11
|
-
|
|
12
|
-
import {getFileLastUpdate} from '../lastUpdate';
|
|
13
|
-
|
|
14
|
-
describe('lastUpdate', () => {
|
|
15
|
-
const existingFilePath = path.join(
|
|
16
|
-
__dirname,
|
|
17
|
-
'__fixtures__/simple-site/docs/hello.md',
|
|
18
|
-
);
|
|
19
|
-
test('existing test file in repository with Git timestamp', async () => {
|
|
20
|
-
const lastUpdateData = await getFileLastUpdate(existingFilePath);
|
|
21
|
-
expect(lastUpdateData).not.toBeNull();
|
|
22
|
-
|
|
23
|
-
const {author, timestamp} = lastUpdateData;
|
|
24
|
-
expect(author).not.toBeNull();
|
|
25
|
-
expect(typeof author).toBe('string');
|
|
26
|
-
|
|
27
|
-
expect(timestamp).not.toBeNull();
|
|
28
|
-
expect(typeof timestamp).toBe('number');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('non-existing file', async () => {
|
|
32
|
-
const consoleMock = jest.spyOn(console, 'error');
|
|
33
|
-
consoleMock.mockImplementation();
|
|
34
|
-
const nonExistingFileName = '.nonExisting';
|
|
35
|
-
const nonExistingFilePath = path.join(
|
|
36
|
-
__dirname,
|
|
37
|
-
'__fixtures__',
|
|
38
|
-
nonExistingFileName,
|
|
39
|
-
);
|
|
40
|
-
expect(await getFileLastUpdate(nonExistingFilePath)).toBeNull();
|
|
41
|
-
expect(consoleMock).toHaveBeenCalledTimes(1);
|
|
42
|
-
expect(consoleMock.mock.calls[0][0].message).toContain(
|
|
43
|
-
`Command failed with exit code 128: git log -1 --format=%ct, %an ${nonExistingFileName}`,
|
|
44
|
-
);
|
|
45
|
-
expect(await getFileLastUpdate(null)).toBeNull();
|
|
46
|
-
expect(await getFileLastUpdate(undefined)).toBeNull();
|
|
47
|
-
consoleMock.mockRestore();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('temporary created file that has no git timestamp', async () => {
|
|
51
|
-
const tempFilePath = path.join(__dirname, '__fixtures__', '.temp');
|
|
52
|
-
fs.writeFileSync(tempFilePath, 'Lorem ipsum :)');
|
|
53
|
-
expect(await getFileLastUpdate(tempFilePath)).toBeNull();
|
|
54
|
-
fs.unlinkSync(tempFilePath);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('Git does not exist', async () => {
|
|
58
|
-
const mock = jest.spyOn(shell, 'which').mockImplementationOnce(() => null);
|
|
59
|
-
const consoleMock = jest.spyOn(console, 'warn').mockImplementation();
|
|
60
|
-
const lastUpdateData = await getFileLastUpdate(existingFilePath);
|
|
61
|
-
expect(lastUpdateData).toBeNull();
|
|
62
|
-
expect(consoleMock).toHaveBeenLastCalledWith(
|
|
63
|
-
'Sorry, the docs plugin last update options require Git.',
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
consoleMock.mockRestore();
|
|
67
|
-
mock.mockRestore();
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
DefaultNumberPrefixParser,
|
|
10
|
-
DisabledNumberPrefixParser,
|
|
11
|
-
stripNumberPrefix,
|
|
12
|
-
stripPathNumberPrefixes,
|
|
13
|
-
} from '../numberPrefix';
|
|
14
|
-
|
|
15
|
-
const IgnoredNumberPrefixPatterns = [
|
|
16
|
-
// Patterns without number prefix
|
|
17
|
-
'MyDoc',
|
|
18
|
-
'a1-My Doc',
|
|
19
|
-
'My Doc-000',
|
|
20
|
-
'My Doc - 1',
|
|
21
|
-
'My Doc - 02',
|
|
22
|
-
'Hey - 03 - My Doc',
|
|
23
|
-
'00abc01-My Doc',
|
|
24
|
-
'My 001- Doc',
|
|
25
|
-
'My -001 Doc',
|
|
26
|
-
// ignore common date-like patterns: https://github.com/facebook/docusaurus/issues/4640
|
|
27
|
-
'2021-01-31 - Doc',
|
|
28
|
-
'31-01-2021 - Doc',
|
|
29
|
-
'2021_01_31 - Doc',
|
|
30
|
-
'31_01_2021 - Doc',
|
|
31
|
-
'2021.01.31 - Doc',
|
|
32
|
-
'31.01.2021 - Doc',
|
|
33
|
-
'2021-01 - Doc',
|
|
34
|
-
'2021_01 - Doc',
|
|
35
|
-
'2021.01 - Doc',
|
|
36
|
-
'01-2021 - Doc',
|
|
37
|
-
'01_2021 - Doc',
|
|
38
|
-
'01.2021 - Doc',
|
|
39
|
-
// date patterns without suffix
|
|
40
|
-
'2021-01-31',
|
|
41
|
-
'2021-01',
|
|
42
|
-
'21-01-31',
|
|
43
|
-
'21-01',
|
|
44
|
-
'2021_01_31',
|
|
45
|
-
'2021_01',
|
|
46
|
-
'21_01_31',
|
|
47
|
-
'21_01',
|
|
48
|
-
'01_31',
|
|
49
|
-
'01',
|
|
50
|
-
'2021',
|
|
51
|
-
'01',
|
|
52
|
-
// ignore common versioning patterns: https://github.com/facebook/docusaurus/issues/4653
|
|
53
|
-
'8.0',
|
|
54
|
-
'8.0.0',
|
|
55
|
-
'14.2.16',
|
|
56
|
-
'18.2',
|
|
57
|
-
'8.0 - Doc',
|
|
58
|
-
'8.0.0 - Doc',
|
|
59
|
-
'8_0',
|
|
60
|
-
'8_0_0',
|
|
61
|
-
'14_2_16',
|
|
62
|
-
'18_2',
|
|
63
|
-
'8.0 - Doc',
|
|
64
|
-
'8.0.0 - Doc',
|
|
65
|
-
];
|
|
66
|
-
|
|
67
|
-
describe('stripNumberPrefix', () => {
|
|
68
|
-
function stripNumberPrefixDefault(str: string) {
|
|
69
|
-
return stripNumberPrefix(str, DefaultNumberPrefixParser);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
test('should strip number prefix if present', () => {
|
|
73
|
-
expect(stripNumberPrefixDefault('1-My Doc')).toEqual('My Doc');
|
|
74
|
-
expect(stripNumberPrefixDefault('01-My Doc')).toEqual('My Doc');
|
|
75
|
-
expect(stripNumberPrefixDefault('001-My Doc')).toEqual('My Doc');
|
|
76
|
-
expect(stripNumberPrefixDefault('001 - My Doc')).toEqual('My Doc');
|
|
77
|
-
expect(stripNumberPrefixDefault('001 - My Doc')).toEqual('My Doc');
|
|
78
|
-
expect(stripNumberPrefixDefault('999 - My Doc')).toEqual(
|
|
79
|
-
'My Doc',
|
|
80
|
-
);
|
|
81
|
-
//
|
|
82
|
-
expect(stripNumberPrefixDefault('1---My Doc')).toEqual('My Doc');
|
|
83
|
-
expect(stripNumberPrefixDefault('01---My Doc')).toEqual('My Doc');
|
|
84
|
-
expect(stripNumberPrefixDefault('001---My Doc')).toEqual('My Doc');
|
|
85
|
-
expect(stripNumberPrefixDefault('001 --- My Doc')).toEqual('My Doc');
|
|
86
|
-
expect(stripNumberPrefixDefault('001 --- My Doc')).toEqual(
|
|
87
|
-
'My Doc',
|
|
88
|
-
);
|
|
89
|
-
expect(stripNumberPrefixDefault('999 --- My Doc')).toEqual(
|
|
90
|
-
'My Doc',
|
|
91
|
-
);
|
|
92
|
-
//
|
|
93
|
-
expect(stripNumberPrefixDefault('1___My Doc')).toEqual('My Doc');
|
|
94
|
-
expect(stripNumberPrefixDefault('01___My Doc')).toEqual('My Doc');
|
|
95
|
-
expect(stripNumberPrefixDefault('001___My Doc')).toEqual('My Doc');
|
|
96
|
-
expect(stripNumberPrefixDefault('001 ___ My Doc')).toEqual('My Doc');
|
|
97
|
-
expect(stripNumberPrefixDefault('001 ___ My Doc')).toEqual(
|
|
98
|
-
'My Doc',
|
|
99
|
-
);
|
|
100
|
-
expect(stripNumberPrefixDefault('999 ___ My Doc')).toEqual(
|
|
101
|
-
'My Doc',
|
|
102
|
-
);
|
|
103
|
-
//
|
|
104
|
-
expect(stripNumberPrefixDefault('1.My Doc')).toEqual('My Doc');
|
|
105
|
-
expect(stripNumberPrefixDefault('01.My Doc')).toEqual('My Doc');
|
|
106
|
-
expect(stripNumberPrefixDefault('001.My Doc')).toEqual('My Doc');
|
|
107
|
-
expect(stripNumberPrefixDefault('001 . My Doc')).toEqual('My Doc');
|
|
108
|
-
expect(stripNumberPrefixDefault('001 . My Doc')).toEqual('My Doc');
|
|
109
|
-
expect(stripNumberPrefixDefault('999 . My Doc')).toEqual(
|
|
110
|
-
'My Doc',
|
|
111
|
-
);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test('should not strip number prefix if pattern does not match', () => {
|
|
115
|
-
IgnoredNumberPrefixPatterns.forEach((badPattern) => {
|
|
116
|
-
expect(stripNumberPrefixDefault(badPattern)).toEqual(badPattern);
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe('stripPathNumberPrefix', () => {
|
|
122
|
-
test('should strip number prefixes in paths', () => {
|
|
123
|
-
expect(
|
|
124
|
-
stripPathNumberPrefixes(
|
|
125
|
-
'0-MyRootFolder0/1 - MySubFolder1/2. MyDeepFolder2/3 _MyDoc3',
|
|
126
|
-
DefaultNumberPrefixParser,
|
|
127
|
-
),
|
|
128
|
-
).toEqual('MyRootFolder0/MySubFolder1/MyDeepFolder2/MyDoc3');
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test('should strip number prefixes in paths with custom parser', () => {
|
|
132
|
-
function stripPathNumberPrefixCustom(str: string) {
|
|
133
|
-
return {
|
|
134
|
-
filename: str.substring(1, str.length),
|
|
135
|
-
numberPrefix: 0,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
expect(
|
|
140
|
-
stripPathNumberPrefixes('aaaa/bbbb/cccc', stripPathNumberPrefixCustom),
|
|
141
|
-
).toEqual('aaa/bbb/ccc');
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
test('should strip number prefixes in paths with disabled parser', () => {
|
|
145
|
-
expect(
|
|
146
|
-
stripPathNumberPrefixes(
|
|
147
|
-
'0-MyRootFolder0/1 - MySubFolder1/2. MyDeepFolder2/3 _MyDoc3',
|
|
148
|
-
DisabledNumberPrefixParser,
|
|
149
|
-
),
|
|
150
|
-
).toEqual('0-MyRootFolder0/1 - MySubFolder1/2. MyDeepFolder2/3 _MyDoc3');
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
describe('DefaultNumberPrefixParser', () => {
|
|
155
|
-
test('should extract number prefix if present', () => {
|
|
156
|
-
expect(DefaultNumberPrefixParser('0-My Doc')).toEqual({
|
|
157
|
-
filename: 'My Doc',
|
|
158
|
-
numberPrefix: 0,
|
|
159
|
-
});
|
|
160
|
-
expect(DefaultNumberPrefixParser('1-My Doc')).toEqual({
|
|
161
|
-
filename: 'My Doc',
|
|
162
|
-
numberPrefix: 1,
|
|
163
|
-
});
|
|
164
|
-
expect(DefaultNumberPrefixParser('01-My Doc')).toEqual({
|
|
165
|
-
filename: 'My Doc',
|
|
166
|
-
numberPrefix: 1,
|
|
167
|
-
});
|
|
168
|
-
expect(DefaultNumberPrefixParser('001-My Doc')).toEqual({
|
|
169
|
-
filename: 'My Doc',
|
|
170
|
-
numberPrefix: 1,
|
|
171
|
-
});
|
|
172
|
-
expect(DefaultNumberPrefixParser('001 - My Doc')).toEqual({
|
|
173
|
-
filename: 'My Doc',
|
|
174
|
-
numberPrefix: 1,
|
|
175
|
-
});
|
|
176
|
-
expect(DefaultNumberPrefixParser('001 - My Doc')).toEqual({
|
|
177
|
-
filename: 'My Doc',
|
|
178
|
-
numberPrefix: 1,
|
|
179
|
-
});
|
|
180
|
-
expect(DefaultNumberPrefixParser('999 - My Doc')).toEqual({
|
|
181
|
-
filename: 'My Doc',
|
|
182
|
-
numberPrefix: 999,
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
expect(DefaultNumberPrefixParser('0046036 - My Doc')).toEqual({
|
|
186
|
-
filename: 'My Doc',
|
|
187
|
-
numberPrefix: 46036,
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
test('should not extract number prefix if pattern does not match', () => {
|
|
192
|
-
IgnoredNumberPrefixPatterns.forEach((badPattern) => {
|
|
193
|
-
expect(DefaultNumberPrefixParser(badPattern)).toEqual({
|
|
194
|
-
filename: badPattern,
|
|
195
|
-
numberPrefix: undefined,
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
});
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import {OptionsSchema, DEFAULT_OPTIONS} from '../options';
|
|
9
|
-
import {normalizePluginOptions} from '@docusaurus/utils-validation';
|
|
10
|
-
import {DefaultSidebarItemsGenerator} from '../sidebarItemsGenerator';
|
|
11
|
-
import {
|
|
12
|
-
DefaultNumberPrefixParser,
|
|
13
|
-
DisabledNumberPrefixParser,
|
|
14
|
-
} from '../numberPrefix';
|
|
15
|
-
|
|
16
|
-
// the type of remark/rehype plugins is function
|
|
17
|
-
const markdownPluginsFunctionStub = () => {};
|
|
18
|
-
const markdownPluginsObjectStub = {};
|
|
19
|
-
|
|
20
|
-
describe('normalizeDocsPluginOptions', () => {
|
|
21
|
-
test('should return default options for undefined user options', async () => {
|
|
22
|
-
const {value, error} = await OptionsSchema.validate({});
|
|
23
|
-
expect(value).toEqual(DEFAULT_OPTIONS);
|
|
24
|
-
expect(error).toBe(undefined);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('should accept correctly defined user options', async () => {
|
|
28
|
-
const userOptions = {
|
|
29
|
-
path: 'my-docs', // Path to data on filesystem, relative to site dir.
|
|
30
|
-
routeBasePath: 'my-docs', // URL Route.
|
|
31
|
-
homePageId: 'home', // Document id for docs home page.
|
|
32
|
-
include: ['**/*.{md,mdx}'], // Extensions to include.
|
|
33
|
-
sidebarPath: 'my-sidebar', // Path to sidebar configuration for showing a list of markdown pages.
|
|
34
|
-
sidebarItemsGenerator: DefaultSidebarItemsGenerator,
|
|
35
|
-
numberPrefixParser: DefaultNumberPrefixParser,
|
|
36
|
-
docLayoutComponent: '@theme/DocPage',
|
|
37
|
-
docItemComponent: '@theme/DocItem',
|
|
38
|
-
remarkPlugins: [markdownPluginsObjectStub],
|
|
39
|
-
rehypePlugins: [markdownPluginsFunctionStub],
|
|
40
|
-
beforeDefaultRehypePlugins: [],
|
|
41
|
-
beforeDefaultRemarkPlugins: [],
|
|
42
|
-
showLastUpdateTime: true,
|
|
43
|
-
showLastUpdateAuthor: true,
|
|
44
|
-
admonitions: {},
|
|
45
|
-
includeCurrentVersion: false,
|
|
46
|
-
disableVersioning: true,
|
|
47
|
-
editCurrentVersion: true,
|
|
48
|
-
editLocalizedFiles: true,
|
|
49
|
-
versions: {
|
|
50
|
-
current: {
|
|
51
|
-
path: 'next',
|
|
52
|
-
label: 'next',
|
|
53
|
-
},
|
|
54
|
-
version1: {
|
|
55
|
-
path: 'hello',
|
|
56
|
-
label: 'world',
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
const {value, error} = await OptionsSchema.validate(userOptions);
|
|
61
|
-
expect(value).toEqual(userOptions);
|
|
62
|
-
expect(error).toBe(undefined);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test('should accept correctly defined remark and rehype plugin options', async () => {
|
|
66
|
-
const userOptions = {
|
|
67
|
-
...DEFAULT_OPTIONS,
|
|
68
|
-
beforeDefaultRemarkPlugins: [],
|
|
69
|
-
beforeDefaultRehypePlugins: [markdownPluginsFunctionStub],
|
|
70
|
-
remarkPlugins: [[markdownPluginsFunctionStub, {option1: '42'}]],
|
|
71
|
-
rehypePlugins: [
|
|
72
|
-
markdownPluginsObjectStub,
|
|
73
|
-
[markdownPluginsFunctionStub, {option1: '42'}],
|
|
74
|
-
],
|
|
75
|
-
};
|
|
76
|
-
const {value, error} = await OptionsSchema.validate(userOptions);
|
|
77
|
-
expect(value).toEqual(userOptions);
|
|
78
|
-
expect(error).toBe(undefined);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test('should accept admonitions false', async () => {
|
|
82
|
-
const admonitionsFalse = {
|
|
83
|
-
...DEFAULT_OPTIONS,
|
|
84
|
-
admonitions: false,
|
|
85
|
-
};
|
|
86
|
-
const {value, error} = OptionsSchema.validate(admonitionsFalse);
|
|
87
|
-
expect(value).toEqual(admonitionsFalse);
|
|
88
|
-
expect(error).toBe(undefined);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test('should accept numberPrefixParser function', () => {
|
|
92
|
-
function customNumberPrefixParser() {}
|
|
93
|
-
expect(
|
|
94
|
-
normalizePluginOptions(OptionsSchema, {
|
|
95
|
-
...DEFAULT_OPTIONS,
|
|
96
|
-
numberPrefixParser: customNumberPrefixParser,
|
|
97
|
-
}),
|
|
98
|
-
).toEqual({
|
|
99
|
-
...DEFAULT_OPTIONS,
|
|
100
|
-
id: 'default',
|
|
101
|
-
numberPrefixParser: customNumberPrefixParser,
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('should accept numberPrefixParser false', () => {
|
|
106
|
-
expect(
|
|
107
|
-
normalizePluginOptions(OptionsSchema, {
|
|
108
|
-
...DEFAULT_OPTIONS,
|
|
109
|
-
numberPrefixParser: false,
|
|
110
|
-
}),
|
|
111
|
-
).toEqual({
|
|
112
|
-
...DEFAULT_OPTIONS,
|
|
113
|
-
id: 'default',
|
|
114
|
-
numberPrefixParser: DisabledNumberPrefixParser,
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
test('should accept numberPrefixParser true', () => {
|
|
119
|
-
expect(
|
|
120
|
-
normalizePluginOptions(OptionsSchema, {
|
|
121
|
-
...DEFAULT_OPTIONS,
|
|
122
|
-
numberPrefixParser: true,
|
|
123
|
-
}),
|
|
124
|
-
).toEqual({
|
|
125
|
-
...DEFAULT_OPTIONS,
|
|
126
|
-
id: 'default',
|
|
127
|
-
numberPrefixParser: DefaultNumberPrefixParser,
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test('should reject admonitions true', async () => {
|
|
132
|
-
const admonitionsTrue = {
|
|
133
|
-
...DEFAULT_OPTIONS,
|
|
134
|
-
admonitions: true,
|
|
135
|
-
};
|
|
136
|
-
const {error} = OptionsSchema.validate(admonitionsTrue);
|
|
137
|
-
expect(error).toMatchInlineSnapshot(
|
|
138
|
-
`[ValidationError: "admonitions" contains an invalid value]`,
|
|
139
|
-
);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test('should reject invalid remark plugin options', () => {
|
|
143
|
-
expect(() => {
|
|
144
|
-
normalizePluginOptions(OptionsSchema, {
|
|
145
|
-
remarkPlugins: [[{option1: '42'}, markdownPluginsFunctionStub]],
|
|
146
|
-
});
|
|
147
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
148
|
-
`"\\"remarkPlugins[0]\\" does not match any of the allowed types"`,
|
|
149
|
-
);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
test('should reject invalid rehype plugin options', () => {
|
|
153
|
-
expect(() => {
|
|
154
|
-
normalizePluginOptions(OptionsSchema, {
|
|
155
|
-
rehypePlugins: [
|
|
156
|
-
[
|
|
157
|
-
markdownPluginsFunctionStub,
|
|
158
|
-
{option1: '42'},
|
|
159
|
-
markdownPluginsFunctionStub,
|
|
160
|
-
],
|
|
161
|
-
],
|
|
162
|
-
});
|
|
163
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
164
|
-
`"\\"rehypePlugins[0]\\" does not match any of the allowed types"`,
|
|
165
|
-
);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
test('should reject bad path inputs', () => {
|
|
169
|
-
expect(() => {
|
|
170
|
-
normalizePluginOptions(OptionsSchema, {
|
|
171
|
-
path: 2,
|
|
172
|
-
});
|
|
173
|
-
}).toThrowErrorMatchingInlineSnapshot(`"\\"path\\" must be a string"`);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
test('should reject bad include inputs', () => {
|
|
177
|
-
expect(() => {
|
|
178
|
-
normalizePluginOptions(OptionsSchema, {
|
|
179
|
-
include: '**/*.{md,mdx}',
|
|
180
|
-
});
|
|
181
|
-
}).toThrowErrorMatchingInlineSnapshot(`"\\"include\\" must be an array"`);
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
test('should reject bad showLastUpdateTime inputs', () => {
|
|
185
|
-
expect(() => {
|
|
186
|
-
normalizePluginOptions(OptionsSchema, {
|
|
187
|
-
showLastUpdateTime: 'true',
|
|
188
|
-
});
|
|
189
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
190
|
-
`"\\"showLastUpdateTime\\" must be a boolean"`,
|
|
191
|
-
);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test('should reject bad remarkPlugins input', () => {
|
|
195
|
-
expect(() => {
|
|
196
|
-
normalizePluginOptions(OptionsSchema, {
|
|
197
|
-
remarkPlugins: 'remark-math',
|
|
198
|
-
});
|
|
199
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
200
|
-
`"\\"remarkPlugins\\" must be an array"`,
|
|
201
|
-
);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
test('should reject bad lastVersion', () => {
|
|
205
|
-
expect(() => {
|
|
206
|
-
normalizePluginOptions(OptionsSchema, {
|
|
207
|
-
lastVersion: false,
|
|
208
|
-
});
|
|
209
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
210
|
-
`"\\"lastVersion\\" must be a string"`,
|
|
211
|
-
);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
test('should reject bad versions', () => {
|
|
215
|
-
expect(() => {
|
|
216
|
-
normalizePluginOptions(OptionsSchema, {
|
|
217
|
-
versions: {
|
|
218
|
-
current: {
|
|
219
|
-
hey: 3,
|
|
220
|
-
},
|
|
221
|
-
version1: {
|
|
222
|
-
path: 'hello',
|
|
223
|
-
label: 'world',
|
|
224
|
-
},
|
|
225
|
-
},
|
|
226
|
-
});
|
|
227
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
228
|
-
`"\\"versions.current.hey\\" is not allowed"`,
|
|
229
|
-
);
|
|
230
|
-
});
|
|
231
|
-
});
|