@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
|
@@ -0,0 +1,183 @@
|
|
|
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
|
+
import type { Optional, Required } from 'utility-types';
|
|
8
|
+
import type { NumberPrefixParser, SidebarOptions, CategoryIndexMatcher, DocMetadataBase, VersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
9
|
+
import type { Slugger } from '@docusaurus/utils';
|
|
10
|
+
declare type Expand<T extends {
|
|
11
|
+
[x: string]: unknown;
|
|
12
|
+
}> = {
|
|
13
|
+
[P in keyof T]: T[P];
|
|
14
|
+
};
|
|
15
|
+
export declare type SidebarItemBase = {
|
|
16
|
+
className?: string;
|
|
17
|
+
customProps?: {
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export declare type SidebarItemDoc = SidebarItemBase & {
|
|
22
|
+
type: 'doc' | 'ref';
|
|
23
|
+
label?: string;
|
|
24
|
+
id: string;
|
|
25
|
+
/**
|
|
26
|
+
* This is an internal marker. Items with labels defined in the config needs
|
|
27
|
+
* to be translated with JSON
|
|
28
|
+
*/
|
|
29
|
+
translatable?: true;
|
|
30
|
+
};
|
|
31
|
+
export declare type SidebarItemHtml = SidebarItemBase & {
|
|
32
|
+
type: 'html';
|
|
33
|
+
value: string;
|
|
34
|
+
defaultStyle?: boolean;
|
|
35
|
+
};
|
|
36
|
+
export declare type SidebarItemLink = SidebarItemBase & {
|
|
37
|
+
type: 'link';
|
|
38
|
+
href: string;
|
|
39
|
+
label: string;
|
|
40
|
+
};
|
|
41
|
+
export declare type SidebarItemAutogenerated = SidebarItemBase & {
|
|
42
|
+
type: 'autogenerated';
|
|
43
|
+
dirName: string;
|
|
44
|
+
};
|
|
45
|
+
declare type SidebarItemCategoryBase = SidebarItemBase & {
|
|
46
|
+
type: 'category';
|
|
47
|
+
label: string;
|
|
48
|
+
collapsed: boolean;
|
|
49
|
+
collapsible: boolean;
|
|
50
|
+
};
|
|
51
|
+
export declare type SidebarItemCategoryLinkDoc = {
|
|
52
|
+
type: 'doc';
|
|
53
|
+
id: string;
|
|
54
|
+
};
|
|
55
|
+
export declare type SidebarItemCategoryLinkGeneratedIndexConfig = {
|
|
56
|
+
type: 'generated-index';
|
|
57
|
+
slug?: string;
|
|
58
|
+
title?: string;
|
|
59
|
+
description?: string;
|
|
60
|
+
image?: string;
|
|
61
|
+
keywords?: string | readonly string[];
|
|
62
|
+
};
|
|
63
|
+
export declare type SidebarItemCategoryLinkGeneratedIndex = {
|
|
64
|
+
type: 'generated-index';
|
|
65
|
+
slug: string;
|
|
66
|
+
permalink: string;
|
|
67
|
+
title?: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
image?: string;
|
|
70
|
+
keywords?: string | readonly string[];
|
|
71
|
+
};
|
|
72
|
+
export declare type SidebarItemCategoryLinkConfig = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndexConfig;
|
|
73
|
+
export declare type SidebarItemCategoryLink = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndex;
|
|
74
|
+
export declare type SidebarItemCategoryConfig = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
75
|
+
items: SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
76
|
+
link?: SidebarItemCategoryLinkConfig;
|
|
77
|
+
}>;
|
|
78
|
+
export declare type SidebarCategoriesShorthand = {
|
|
79
|
+
[sidebarCategory: string]: SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
80
|
+
};
|
|
81
|
+
export declare type SidebarItemConfig = Omit<SidebarItemDoc, 'translatable'> | SidebarItemHtml | SidebarItemLink | SidebarItemAutogenerated | SidebarItemCategoryConfig | string | SidebarCategoriesShorthand;
|
|
82
|
+
export declare type SidebarConfig = SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
83
|
+
export declare type SidebarsConfig = {
|
|
84
|
+
[sidebarId: string]: SidebarConfig;
|
|
85
|
+
};
|
|
86
|
+
export declare type NormalizedSidebarItemCategory = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
87
|
+
items: NormalizedSidebarItem[];
|
|
88
|
+
link?: SidebarItemCategoryLinkConfig;
|
|
89
|
+
}>;
|
|
90
|
+
export declare type NormalizedSidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | NormalizedSidebarItemCategory | SidebarItemAutogenerated;
|
|
91
|
+
export declare type NormalizedSidebar = NormalizedSidebarItem[];
|
|
92
|
+
export declare type NormalizedSidebars = {
|
|
93
|
+
[sidebarId: string]: NormalizedSidebar;
|
|
94
|
+
};
|
|
95
|
+
export declare type ProcessedSidebarItemCategory = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
96
|
+
items: ProcessedSidebarItem[];
|
|
97
|
+
link?: SidebarItemCategoryLinkConfig;
|
|
98
|
+
}>;
|
|
99
|
+
export declare type ProcessedSidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | ProcessedSidebarItemCategory;
|
|
100
|
+
export declare type ProcessedSidebar = ProcessedSidebarItem[];
|
|
101
|
+
export declare type ProcessedSidebars = {
|
|
102
|
+
[sidebarId: string]: ProcessedSidebar;
|
|
103
|
+
};
|
|
104
|
+
export declare type SidebarItemCategory = Expand<SidebarItemCategoryBase & {
|
|
105
|
+
items: SidebarItem[];
|
|
106
|
+
link?: SidebarItemCategoryLink;
|
|
107
|
+
}>;
|
|
108
|
+
export declare type SidebarItemCategoryWithLink = Required<SidebarItemCategory, 'link'>;
|
|
109
|
+
export declare type SidebarItemCategoryWithGeneratedIndex = SidebarItemCategoryWithLink & {
|
|
110
|
+
link: SidebarItemCategoryLinkGeneratedIndex;
|
|
111
|
+
};
|
|
112
|
+
export declare type SidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | SidebarItemCategory;
|
|
113
|
+
export declare type SidebarNavigationItem = SidebarItemDoc | SidebarItemCategoryWithLink;
|
|
114
|
+
export declare type Sidebar = SidebarItem[];
|
|
115
|
+
export declare type SidebarItemType = SidebarItem['type'];
|
|
116
|
+
export declare type Sidebars = {
|
|
117
|
+
[sidebarId: string]: Sidebar;
|
|
118
|
+
};
|
|
119
|
+
export declare type PropSidebarItemCategory = Expand<SidebarItemCategoryBase & {
|
|
120
|
+
items: PropSidebarItem[];
|
|
121
|
+
href?: string;
|
|
122
|
+
}>;
|
|
123
|
+
export declare type PropSidebarItemLink = SidebarItemLink & {
|
|
124
|
+
docId?: string;
|
|
125
|
+
};
|
|
126
|
+
export declare type PropSidebarItemHtml = SidebarItemHtml;
|
|
127
|
+
export declare type PropSidebarItem = PropSidebarItemLink | PropSidebarItemCategory | PropSidebarItemHtml;
|
|
128
|
+
export declare type PropSidebar = PropSidebarItem[];
|
|
129
|
+
export declare type PropSidebars = {
|
|
130
|
+
[sidebarId: string]: PropSidebar;
|
|
131
|
+
};
|
|
132
|
+
export declare type PropSidebarBreadcrumbsItem = PropSidebarItemLink | PropSidebarItemCategory;
|
|
133
|
+
export declare type CategoryMetadataFile = {
|
|
134
|
+
label?: string;
|
|
135
|
+
position?: number;
|
|
136
|
+
collapsed?: boolean;
|
|
137
|
+
collapsible?: boolean;
|
|
138
|
+
className?: string;
|
|
139
|
+
link?: SidebarItemCategoryLinkConfig | null;
|
|
140
|
+
customProps?: {
|
|
141
|
+
[key: string]: unknown;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'unversionedId' | 'title' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
|
|
145
|
+
export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
|
|
146
|
+
export declare type SidebarItemsGeneratorArgs = {
|
|
147
|
+
/** The sidebar item with type "autogenerated" to be transformed. */
|
|
148
|
+
item: SidebarItemAutogenerated;
|
|
149
|
+
/** Useful metadata for the version this sidebar belongs to. */
|
|
150
|
+
version: SidebarItemsGeneratorVersion;
|
|
151
|
+
/** All the docs of that version (unfiltered). */
|
|
152
|
+
docs: SidebarItemsGeneratorDoc[];
|
|
153
|
+
/** Number prefix parser configured for this plugin. */
|
|
154
|
+
numberPrefixParser: NumberPrefixParser;
|
|
155
|
+
/** The default category index matcher which you can override. */
|
|
156
|
+
isCategoryIndex: CategoryIndexMatcher;
|
|
157
|
+
/**
|
|
158
|
+
* Key is the path relative to the doc content directory, value is the
|
|
159
|
+
* category metadata file's content.
|
|
160
|
+
*/
|
|
161
|
+
categoriesMetadata: {
|
|
162
|
+
[filePath: string]: CategoryMetadataFile;
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => NormalizedSidebar | Promise<NormalizedSidebar>;
|
|
166
|
+
export declare type SidebarItemsGeneratorOption = (generatorArgs: {
|
|
167
|
+
/**
|
|
168
|
+
* Useful to re-use/enhance the default sidebar generation logic from
|
|
169
|
+
* Docusaurus.
|
|
170
|
+
* @see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320
|
|
171
|
+
*/
|
|
172
|
+
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
173
|
+
} & SidebarItemsGeneratorArgs) => NormalizedSidebar | Promise<NormalizedSidebar>;
|
|
174
|
+
export declare type SidebarProcessorParams = {
|
|
175
|
+
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
176
|
+
numberPrefixParser: NumberPrefixParser;
|
|
177
|
+
docs: DocMetadataBase[];
|
|
178
|
+
drafts: DocMetadataBase[];
|
|
179
|
+
version: VersionMetadata;
|
|
180
|
+
categoryLabelSlugger: Slugger;
|
|
181
|
+
sidebarOptions: SidebarOptions;
|
|
182
|
+
};
|
|
183
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
4
|
*
|
|
4
5
|
* This source code is licensed under the MIT license found in the
|
|
5
6
|
* LICENSE file in the root directory of this source tree.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
-
export declare function validateDocFrontMatter(frontMatter: Record<string, unknown>): DocFrontMatter;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
import type { Sidebars, Sidebar, SidebarItem, SidebarItemCategory, SidebarItemLink, SidebarItemDoc, SidebarCategoriesShorthand, SidebarItemConfig, SidebarItemCategoryWithGeneratedIndex, SidebarNavigationItem } from './types';
|
|
8
|
+
import type { DocMetadataBase, PropNavigationLink } from '@docusaurus/plugin-content-docs';
|
|
9
|
+
export declare function isCategoriesShorthand(item: SidebarItemConfig): item is SidebarCategoriesShorthand;
|
|
10
|
+
export declare function transformSidebarItems(sidebar: Sidebar, updateFn: (item: SidebarItem) => SidebarItem): Sidebar;
|
|
11
|
+
export declare function collectSidebarDocItems(sidebar: Sidebar): SidebarItemDoc[];
|
|
12
|
+
export declare function collectSidebarCategories(sidebar: Sidebar): SidebarItemCategory[];
|
|
13
|
+
export declare function collectSidebarLinks(sidebar: Sidebar): SidebarItemLink[];
|
|
14
|
+
export declare function collectSidebarRefs(sidebar: Sidebar): SidebarItemDoc[];
|
|
15
|
+
export declare function collectSidebarDocIds(sidebar: Sidebar): string[];
|
|
16
|
+
export declare function collectSidebarNavigation(sidebar: Sidebar): SidebarNavigationItem[];
|
|
17
|
+
export declare function collectSidebarsDocIds(sidebars: Sidebars): {
|
|
18
|
+
[sidebarId: string]: string[];
|
|
19
|
+
};
|
|
20
|
+
export declare function collectSidebarsNavigations(sidebars: Sidebars): {
|
|
21
|
+
[sidebarId: string]: SidebarNavigationItem[];
|
|
22
|
+
};
|
|
23
|
+
export declare type SidebarNavigation = {
|
|
24
|
+
sidebarName: string | undefined;
|
|
25
|
+
previous: SidebarNavigationItem | undefined;
|
|
26
|
+
next: SidebarNavigationItem | undefined;
|
|
27
|
+
};
|
|
28
|
+
export declare type SidebarsUtils = {
|
|
29
|
+
sidebars: Sidebars;
|
|
30
|
+
getFirstDocIdOfFirstSidebar: () => string | undefined;
|
|
31
|
+
getSidebarNameByDocId: (docId: string) => string | undefined;
|
|
32
|
+
getDocNavigation: (unversionedId: string, versionedId: string, displayedSidebar: string | null | undefined) => SidebarNavigation;
|
|
33
|
+
getCategoryGeneratedIndexList: () => SidebarItemCategoryWithGeneratedIndex[];
|
|
34
|
+
getCategoryGeneratedIndexNavigation: (categoryGeneratedIndexPermalink: string) => SidebarNavigation;
|
|
35
|
+
/**
|
|
36
|
+
* This function may return undefined. This is usually a user mistake, because
|
|
37
|
+
* it means this sidebar will never be displayed; however, we can still use
|
|
38
|
+
* `displayed_sidebar` to make it displayed. Pretty weird but valid use-case
|
|
39
|
+
*/
|
|
40
|
+
getFirstLink: (sidebarId: string) => {
|
|
41
|
+
type: 'doc';
|
|
42
|
+
id: string;
|
|
43
|
+
label: string;
|
|
44
|
+
} | {
|
|
45
|
+
type: 'generated-index';
|
|
46
|
+
permalink: string;
|
|
47
|
+
label: string;
|
|
48
|
+
} | undefined;
|
|
49
|
+
checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
|
|
50
|
+
};
|
|
51
|
+
export declare function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils;
|
|
52
|
+
export declare function toDocNavigationLink(doc: DocMetadataBase): PropNavigationLink;
|
|
53
|
+
export declare function toNavigationLink(navigationItem: SidebarNavigationItem | undefined, docsById: {
|
|
54
|
+
[docId: string]: DocMetadataBase;
|
|
55
|
+
}): PropNavigationLink | undefined;
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.toNavigationLink = exports.toDocNavigationLink = exports.createSidebarsUtils = exports.collectSidebarsNavigations = exports.collectSidebarsDocIds = exports.collectSidebarNavigation = exports.collectSidebarDocIds = exports.collectSidebarRefs = exports.collectSidebarLinks = exports.collectSidebarCategories = exports.collectSidebarDocItems = exports.transformSidebarItems = exports.isCategoriesShorthand = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
|
+
const utils_1 = require("@docusaurus/utils");
|
|
13
|
+
function isCategoriesShorthand(item) {
|
|
14
|
+
return typeof item === 'object' && !item.type;
|
|
15
|
+
}
|
|
16
|
+
exports.isCategoriesShorthand = isCategoriesShorthand;
|
|
17
|
+
function transformSidebarItems(sidebar, updateFn) {
|
|
18
|
+
function transformRecursive(item) {
|
|
19
|
+
if (item.type === 'category') {
|
|
20
|
+
return updateFn({
|
|
21
|
+
...item,
|
|
22
|
+
items: item.items.map(transformRecursive),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return updateFn(item);
|
|
26
|
+
}
|
|
27
|
+
return sidebar.map(transformRecursive);
|
|
28
|
+
}
|
|
29
|
+
exports.transformSidebarItems = transformSidebarItems;
|
|
30
|
+
/**
|
|
31
|
+
* Flatten sidebar items into a single flat array (containing categories/docs on
|
|
32
|
+
* the same level). Order matters (useful for next/prev nav), top categories
|
|
33
|
+
* appear before their child elements
|
|
34
|
+
*/
|
|
35
|
+
function flattenSidebarItems(items) {
|
|
36
|
+
function flattenRecursive(item) {
|
|
37
|
+
return item.type === 'category'
|
|
38
|
+
? [item, ...item.items.flatMap(flattenRecursive)]
|
|
39
|
+
: [item];
|
|
40
|
+
}
|
|
41
|
+
return items.flatMap(flattenRecursive);
|
|
42
|
+
}
|
|
43
|
+
function collectSidebarItemsOfType(type, sidebar) {
|
|
44
|
+
return flattenSidebarItems(sidebar).filter((item) => item.type === type);
|
|
45
|
+
}
|
|
46
|
+
function collectSidebarDocItems(sidebar) {
|
|
47
|
+
return collectSidebarItemsOfType('doc', sidebar);
|
|
48
|
+
}
|
|
49
|
+
exports.collectSidebarDocItems = collectSidebarDocItems;
|
|
50
|
+
function collectSidebarCategories(sidebar) {
|
|
51
|
+
return collectSidebarItemsOfType('category', sidebar);
|
|
52
|
+
}
|
|
53
|
+
exports.collectSidebarCategories = collectSidebarCategories;
|
|
54
|
+
function collectSidebarLinks(sidebar) {
|
|
55
|
+
return collectSidebarItemsOfType('link', sidebar);
|
|
56
|
+
}
|
|
57
|
+
exports.collectSidebarLinks = collectSidebarLinks;
|
|
58
|
+
function collectSidebarRefs(sidebar) {
|
|
59
|
+
return collectSidebarItemsOfType('ref', sidebar);
|
|
60
|
+
}
|
|
61
|
+
exports.collectSidebarRefs = collectSidebarRefs;
|
|
62
|
+
// /!\ docId order matters for navigation!
|
|
63
|
+
function collectSidebarDocIds(sidebar) {
|
|
64
|
+
return flattenSidebarItems(sidebar).flatMap((item) => {
|
|
65
|
+
if (item.type === 'category') {
|
|
66
|
+
return item.link?.type === 'doc' ? [item.link.id] : [];
|
|
67
|
+
}
|
|
68
|
+
if (item.type === 'doc') {
|
|
69
|
+
return [item.id];
|
|
70
|
+
}
|
|
71
|
+
return [];
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
exports.collectSidebarDocIds = collectSidebarDocIds;
|
|
75
|
+
function collectSidebarNavigation(sidebar) {
|
|
76
|
+
return flattenSidebarItems(sidebar).flatMap((item) => {
|
|
77
|
+
if (item.type === 'category' && item.link) {
|
|
78
|
+
return [item];
|
|
79
|
+
}
|
|
80
|
+
if (item.type === 'doc') {
|
|
81
|
+
return [item];
|
|
82
|
+
}
|
|
83
|
+
return [];
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
exports.collectSidebarNavigation = collectSidebarNavigation;
|
|
87
|
+
function collectSidebarsDocIds(sidebars) {
|
|
88
|
+
return lodash_1.default.mapValues(sidebars, collectSidebarDocIds);
|
|
89
|
+
}
|
|
90
|
+
exports.collectSidebarsDocIds = collectSidebarsDocIds;
|
|
91
|
+
function collectSidebarsNavigations(sidebars) {
|
|
92
|
+
return lodash_1.default.mapValues(sidebars, collectSidebarNavigation);
|
|
93
|
+
}
|
|
94
|
+
exports.collectSidebarsNavigations = collectSidebarsNavigations;
|
|
95
|
+
function createSidebarsUtils(sidebars) {
|
|
96
|
+
const sidebarNameToDocIds = collectSidebarsDocIds(sidebars);
|
|
97
|
+
const sidebarNameToNavigationItems = collectSidebarsNavigations(sidebars);
|
|
98
|
+
// Reverse mapping
|
|
99
|
+
const docIdToSidebarName = Object.fromEntries(Object.entries(sidebarNameToDocIds).flatMap(([sidebarName, docIds]) => docIds.map((docId) => [docId, sidebarName])));
|
|
100
|
+
function getFirstDocIdOfFirstSidebar() {
|
|
101
|
+
return Object.values(sidebarNameToDocIds)[0]?.[0];
|
|
102
|
+
}
|
|
103
|
+
function getSidebarNameByDocId(docId) {
|
|
104
|
+
return docIdToSidebarName[docId];
|
|
105
|
+
}
|
|
106
|
+
function emptySidebarNavigation() {
|
|
107
|
+
return {
|
|
108
|
+
sidebarName: undefined,
|
|
109
|
+
previous: undefined,
|
|
110
|
+
next: undefined,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function getDocNavigation(unversionedId, versionedId, displayedSidebar) {
|
|
114
|
+
// TODO legacy id retro-compatibility!
|
|
115
|
+
let docId = unversionedId;
|
|
116
|
+
let sidebarName = displayedSidebar === undefined
|
|
117
|
+
? getSidebarNameByDocId(docId)
|
|
118
|
+
: displayedSidebar;
|
|
119
|
+
if (sidebarName === undefined) {
|
|
120
|
+
docId = versionedId;
|
|
121
|
+
sidebarName = getSidebarNameByDocId(docId);
|
|
122
|
+
}
|
|
123
|
+
if (!sidebarName) {
|
|
124
|
+
return emptySidebarNavigation();
|
|
125
|
+
}
|
|
126
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
127
|
+
if (!navigationItems) {
|
|
128
|
+
throw new Error(`Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`);
|
|
129
|
+
}
|
|
130
|
+
const currentItemIndex = navigationItems.findIndex((item) => {
|
|
131
|
+
if (item.type === 'doc') {
|
|
132
|
+
return item.id === docId;
|
|
133
|
+
}
|
|
134
|
+
if (item.type === 'category' && item.link.type === 'doc') {
|
|
135
|
+
return item.link.id === docId;
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
});
|
|
139
|
+
if (currentItemIndex === -1) {
|
|
140
|
+
return { sidebarName, next: undefined, previous: undefined };
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
sidebarName,
|
|
144
|
+
previous: navigationItems[currentItemIndex - 1],
|
|
145
|
+
next: navigationItems[currentItemIndex + 1],
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function getCategoryGeneratedIndexList() {
|
|
149
|
+
return Object.values(sidebarNameToNavigationItems)
|
|
150
|
+
.flat()
|
|
151
|
+
.flatMap((item) => {
|
|
152
|
+
if (item.type === 'category' && item.link.type === 'generated-index') {
|
|
153
|
+
return [item];
|
|
154
|
+
}
|
|
155
|
+
return [];
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* We identity the category generated index by its permalink (should be
|
|
160
|
+
* unique). More reliable than using object identity
|
|
161
|
+
*/
|
|
162
|
+
function getCategoryGeneratedIndexNavigation(categoryGeneratedIndexPermalink) {
|
|
163
|
+
function isCurrentCategoryGeneratedIndexItem(item) {
|
|
164
|
+
return (item.type === 'category' &&
|
|
165
|
+
item.link.type === 'generated-index' &&
|
|
166
|
+
item.link.permalink === categoryGeneratedIndexPermalink);
|
|
167
|
+
}
|
|
168
|
+
const sidebarName = Object.entries(sidebarNameToNavigationItems).find(([, navigationItems]) => navigationItems.find(isCurrentCategoryGeneratedIndexItem))[0];
|
|
169
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
170
|
+
const currentItemIndex = navigationItems.findIndex(isCurrentCategoryGeneratedIndexItem);
|
|
171
|
+
return {
|
|
172
|
+
sidebarName,
|
|
173
|
+
previous: navigationItems[currentItemIndex - 1],
|
|
174
|
+
next: navigationItems[currentItemIndex + 1],
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function checkSidebarsDocIds(validDocIds, sidebarFilePath) {
|
|
178
|
+
const allSidebarDocIds = Object.values(sidebarNameToDocIds).flat();
|
|
179
|
+
const invalidSidebarDocIds = lodash_1.default.difference(allSidebarDocIds, validDocIds);
|
|
180
|
+
if (invalidSidebarDocIds.length > 0) {
|
|
181
|
+
throw new Error(`Invalid sidebar file at "${(0, utils_1.toMessageRelativeFilePath)(sidebarFilePath)}".
|
|
182
|
+
These sidebar document ids do not exist:
|
|
183
|
+
- ${invalidSidebarDocIds.sort().join('\n- ')}
|
|
184
|
+
|
|
185
|
+
Available document ids are:
|
|
186
|
+
- ${lodash_1.default.uniq(validDocIds).sort().join('\n- ')}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function getFirstLink(sidebar) {
|
|
190
|
+
for (const item of sidebar) {
|
|
191
|
+
if (item.type === 'doc') {
|
|
192
|
+
return {
|
|
193
|
+
type: 'doc',
|
|
194
|
+
id: item.id,
|
|
195
|
+
label: item.label ?? item.id,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
else if (item.type === 'category') {
|
|
199
|
+
if (item.link?.type === 'doc') {
|
|
200
|
+
return {
|
|
201
|
+
type: 'doc',
|
|
202
|
+
id: item.link.id,
|
|
203
|
+
label: item.label,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
else if (item.link?.type === 'generated-index') {
|
|
207
|
+
return {
|
|
208
|
+
type: 'generated-index',
|
|
209
|
+
permalink: item.link.permalink,
|
|
210
|
+
label: item.label,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const firstSubItem = getFirstLink(item.items);
|
|
214
|
+
if (firstSubItem) {
|
|
215
|
+
return firstSubItem;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
sidebars,
|
|
223
|
+
getFirstDocIdOfFirstSidebar,
|
|
224
|
+
getSidebarNameByDocId,
|
|
225
|
+
getDocNavigation,
|
|
226
|
+
getCategoryGeneratedIndexList,
|
|
227
|
+
getCategoryGeneratedIndexNavigation,
|
|
228
|
+
checkSidebarsDocIds,
|
|
229
|
+
getFirstLink: (id) => getFirstLink(sidebars[id]),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
exports.createSidebarsUtils = createSidebarsUtils;
|
|
233
|
+
function toDocNavigationLink(doc) {
|
|
234
|
+
const { title, permalink, frontMatter: { pagination_label: paginationLabel, sidebar_label: sidebarLabel, }, } = doc;
|
|
235
|
+
return { title: paginationLabel ?? sidebarLabel ?? title, permalink };
|
|
236
|
+
}
|
|
237
|
+
exports.toDocNavigationLink = toDocNavigationLink;
|
|
238
|
+
function toNavigationLink(navigationItem, docsById) {
|
|
239
|
+
function getDocById(docId) {
|
|
240
|
+
const doc = docsById[docId];
|
|
241
|
+
if (!doc) {
|
|
242
|
+
throw new Error(`Can't create navigation link: no doc found with id=${docId}`);
|
|
243
|
+
}
|
|
244
|
+
return doc;
|
|
245
|
+
}
|
|
246
|
+
if (!navigationItem) {
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
if (navigationItem.type === 'category') {
|
|
250
|
+
return navigationItem.link.type === 'doc'
|
|
251
|
+
? toDocNavigationLink(getDocById(navigationItem.link.id))
|
|
252
|
+
: {
|
|
253
|
+
title: navigationItem.label,
|
|
254
|
+
permalink: navigationItem.link.permalink,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
return toDocNavigationLink(getDocById(navigationItem.id));
|
|
258
|
+
}
|
|
259
|
+
exports.toNavigationLink = toNavigationLink;
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
import type { NormalizedSidebars, CategoryMetadataFile } from './types';
|
|
8
|
+
export declare function validateSidebars(sidebars: {
|
|
9
|
+
[sidebarId: string]: unknown;
|
|
10
|
+
}): asserts sidebars is NormalizedSidebars;
|
|
11
|
+
export declare function validateCategoryMetadataFile(unsafeContent: unknown): CategoryMetadataFile;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.validateCategoryMetadataFile = exports.validateSidebars = void 0;
|
|
10
|
+
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
|
+
// NOTE: we don't add any default values during validation on purpose!
|
|
12
|
+
// Config types are exposed to users for typechecking and we use the same type
|
|
13
|
+
// in normalization
|
|
14
|
+
const sidebarItemBaseSchema = utils_validation_1.Joi.object({
|
|
15
|
+
className: utils_validation_1.Joi.string(),
|
|
16
|
+
customProps: utils_validation_1.Joi.object().unknown(),
|
|
17
|
+
});
|
|
18
|
+
const sidebarItemAutogeneratedSchema = sidebarItemBaseSchema.append({
|
|
19
|
+
type: 'autogenerated',
|
|
20
|
+
dirName: utils_validation_1.Joi.string()
|
|
21
|
+
.required()
|
|
22
|
+
.pattern(/^[^/](?:.*[^/])?$/)
|
|
23
|
+
.message('"dirName" must be a dir path relative to the docs folder root, and should not start or end with slash'),
|
|
24
|
+
});
|
|
25
|
+
const sidebarItemDocSchema = sidebarItemBaseSchema.append({
|
|
26
|
+
type: utils_validation_1.Joi.string().valid('doc', 'ref').required(),
|
|
27
|
+
id: utils_validation_1.Joi.string().required(),
|
|
28
|
+
label: utils_validation_1.Joi.string(),
|
|
29
|
+
translatable: utils_validation_1.Joi.boolean(),
|
|
30
|
+
});
|
|
31
|
+
const sidebarItemHtmlSchema = sidebarItemBaseSchema.append({
|
|
32
|
+
type: 'html',
|
|
33
|
+
value: utils_validation_1.Joi.string().required(),
|
|
34
|
+
defaultStyle: utils_validation_1.Joi.boolean(),
|
|
35
|
+
});
|
|
36
|
+
const sidebarItemLinkSchema = sidebarItemBaseSchema.append({
|
|
37
|
+
type: 'link',
|
|
38
|
+
href: utils_validation_1.URISchema.required(),
|
|
39
|
+
label: utils_validation_1.Joi.string()
|
|
40
|
+
.required()
|
|
41
|
+
.messages({ 'any.unknown': '"label" must be a string' }),
|
|
42
|
+
});
|
|
43
|
+
const sidebarItemCategoryLinkSchema = utils_validation_1.Joi.object()
|
|
44
|
+
.allow(null)
|
|
45
|
+
.when('.type', {
|
|
46
|
+
switch: [
|
|
47
|
+
{
|
|
48
|
+
is: 'doc',
|
|
49
|
+
then: utils_validation_1.Joi.object({
|
|
50
|
+
type: 'doc',
|
|
51
|
+
id: utils_validation_1.Joi.string().required(),
|
|
52
|
+
}),
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
is: 'generated-index',
|
|
56
|
+
then: utils_validation_1.Joi.object({
|
|
57
|
+
type: 'generated-index',
|
|
58
|
+
slug: utils_validation_1.Joi.string().optional(),
|
|
59
|
+
// This one is not in the user config, only in the normalized version
|
|
60
|
+
// permalink: Joi.string().optional(),
|
|
61
|
+
title: utils_validation_1.Joi.string().optional(),
|
|
62
|
+
description: utils_validation_1.Joi.string().optional(),
|
|
63
|
+
image: utils_validation_1.Joi.string().optional(),
|
|
64
|
+
keywords: [utils_validation_1.Joi.string(), utils_validation_1.Joi.array().items(utils_validation_1.Joi.string())],
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
is: utils_validation_1.Joi.required(),
|
|
69
|
+
then: utils_validation_1.Joi.forbidden().messages({
|
|
70
|
+
'any.unknown': 'Unknown sidebar category link type "{.type}".',
|
|
71
|
+
}),
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
});
|
|
75
|
+
const sidebarItemCategorySchema = sidebarItemBaseSchema.append({
|
|
76
|
+
type: 'category',
|
|
77
|
+
label: utils_validation_1.Joi.string()
|
|
78
|
+
.required()
|
|
79
|
+
.messages({ 'any.unknown': '"label" must be a string' }),
|
|
80
|
+
items: utils_validation_1.Joi.array()
|
|
81
|
+
.required()
|
|
82
|
+
.messages({ 'any.unknown': '"items" must be an array' }),
|
|
83
|
+
// TODO: Joi doesn't allow mutual recursion. See https://github.com/sideway/joi/issues/2611
|
|
84
|
+
// .items(Joi.link('#sidebarItemSchema')),
|
|
85
|
+
link: sidebarItemCategoryLinkSchema,
|
|
86
|
+
collapsed: utils_validation_1.Joi.boolean().messages({
|
|
87
|
+
'any.unknown': '"collapsed" must be a boolean',
|
|
88
|
+
}),
|
|
89
|
+
collapsible: utils_validation_1.Joi.boolean().messages({
|
|
90
|
+
'any.unknown': '"collapsible" must be a boolean',
|
|
91
|
+
}),
|
|
92
|
+
});
|
|
93
|
+
const sidebarItemSchema = utils_validation_1.Joi.object().when('.type', {
|
|
94
|
+
switch: [
|
|
95
|
+
{ is: 'link', then: sidebarItemLinkSchema },
|
|
96
|
+
{
|
|
97
|
+
is: utils_validation_1.Joi.string().valid('doc', 'ref').required(),
|
|
98
|
+
then: sidebarItemDocSchema,
|
|
99
|
+
},
|
|
100
|
+
{ is: 'html', then: sidebarItemHtmlSchema },
|
|
101
|
+
{ is: 'autogenerated', then: sidebarItemAutogeneratedSchema },
|
|
102
|
+
{ is: 'category', then: sidebarItemCategorySchema },
|
|
103
|
+
{
|
|
104
|
+
is: utils_validation_1.Joi.any().required(),
|
|
105
|
+
then: utils_validation_1.Joi.forbidden().messages({
|
|
106
|
+
'any.unknown': 'Unknown sidebar item type "{.type}".',
|
|
107
|
+
}),
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
});
|
|
111
|
+
// .id('sidebarItemSchema');
|
|
112
|
+
function validateSidebarItem(item) {
|
|
113
|
+
// TODO: remove once with proper Joi support
|
|
114
|
+
// Because we can't use Joi to validate nested items (see above), we do it
|
|
115
|
+
// manually
|
|
116
|
+
utils_validation_1.Joi.assert(item, sidebarItemSchema);
|
|
117
|
+
if (item.type === 'category') {
|
|
118
|
+
item.items.forEach(validateSidebarItem);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function validateSidebars(sidebars) {
|
|
122
|
+
Object.values(sidebars).forEach((sidebar) => {
|
|
123
|
+
sidebar.forEach(validateSidebarItem);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
exports.validateSidebars = validateSidebars;
|
|
127
|
+
const categoryMetadataFileSchema = utils_validation_1.Joi.object({
|
|
128
|
+
label: utils_validation_1.Joi.string(),
|
|
129
|
+
position: utils_validation_1.Joi.number(),
|
|
130
|
+
collapsed: utils_validation_1.Joi.boolean(),
|
|
131
|
+
collapsible: utils_validation_1.Joi.boolean(),
|
|
132
|
+
className: utils_validation_1.Joi.string(),
|
|
133
|
+
link: sidebarItemCategoryLinkSchema,
|
|
134
|
+
customProps: utils_validation_1.Joi.object().unknown(),
|
|
135
|
+
});
|
|
136
|
+
function validateCategoryMetadataFile(unsafeContent) {
|
|
137
|
+
const { error, value } = categoryMetadataFileSchema.validate(unsafeContent);
|
|
138
|
+
if (error) {
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
exports.validateCategoryMetadataFile = validateCategoryMetadataFile;
|
package/lib/slug.d.ts
CHANGED
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { NumberPrefixParser } from '
|
|
8
|
-
export default function getSlug({ baseID,
|
|
7
|
+
import type { NumberPrefixParser, DocMetadataBase } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
export default function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumberPrefixes, numberPrefixParser, }: {
|
|
9
9
|
baseID: string;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
frontMatterSlug?: string;
|
|
11
|
+
source: DocMetadataBase['source'];
|
|
12
|
+
sourceDirName: DocMetadataBase['sourceDirName'];
|
|
12
13
|
stripDirNumberPrefixes?: boolean;
|
|
13
14
|
numberPrefixParser?: NumberPrefixParser;
|
|
14
15
|
}): string;
|