@docusaurus/plugin-content-docs 2.0.0-beta.fc64c12e4 → 2.0.0
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 -73
- 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 +33 -6
- package/lib/docs.js +201 -78
- package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docusaurus.config.js → lib/frontMatter.d.ts} +4 -8
- package/lib/{docFrontMatter.js → frontMatter.js} +22 -3
- package/lib/globalData.d.ts +3 -3
- package/lib/globalData.js +35 -6
- package/lib/index.d.ts +3 -3
- package/lib/index.js +120 -153
- 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 +34 -26
- package/lib/props.d.ts +7 -2
- package/lib/props.js +84 -13
- 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 +25 -0
- package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +1 -7
- 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 -192
- 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 -118
- package/src/client/docsClientUtils.ts +44 -71
- package/src/client/index.ts +158 -0
- package/src/constants.ts +4 -2
- package/src/docs.ts +277 -80
- package/src/frontMatter.ts +63 -0
- package/src/globalData.ts +57 -7
- package/src/index.ts +174 -221
- 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 +38 -38
- package/src/plugin-content-docs.d.ts +570 -91
- package/src/props.ts +121 -20
- package/src/routes.ts +159 -0
- package/src/server-export.ts +26 -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 -259
- 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 -215
- package/lib/sidebars.d.ts +0 -45
- package/lib/sidebars.js +0 -354
- package/lib/theme/hooks/useDocs.d.ts +0 -20
- package/lib/theme/hooks/useDocs.js +0 -75
- 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/_partials/somePartial.md +0 -3
- package/src/__tests__/__fixtures__/simple-site/docs/_partials/subfolder/somePartial.md +0 -3
- package/src/__tests__/__fixtures__/simple-site/docs/_somePartial.md +0 -3
- 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/_partials/somePartial.md +0 -3
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/subfolder/somePartial.md +0 -3
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_somePartial.md +0 -3
- 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 -95
- package/src/__tests__/__snapshots__/index.test.ts.snap +0 -1926
- package/src/__tests__/__snapshots__/sidebars.test.ts.snap +0 -233
- package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -484
- package/src/__tests__/cli.test.ts +0 -337
- package/src/__tests__/docFrontMatter.test.ts +0 -244
- package/src/__tests__/docs.test.ts +0 -878
- package/src/__tests__/index.test.ts +0 -1885
- package/src/__tests__/lastUpdate.test.ts +0 -69
- package/src/__tests__/numberPrefix.test.ts +0 -199
- package/src/__tests__/options.test.ts +0 -272
- package/src/__tests__/sidebarItemsGenerator.test.ts +0 -358
- package/src/__tests__/sidebars.test.ts +0 -746
- package/src/__tests__/slug.test.ts +0 -109
- package/src/__tests__/translations.test.ts +0 -158
- 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 -315
- package/src/sidebars.ts +0 -589
- package/src/theme/hooks/useDocs.ts +0 -103
- 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,272 +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, validateOptions} from '../options';
|
|
9
|
-
import {normalizePluginOptions} from '@docusaurus/utils-validation';
|
|
10
|
-
import {DefaultSidebarItemsGenerator} from '../sidebarItemsGenerator';
|
|
11
|
-
import {
|
|
12
|
-
DefaultNumberPrefixParser,
|
|
13
|
-
DisabledNumberPrefixParser,
|
|
14
|
-
} from '../numberPrefix';
|
|
15
|
-
import {GlobExcludeDefault} from '@docusaurus/utils';
|
|
16
|
-
import {PluginOptions} from '../types';
|
|
17
|
-
|
|
18
|
-
// the type of remark/rehype plugins is function
|
|
19
|
-
const markdownPluginsFunctionStub = () => {};
|
|
20
|
-
const markdownPluginsObjectStub = {};
|
|
21
|
-
|
|
22
|
-
function testValidateOptions(options: Partial<PluginOptions>) {
|
|
23
|
-
return validateOptions({
|
|
24
|
-
options: {
|
|
25
|
-
...DEFAULT_OPTIONS,
|
|
26
|
-
...options,
|
|
27
|
-
},
|
|
28
|
-
validate: normalizePluginOptions,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
describe('normalizeDocsPluginOptions', () => {
|
|
33
|
-
test('should return default options for undefined user options', async () => {
|
|
34
|
-
const {value, error} = await OptionsSchema.validate({});
|
|
35
|
-
expect(value).toEqual(DEFAULT_OPTIONS);
|
|
36
|
-
expect(error).toBe(undefined);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('should accept correctly defined user options', async () => {
|
|
40
|
-
const userOptions = {
|
|
41
|
-
path: 'my-docs', // Path to data on filesystem, relative to site dir.
|
|
42
|
-
routeBasePath: 'my-docs', // URL Route.
|
|
43
|
-
homePageId: 'home', // Document id for docs home page.
|
|
44
|
-
include: ['**/*.{md,mdx}'], // Extensions to include.
|
|
45
|
-
exclude: GlobExcludeDefault,
|
|
46
|
-
sidebarPath: 'my-sidebar', // Path to sidebar configuration for showing a list of markdown pages.
|
|
47
|
-
sidebarItemsGenerator: DefaultSidebarItemsGenerator,
|
|
48
|
-
numberPrefixParser: DefaultNumberPrefixParser,
|
|
49
|
-
docLayoutComponent: '@theme/DocPage',
|
|
50
|
-
docItemComponent: '@theme/DocItem',
|
|
51
|
-
remarkPlugins: [markdownPluginsObjectStub],
|
|
52
|
-
rehypePlugins: [markdownPluginsFunctionStub],
|
|
53
|
-
beforeDefaultRehypePlugins: [],
|
|
54
|
-
beforeDefaultRemarkPlugins: [],
|
|
55
|
-
showLastUpdateTime: true,
|
|
56
|
-
showLastUpdateAuthor: true,
|
|
57
|
-
admonitions: {},
|
|
58
|
-
includeCurrentVersion: false,
|
|
59
|
-
disableVersioning: true,
|
|
60
|
-
editCurrentVersion: true,
|
|
61
|
-
editLocalizedFiles: true,
|
|
62
|
-
versions: {
|
|
63
|
-
current: {
|
|
64
|
-
path: 'next',
|
|
65
|
-
label: 'next',
|
|
66
|
-
},
|
|
67
|
-
version1: {
|
|
68
|
-
path: 'hello',
|
|
69
|
-
label: 'world',
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
sidebarCollapsible: false,
|
|
73
|
-
sidebarCollapsed: false,
|
|
74
|
-
};
|
|
75
|
-
const {value, error} = await OptionsSchema.validate(userOptions);
|
|
76
|
-
expect(value).toEqual(userOptions);
|
|
77
|
-
expect(error).toBe(undefined);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('should accept correctly defined remark and rehype plugin options', async () => {
|
|
81
|
-
const userOptions = {
|
|
82
|
-
...DEFAULT_OPTIONS,
|
|
83
|
-
beforeDefaultRemarkPlugins: [],
|
|
84
|
-
beforeDefaultRehypePlugins: [markdownPluginsFunctionStub],
|
|
85
|
-
remarkPlugins: [[markdownPluginsFunctionStub, {option1: '42'}]],
|
|
86
|
-
rehypePlugins: [
|
|
87
|
-
markdownPluginsObjectStub,
|
|
88
|
-
[markdownPluginsFunctionStub, {option1: '42'}],
|
|
89
|
-
],
|
|
90
|
-
};
|
|
91
|
-
const {value, error} = await OptionsSchema.validate(userOptions);
|
|
92
|
-
expect(value).toEqual(userOptions);
|
|
93
|
-
expect(error).toBe(undefined);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test('should accept admonitions false', async () => {
|
|
97
|
-
const admonitionsFalse = {
|
|
98
|
-
...DEFAULT_OPTIONS,
|
|
99
|
-
admonitions: false,
|
|
100
|
-
};
|
|
101
|
-
const {value, error} = OptionsSchema.validate(admonitionsFalse);
|
|
102
|
-
expect(value).toEqual(admonitionsFalse);
|
|
103
|
-
expect(error).toBe(undefined);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
test('should accept numberPrefixParser function', () => {
|
|
107
|
-
function customNumberPrefixParser() {}
|
|
108
|
-
expect(
|
|
109
|
-
normalizePluginOptions(OptionsSchema, {
|
|
110
|
-
...DEFAULT_OPTIONS,
|
|
111
|
-
numberPrefixParser: customNumberPrefixParser,
|
|
112
|
-
}),
|
|
113
|
-
).toEqual({
|
|
114
|
-
...DEFAULT_OPTIONS,
|
|
115
|
-
id: 'default',
|
|
116
|
-
numberPrefixParser: customNumberPrefixParser,
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
test('should accept numberPrefixParser false', () => {
|
|
121
|
-
expect(
|
|
122
|
-
normalizePluginOptions(OptionsSchema, {
|
|
123
|
-
...DEFAULT_OPTIONS,
|
|
124
|
-
numberPrefixParser: false,
|
|
125
|
-
}),
|
|
126
|
-
).toEqual({
|
|
127
|
-
...DEFAULT_OPTIONS,
|
|
128
|
-
id: 'default',
|
|
129
|
-
numberPrefixParser: DisabledNumberPrefixParser,
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test('should accept numberPrefixParser true', () => {
|
|
134
|
-
expect(
|
|
135
|
-
normalizePluginOptions(OptionsSchema, {
|
|
136
|
-
...DEFAULT_OPTIONS,
|
|
137
|
-
numberPrefixParser: true,
|
|
138
|
-
}),
|
|
139
|
-
).toEqual({
|
|
140
|
-
...DEFAULT_OPTIONS,
|
|
141
|
-
id: 'default',
|
|
142
|
-
numberPrefixParser: DefaultNumberPrefixParser,
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test('should reject admonitions true', async () => {
|
|
147
|
-
const admonitionsTrue = {
|
|
148
|
-
...DEFAULT_OPTIONS,
|
|
149
|
-
admonitions: true,
|
|
150
|
-
};
|
|
151
|
-
const {error} = OptionsSchema.validate(admonitionsTrue);
|
|
152
|
-
expect(error).toMatchInlineSnapshot(
|
|
153
|
-
`[ValidationError: "admonitions" contains an invalid value]`,
|
|
154
|
-
);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test('should reject invalid remark plugin options', () => {
|
|
158
|
-
expect(() => {
|
|
159
|
-
normalizePluginOptions(OptionsSchema, {
|
|
160
|
-
remarkPlugins: [[{option1: '42'}, markdownPluginsFunctionStub]],
|
|
161
|
-
});
|
|
162
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
163
|
-
`"\\"remarkPlugins[0]\\" does not match any of the allowed types"`,
|
|
164
|
-
);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
test('should reject invalid rehype plugin options', () => {
|
|
168
|
-
expect(() => {
|
|
169
|
-
normalizePluginOptions(OptionsSchema, {
|
|
170
|
-
rehypePlugins: [
|
|
171
|
-
[
|
|
172
|
-
markdownPluginsFunctionStub,
|
|
173
|
-
{option1: '42'},
|
|
174
|
-
markdownPluginsFunctionStub,
|
|
175
|
-
],
|
|
176
|
-
],
|
|
177
|
-
});
|
|
178
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
179
|
-
`"\\"rehypePlugins[0]\\" does not match any of the allowed types"`,
|
|
180
|
-
);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
test('should reject bad path inputs', () => {
|
|
184
|
-
expect(() => {
|
|
185
|
-
normalizePluginOptions(OptionsSchema, {
|
|
186
|
-
path: 2,
|
|
187
|
-
});
|
|
188
|
-
}).toThrowErrorMatchingInlineSnapshot(`"\\"path\\" must be a string"`);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
test('should reject bad include inputs', () => {
|
|
192
|
-
expect(() => {
|
|
193
|
-
normalizePluginOptions(OptionsSchema, {
|
|
194
|
-
include: '**/*.{md,mdx}',
|
|
195
|
-
});
|
|
196
|
-
}).toThrowErrorMatchingInlineSnapshot(`"\\"include\\" must be an array"`);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
test('should reject bad showLastUpdateTime inputs', () => {
|
|
200
|
-
expect(() => {
|
|
201
|
-
normalizePluginOptions(OptionsSchema, {
|
|
202
|
-
showLastUpdateTime: 'true',
|
|
203
|
-
});
|
|
204
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
205
|
-
`"\\"showLastUpdateTime\\" must be a boolean"`,
|
|
206
|
-
);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
test('should reject bad remarkPlugins input', () => {
|
|
210
|
-
expect(() => {
|
|
211
|
-
normalizePluginOptions(OptionsSchema, {
|
|
212
|
-
remarkPlugins: 'remark-math',
|
|
213
|
-
});
|
|
214
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
215
|
-
`"\\"remarkPlugins\\" must be an array"`,
|
|
216
|
-
);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
test('should reject bad lastVersion', () => {
|
|
220
|
-
expect(() => {
|
|
221
|
-
normalizePluginOptions(OptionsSchema, {
|
|
222
|
-
lastVersion: false,
|
|
223
|
-
});
|
|
224
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
225
|
-
`"\\"lastVersion\\" must be a string"`,
|
|
226
|
-
);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
test('should reject bad versions', () => {
|
|
230
|
-
expect(() => {
|
|
231
|
-
normalizePluginOptions(OptionsSchema, {
|
|
232
|
-
versions: {
|
|
233
|
-
current: {
|
|
234
|
-
hey: 3,
|
|
235
|
-
},
|
|
236
|
-
version1: {
|
|
237
|
-
path: 'hello',
|
|
238
|
-
label: 'world',
|
|
239
|
-
},
|
|
240
|
-
},
|
|
241
|
-
});
|
|
242
|
-
}).toThrowErrorMatchingInlineSnapshot(
|
|
243
|
-
`"\\"versions.current.hey\\" is not allowed"`,
|
|
244
|
-
);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
test('should handle sidebarCollapsed option inconsistencies', () => {
|
|
248
|
-
expect(
|
|
249
|
-
testValidateOptions({
|
|
250
|
-
...DEFAULT_OPTIONS,
|
|
251
|
-
sidebarCollapsible: true,
|
|
252
|
-
sidebarCollapsed: undefined,
|
|
253
|
-
}).sidebarCollapsed,
|
|
254
|
-
).toEqual(true);
|
|
255
|
-
|
|
256
|
-
expect(
|
|
257
|
-
testValidateOptions({
|
|
258
|
-
...DEFAULT_OPTIONS,
|
|
259
|
-
sidebarCollapsible: false,
|
|
260
|
-
sidebarCollapsed: undefined,
|
|
261
|
-
}).sidebarCollapsed,
|
|
262
|
-
).toEqual(false);
|
|
263
|
-
|
|
264
|
-
expect(
|
|
265
|
-
testValidateOptions({
|
|
266
|
-
...DEFAULT_OPTIONS,
|
|
267
|
-
sidebarCollapsible: false,
|
|
268
|
-
sidebarCollapsed: true,
|
|
269
|
-
}).sidebarCollapsed,
|
|
270
|
-
).toEqual(false);
|
|
271
|
-
});
|
|
272
|
-
});
|