@docusaurus/plugin-content-docs 2.0.0-beta.ff31de0ff → 2.0.0-rc.1
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 +62 -72
- package/lib/client/docsClientUtils.d.ts +9 -28
- package/lib/client/docsClientUtils.js +35 -51
- 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 +35 -8
- package/lib/docs.js +211 -78
- package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js → lib/frontMatter.d.ts} +4 -10
- package/lib/frontMatter.js +53 -0
- package/lib/globalData.d.ts +3 -3
- package/lib/globalData.js +35 -6
- package/lib/index.d.ts +3 -3
- package/lib/index.js +137 -146
- 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 +7 -4
- package/lib/numberPrefix.d.ts +1 -1
- package/lib/numberPrefix.js +16 -21
- package/lib/options.d.ts +3 -5
- package/lib/options.js +57 -29
- package/lib/props.d.ts +7 -2
- package/lib/props.js +87 -16
- 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 -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/{types.d.ts → lib/sidebars/types.js} +2 -7
- 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 +29 -19
- 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 -172
- 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 -29
- package/src/categoryGeneratedIndex.ts +60 -0
- package/src/cli.ts +94 -114
- package/src/client/docsClientUtils.ts +47 -84
- package/src/client/index.ts +158 -0
- package/src/constants.ts +4 -2
- package/src/docs.ts +294 -78
- package/src/frontMatter.ts +63 -0
- package/src/globalData.ts +57 -7
- package/src/index.ts +200 -204
- package/src/lastUpdate.ts +27 -34
- package/src/markdown/index.ts +10 -16
- package/src/markdown/linkify.ts +8 -5
- package/src/numberPrefix.ts +19 -26
- package/src/options.ts +61 -43
- package/src/plugin-content-docs.d.ts +575 -78
- package/src/props.ts +128 -23
- 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 +42 -23
- package/src/tags.ts +20 -0
- package/src/translations.ts +155 -124
- package/src/types.ts +17 -234
- 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 -4673
- package/lib/docFrontMatter.d.ts +0 -21
- package/lib/docFrontMatter.js +0 -33
- package/lib/sidebarItemsGenerator.js +0 -211
- package/lib/sidebars.d.ts +0 -42
- package/lib/sidebars.js +0 -309
- 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 -287
- 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 -67
- package/src/__tests__/__fixtures__/simple-site/docs/headingAsTitle.md +0 -1
- package/src/__tests__/__fixtures__/simple-site/docs/hello.md +0 -52
- 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/docusaurus.config.js +0 -14
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars.js +0 -23
- 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 -1907
- 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 -204
- package/src/__tests__/docs.test.ts +0 -875
- package/src/__tests__/index.test.ts +0 -1831
- package/src/__tests__/lastUpdate.test.ts +0 -68
- package/src/__tests__/numberPrefix.test.ts +0 -199
- package/src/__tests__/options.test.ts +0 -232
- package/src/__tests__/sidebarItemsGenerator.test.ts +0 -336
- package/src/__tests__/sidebars.test.ts +0 -638
- package/src/__tests__/slug.test.ts +0 -109
- package/src/__tests__/translations.test.ts +0 -159
- package/src/__tests__/versions.test.ts +0 -718
- package/src/client/__tests__/docsClientUtils.test.ts +0 -372
- package/src/docFrontMatter.ts +0 -53
- 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 -489
- package/src/theme/hooks/useDocs.ts +0 -99
- package/src/versions.ts +0 -511
- package/tsconfig.json +0 -9
|
@@ -0,0 +1,280 @@
|
|
|
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 type {Optional, Required} from 'utility-types';
|
|
9
|
+
import type {
|
|
10
|
+
NumberPrefixParser,
|
|
11
|
+
SidebarOptions,
|
|
12
|
+
CategoryIndexMatcher,
|
|
13
|
+
DocMetadataBase,
|
|
14
|
+
VersionMetadata,
|
|
15
|
+
} from '@docusaurus/plugin-content-docs';
|
|
16
|
+
import type {Slugger} from '@docusaurus/utils';
|
|
17
|
+
|
|
18
|
+
// Makes all properties visible when hovering over the type
|
|
19
|
+
type Expand<T extends {[x: string]: unknown}> = {[P in keyof T]: T[P]};
|
|
20
|
+
|
|
21
|
+
export type SidebarItemBase = {
|
|
22
|
+
className?: string;
|
|
23
|
+
customProps?: {[key: string]: unknown};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type SidebarItemDoc = SidebarItemBase & {
|
|
27
|
+
type: 'doc' | 'ref';
|
|
28
|
+
label?: string;
|
|
29
|
+
id: string;
|
|
30
|
+
/**
|
|
31
|
+
* This is an internal marker. Items with labels defined in the config needs
|
|
32
|
+
* to be translated with JSON
|
|
33
|
+
*/
|
|
34
|
+
translatable?: true;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type SidebarItemHtml = SidebarItemBase & {
|
|
38
|
+
type: 'html';
|
|
39
|
+
value: string;
|
|
40
|
+
defaultStyle?: boolean;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type SidebarItemLink = SidebarItemBase & {
|
|
44
|
+
type: 'link';
|
|
45
|
+
href: string;
|
|
46
|
+
label: string;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type SidebarItemAutogenerated = SidebarItemBase & {
|
|
50
|
+
type: 'autogenerated';
|
|
51
|
+
dirName: string;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type SidebarItemCategoryBase = SidebarItemBase & {
|
|
55
|
+
type: 'category';
|
|
56
|
+
label: string;
|
|
57
|
+
collapsed: boolean;
|
|
58
|
+
collapsible: boolean;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type SidebarItemCategoryLinkDoc = {type: 'doc'; id: string};
|
|
62
|
+
|
|
63
|
+
export type SidebarItemCategoryLinkGeneratedIndexConfig = {
|
|
64
|
+
type: 'generated-index';
|
|
65
|
+
slug?: string;
|
|
66
|
+
title?: string;
|
|
67
|
+
description?: string;
|
|
68
|
+
image?: string;
|
|
69
|
+
keywords?: string | readonly string[];
|
|
70
|
+
};
|
|
71
|
+
export type SidebarItemCategoryLinkGeneratedIndex = {
|
|
72
|
+
type: 'generated-index';
|
|
73
|
+
slug: string;
|
|
74
|
+
permalink: string;
|
|
75
|
+
title?: string;
|
|
76
|
+
description?: string;
|
|
77
|
+
image?: string;
|
|
78
|
+
keywords?: string | readonly string[];
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type SidebarItemCategoryLinkConfig =
|
|
82
|
+
| SidebarItemCategoryLinkDoc
|
|
83
|
+
| SidebarItemCategoryLinkGeneratedIndexConfig;
|
|
84
|
+
|
|
85
|
+
export type SidebarItemCategoryLink =
|
|
86
|
+
| SidebarItemCategoryLinkDoc
|
|
87
|
+
| SidebarItemCategoryLinkGeneratedIndex;
|
|
88
|
+
|
|
89
|
+
// The user-given configuration in sidebars.js, before normalization
|
|
90
|
+
export type SidebarItemCategoryConfig = Expand<
|
|
91
|
+
Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
92
|
+
items: SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
93
|
+
link?: SidebarItemCategoryLinkConfig;
|
|
94
|
+
}
|
|
95
|
+
>;
|
|
96
|
+
|
|
97
|
+
export type SidebarCategoriesShorthand = {
|
|
98
|
+
[sidebarCategory: string]: SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export type SidebarItemConfig =
|
|
102
|
+
| Omit<SidebarItemDoc, 'translatable'>
|
|
103
|
+
| SidebarItemHtml
|
|
104
|
+
| SidebarItemLink
|
|
105
|
+
| SidebarItemAutogenerated
|
|
106
|
+
| SidebarItemCategoryConfig
|
|
107
|
+
| string
|
|
108
|
+
| SidebarCategoriesShorthand;
|
|
109
|
+
|
|
110
|
+
export type SidebarConfig = SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
111
|
+
export type SidebarsConfig = {
|
|
112
|
+
[sidebarId: string]: SidebarConfig;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// Normalized but still has 'autogenerated', which will be handled in processing
|
|
116
|
+
export type NormalizedSidebarItemCategory = Expand<
|
|
117
|
+
Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
118
|
+
items: NormalizedSidebarItem[];
|
|
119
|
+
link?: SidebarItemCategoryLinkConfig;
|
|
120
|
+
}
|
|
121
|
+
>;
|
|
122
|
+
|
|
123
|
+
export type NormalizedSidebarItem =
|
|
124
|
+
| SidebarItemDoc
|
|
125
|
+
| SidebarItemHtml
|
|
126
|
+
| SidebarItemLink
|
|
127
|
+
| NormalizedSidebarItemCategory
|
|
128
|
+
| SidebarItemAutogenerated;
|
|
129
|
+
|
|
130
|
+
export type NormalizedSidebar = NormalizedSidebarItem[];
|
|
131
|
+
export type NormalizedSidebars = {
|
|
132
|
+
[sidebarId: string]: NormalizedSidebar;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export type ProcessedSidebarItemCategory = Expand<
|
|
136
|
+
Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
137
|
+
items: ProcessedSidebarItem[];
|
|
138
|
+
link?: SidebarItemCategoryLinkConfig;
|
|
139
|
+
}
|
|
140
|
+
>;
|
|
141
|
+
export type ProcessedSidebarItem =
|
|
142
|
+
| SidebarItemDoc
|
|
143
|
+
| SidebarItemHtml
|
|
144
|
+
| SidebarItemLink
|
|
145
|
+
| ProcessedSidebarItemCategory;
|
|
146
|
+
export type ProcessedSidebar = ProcessedSidebarItem[];
|
|
147
|
+
export type ProcessedSidebars = {
|
|
148
|
+
[sidebarId: string]: ProcessedSidebar;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export type SidebarItemCategory = Expand<
|
|
152
|
+
SidebarItemCategoryBase & {
|
|
153
|
+
items: SidebarItem[];
|
|
154
|
+
link?: SidebarItemCategoryLink;
|
|
155
|
+
}
|
|
156
|
+
>;
|
|
157
|
+
|
|
158
|
+
export type SidebarItemCategoryWithLink = Required<SidebarItemCategory, 'link'>;
|
|
159
|
+
|
|
160
|
+
export type SidebarItemCategoryWithGeneratedIndex =
|
|
161
|
+
SidebarItemCategoryWithLink & {link: SidebarItemCategoryLinkGeneratedIndex};
|
|
162
|
+
|
|
163
|
+
export type SidebarItem =
|
|
164
|
+
| SidebarItemDoc
|
|
165
|
+
| SidebarItemHtml
|
|
166
|
+
| SidebarItemLink
|
|
167
|
+
| SidebarItemCategory;
|
|
168
|
+
|
|
169
|
+
// A sidebar item that is part of the previous/next ordered navigation
|
|
170
|
+
export type SidebarNavigationItem =
|
|
171
|
+
| SidebarItemDoc
|
|
172
|
+
| SidebarItemCategoryWithLink;
|
|
173
|
+
|
|
174
|
+
export type Sidebar = SidebarItem[];
|
|
175
|
+
export type SidebarItemType = SidebarItem['type'];
|
|
176
|
+
export type Sidebars = {
|
|
177
|
+
[sidebarId: string]: Sidebar;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// Doc links have been resolved to URLs, ready to be passed to the theme
|
|
181
|
+
export type PropSidebarItemCategory = Expand<
|
|
182
|
+
SidebarItemCategoryBase & {
|
|
183
|
+
items: PropSidebarItem[];
|
|
184
|
+
href?: string;
|
|
185
|
+
}
|
|
186
|
+
>;
|
|
187
|
+
|
|
188
|
+
export type PropSidebarItemLink = SidebarItemLink & {
|
|
189
|
+
docId?: string;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export type PropSidebarItemHtml = SidebarItemHtml;
|
|
193
|
+
|
|
194
|
+
export type PropSidebarItem =
|
|
195
|
+
| PropSidebarItemLink
|
|
196
|
+
| PropSidebarItemCategory
|
|
197
|
+
| PropSidebarItemHtml;
|
|
198
|
+
export type PropSidebar = PropSidebarItem[];
|
|
199
|
+
export type PropSidebars = {
|
|
200
|
+
[sidebarId: string]: PropSidebar;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
export type PropSidebarBreadcrumbsItem =
|
|
204
|
+
| PropSidebarItemLink
|
|
205
|
+
| PropSidebarItemCategory;
|
|
206
|
+
|
|
207
|
+
export type CategoryMetadataFile = {
|
|
208
|
+
label?: string;
|
|
209
|
+
position?: number;
|
|
210
|
+
collapsed?: boolean;
|
|
211
|
+
collapsible?: boolean;
|
|
212
|
+
className?: string;
|
|
213
|
+
link?: SidebarItemCategoryLinkConfig | null;
|
|
214
|
+
customProps?: {[key: string]: unknown};
|
|
215
|
+
|
|
216
|
+
// TODO should we allow "items" here? how would this work? would an
|
|
217
|
+
// "autogenerated" type be allowed?
|
|
218
|
+
// This mkdocs plugin do something like that: https://github.com/lukasgeiter/mkdocs-awesome-pages-plugin/
|
|
219
|
+
// cf comment: https://github.com/facebook/docusaurus/issues/3464#issuecomment-784765199
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// Reduce API surface for options.sidebarItemsGenerator
|
|
223
|
+
// The user-provided generator fn should receive only a subset of metadata
|
|
224
|
+
// A change to any of these metadata can be considered as a breaking change
|
|
225
|
+
export type SidebarItemsGeneratorDoc = Pick<
|
|
226
|
+
DocMetadataBase,
|
|
227
|
+
| 'id'
|
|
228
|
+
| 'unversionedId'
|
|
229
|
+
| 'title'
|
|
230
|
+
| 'frontMatter'
|
|
231
|
+
| 'source'
|
|
232
|
+
| 'sourceDirName'
|
|
233
|
+
| 'sidebarPosition'
|
|
234
|
+
>;
|
|
235
|
+
export type SidebarItemsGeneratorVersion = Pick<
|
|
236
|
+
VersionMetadata,
|
|
237
|
+
'versionName' | 'contentPath'
|
|
238
|
+
>;
|
|
239
|
+
|
|
240
|
+
export type SidebarItemsGeneratorArgs = {
|
|
241
|
+
/** The sidebar item with type "autogenerated" to be transformed. */
|
|
242
|
+
item: SidebarItemAutogenerated;
|
|
243
|
+
/** Useful metadata for the version this sidebar belongs to. */
|
|
244
|
+
version: SidebarItemsGeneratorVersion;
|
|
245
|
+
/** All the docs of that version (unfiltered). */
|
|
246
|
+
docs: SidebarItemsGeneratorDoc[];
|
|
247
|
+
/** Number prefix parser configured for this plugin. */
|
|
248
|
+
numberPrefixParser: NumberPrefixParser;
|
|
249
|
+
/** The default category index matcher which you can override. */
|
|
250
|
+
isCategoryIndex: CategoryIndexMatcher;
|
|
251
|
+
/**
|
|
252
|
+
* Key is the path relative to the doc content directory, value is the
|
|
253
|
+
* category metadata file's content.
|
|
254
|
+
*/
|
|
255
|
+
categoriesMetadata: {[filePath: string]: CategoryMetadataFile};
|
|
256
|
+
};
|
|
257
|
+
export type SidebarItemsGenerator = (
|
|
258
|
+
generatorArgs: SidebarItemsGeneratorArgs,
|
|
259
|
+
) => NormalizedSidebar | Promise<NormalizedSidebar>;
|
|
260
|
+
|
|
261
|
+
export type SidebarItemsGeneratorOption = (
|
|
262
|
+
generatorArgs: {
|
|
263
|
+
/**
|
|
264
|
+
* Useful to re-use/enhance the default sidebar generation logic from
|
|
265
|
+
* Docusaurus.
|
|
266
|
+
* @see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320
|
|
267
|
+
*/
|
|
268
|
+
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
269
|
+
} & SidebarItemsGeneratorArgs,
|
|
270
|
+
) => NormalizedSidebar | Promise<NormalizedSidebar>;
|
|
271
|
+
|
|
272
|
+
export type SidebarProcessorParams = {
|
|
273
|
+
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
274
|
+
numberPrefixParser: NumberPrefixParser;
|
|
275
|
+
docs: DocMetadataBase[];
|
|
276
|
+
drafts: DocMetadataBase[];
|
|
277
|
+
version: VersionMetadata;
|
|
278
|
+
categoryLabelSlugger: Slugger;
|
|
279
|
+
sidebarOptions: SidebarOptions;
|
|
280
|
+
};
|
|
@@ -0,0 +1,393 @@
|
|
|
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 _ from 'lodash';
|
|
9
|
+
import {toMessageRelativeFilePath} from '@docusaurus/utils';
|
|
10
|
+
import type {
|
|
11
|
+
Sidebars,
|
|
12
|
+
Sidebar,
|
|
13
|
+
SidebarItem,
|
|
14
|
+
SidebarItemCategory,
|
|
15
|
+
SidebarItemLink,
|
|
16
|
+
SidebarItemDoc,
|
|
17
|
+
SidebarItemType,
|
|
18
|
+
SidebarCategoriesShorthand,
|
|
19
|
+
SidebarItemConfig,
|
|
20
|
+
SidebarItemCategoryWithGeneratedIndex,
|
|
21
|
+
SidebarNavigationItem,
|
|
22
|
+
} from './types';
|
|
23
|
+
import type {
|
|
24
|
+
DocMetadataBase,
|
|
25
|
+
PropNavigationLink,
|
|
26
|
+
} from '@docusaurus/plugin-content-docs';
|
|
27
|
+
|
|
28
|
+
export function isCategoriesShorthand(
|
|
29
|
+
item: SidebarItemConfig,
|
|
30
|
+
): item is SidebarCategoriesShorthand {
|
|
31
|
+
return typeof item === 'object' && !item.type;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function transformSidebarItems(
|
|
35
|
+
sidebar: Sidebar,
|
|
36
|
+
updateFn: (item: SidebarItem) => SidebarItem,
|
|
37
|
+
): Sidebar {
|
|
38
|
+
function transformRecursive(item: SidebarItem): SidebarItem {
|
|
39
|
+
if (item.type === 'category') {
|
|
40
|
+
return updateFn({
|
|
41
|
+
...item,
|
|
42
|
+
items: item.items.map(transformRecursive),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return updateFn(item);
|
|
46
|
+
}
|
|
47
|
+
return sidebar.map(transformRecursive);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Flatten sidebar items into a single flat array (containing categories/docs on
|
|
52
|
+
* the same level). Order matters (useful for next/prev nav), top categories
|
|
53
|
+
* appear before their child elements
|
|
54
|
+
*/
|
|
55
|
+
function flattenSidebarItems(items: SidebarItem[]): SidebarItem[] {
|
|
56
|
+
function flattenRecursive(item: SidebarItem): SidebarItem[] {
|
|
57
|
+
return item.type === 'category'
|
|
58
|
+
? [item, ...item.items.flatMap(flattenRecursive)]
|
|
59
|
+
: [item];
|
|
60
|
+
}
|
|
61
|
+
return items.flatMap(flattenRecursive);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function collectSidebarItemsOfType<
|
|
65
|
+
Type extends SidebarItemType,
|
|
66
|
+
Item extends SidebarItem & {type: SidebarItemType},
|
|
67
|
+
>(type: Type, sidebar: Sidebar): Item[] {
|
|
68
|
+
return flattenSidebarItems(sidebar).filter(
|
|
69
|
+
(item) => item.type === type,
|
|
70
|
+
) as Item[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function collectSidebarDocItems(sidebar: Sidebar): SidebarItemDoc[] {
|
|
74
|
+
return collectSidebarItemsOfType('doc', sidebar);
|
|
75
|
+
}
|
|
76
|
+
export function collectSidebarCategories(
|
|
77
|
+
sidebar: Sidebar,
|
|
78
|
+
): SidebarItemCategory[] {
|
|
79
|
+
return collectSidebarItemsOfType('category', sidebar);
|
|
80
|
+
}
|
|
81
|
+
export function collectSidebarLinks(sidebar: Sidebar): SidebarItemLink[] {
|
|
82
|
+
return collectSidebarItemsOfType('link', sidebar);
|
|
83
|
+
}
|
|
84
|
+
export function collectSidebarRefs(sidebar: Sidebar): SidebarItemDoc[] {
|
|
85
|
+
return collectSidebarItemsOfType('ref', sidebar);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// /!\ docId order matters for navigation!
|
|
89
|
+
export function collectSidebarDocIds(sidebar: Sidebar): string[] {
|
|
90
|
+
return flattenSidebarItems(sidebar).flatMap((item) => {
|
|
91
|
+
if (item.type === 'category') {
|
|
92
|
+
return item.link?.type === 'doc' ? [item.link.id] : [];
|
|
93
|
+
}
|
|
94
|
+
if (item.type === 'doc') {
|
|
95
|
+
return [item.id];
|
|
96
|
+
}
|
|
97
|
+
return [];
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function collectSidebarNavigation(
|
|
102
|
+
sidebar: Sidebar,
|
|
103
|
+
): SidebarNavigationItem[] {
|
|
104
|
+
return flattenSidebarItems(sidebar).flatMap((item) => {
|
|
105
|
+
if (item.type === 'category' && item.link) {
|
|
106
|
+
return [item as SidebarNavigationItem];
|
|
107
|
+
}
|
|
108
|
+
if (item.type === 'doc') {
|
|
109
|
+
return [item];
|
|
110
|
+
}
|
|
111
|
+
return [];
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function collectSidebarsDocIds(sidebars: Sidebars): {
|
|
116
|
+
[sidebarId: string]: string[];
|
|
117
|
+
} {
|
|
118
|
+
return _.mapValues(sidebars, collectSidebarDocIds);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function collectSidebarsNavigations(sidebars: Sidebars): {
|
|
122
|
+
[sidebarId: string]: SidebarNavigationItem[];
|
|
123
|
+
} {
|
|
124
|
+
return _.mapValues(sidebars, collectSidebarNavigation);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export type SidebarNavigation = {
|
|
128
|
+
sidebarName: string | undefined;
|
|
129
|
+
previous: SidebarNavigationItem | undefined;
|
|
130
|
+
next: SidebarNavigationItem | undefined;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// A convenient and performant way to query the sidebars content
|
|
134
|
+
export type SidebarsUtils = {
|
|
135
|
+
sidebars: Sidebars;
|
|
136
|
+
getFirstDocIdOfFirstSidebar: () => string | undefined;
|
|
137
|
+
getSidebarNameByDocId: (docId: string) => string | undefined;
|
|
138
|
+
getDocNavigation: (
|
|
139
|
+
unversionedId: string,
|
|
140
|
+
versionedId: string,
|
|
141
|
+
displayedSidebar: string | null | undefined,
|
|
142
|
+
) => SidebarNavigation;
|
|
143
|
+
getCategoryGeneratedIndexList: () => SidebarItemCategoryWithGeneratedIndex[];
|
|
144
|
+
getCategoryGeneratedIndexNavigation: (
|
|
145
|
+
categoryGeneratedIndexPermalink: string,
|
|
146
|
+
) => SidebarNavigation;
|
|
147
|
+
/**
|
|
148
|
+
* This function may return undefined. This is usually a user mistake, because
|
|
149
|
+
* it means this sidebar will never be displayed; however, we can still use
|
|
150
|
+
* `displayed_sidebar` to make it displayed. Pretty weird but valid use-case
|
|
151
|
+
*/
|
|
152
|
+
getFirstLink: (sidebarId: string) =>
|
|
153
|
+
| {
|
|
154
|
+
type: 'doc';
|
|
155
|
+
id: string;
|
|
156
|
+
label: string;
|
|
157
|
+
}
|
|
158
|
+
| {
|
|
159
|
+
type: 'generated-index';
|
|
160
|
+
permalink: string;
|
|
161
|
+
label: string;
|
|
162
|
+
}
|
|
163
|
+
| undefined;
|
|
164
|
+
|
|
165
|
+
checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
|
|
169
|
+
const sidebarNameToDocIds = collectSidebarsDocIds(sidebars);
|
|
170
|
+
const sidebarNameToNavigationItems = collectSidebarsNavigations(sidebars);
|
|
171
|
+
|
|
172
|
+
// Reverse mapping
|
|
173
|
+
const docIdToSidebarName = Object.fromEntries(
|
|
174
|
+
Object.entries(sidebarNameToDocIds).flatMap(([sidebarName, docIds]) =>
|
|
175
|
+
docIds.map((docId) => [docId, sidebarName]),
|
|
176
|
+
),
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
function getFirstDocIdOfFirstSidebar(): string | undefined {
|
|
180
|
+
return Object.values(sidebarNameToDocIds)[0]?.[0];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function getSidebarNameByDocId(docId: string): string | undefined {
|
|
184
|
+
return docIdToSidebarName[docId];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function emptySidebarNavigation(): SidebarNavigation {
|
|
188
|
+
return {
|
|
189
|
+
sidebarName: undefined,
|
|
190
|
+
previous: undefined,
|
|
191
|
+
next: undefined,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function getDocNavigation(
|
|
196
|
+
unversionedId: string,
|
|
197
|
+
versionedId: string,
|
|
198
|
+
displayedSidebar: string | null | undefined,
|
|
199
|
+
): SidebarNavigation {
|
|
200
|
+
// TODO legacy id retro-compatibility!
|
|
201
|
+
let docId = unversionedId;
|
|
202
|
+
let sidebarName =
|
|
203
|
+
displayedSidebar === undefined
|
|
204
|
+
? getSidebarNameByDocId(docId)
|
|
205
|
+
: displayedSidebar;
|
|
206
|
+
if (sidebarName === undefined) {
|
|
207
|
+
docId = versionedId;
|
|
208
|
+
sidebarName = getSidebarNameByDocId(docId);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (!sidebarName) {
|
|
212
|
+
return emptySidebarNavigation();
|
|
213
|
+
}
|
|
214
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
215
|
+
if (!navigationItems) {
|
|
216
|
+
throw new Error(
|
|
217
|
+
`Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`,
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
const currentItemIndex = navigationItems.findIndex((item) => {
|
|
221
|
+
if (item.type === 'doc') {
|
|
222
|
+
return item.id === docId;
|
|
223
|
+
}
|
|
224
|
+
if (item.type === 'category' && item.link.type === 'doc') {
|
|
225
|
+
return item.link.id === docId;
|
|
226
|
+
}
|
|
227
|
+
return false;
|
|
228
|
+
});
|
|
229
|
+
if (currentItemIndex === -1) {
|
|
230
|
+
return {sidebarName, next: undefined, previous: undefined};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return {
|
|
234
|
+
sidebarName,
|
|
235
|
+
previous: navigationItems[currentItemIndex - 1],
|
|
236
|
+
next: navigationItems[currentItemIndex + 1],
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function getCategoryGeneratedIndexList(): SidebarItemCategoryWithGeneratedIndex[] {
|
|
241
|
+
return Object.values(sidebarNameToNavigationItems)
|
|
242
|
+
.flat()
|
|
243
|
+
.flatMap((item) => {
|
|
244
|
+
if (item.type === 'category' && item.link.type === 'generated-index') {
|
|
245
|
+
return [item as SidebarItemCategoryWithGeneratedIndex];
|
|
246
|
+
}
|
|
247
|
+
return [];
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* We identity the category generated index by its permalink (should be
|
|
253
|
+
* unique). More reliable than using object identity
|
|
254
|
+
*/
|
|
255
|
+
function getCategoryGeneratedIndexNavigation(
|
|
256
|
+
categoryGeneratedIndexPermalink: string,
|
|
257
|
+
): SidebarNavigation {
|
|
258
|
+
function isCurrentCategoryGeneratedIndexItem(
|
|
259
|
+
item: SidebarNavigationItem,
|
|
260
|
+
): boolean {
|
|
261
|
+
return (
|
|
262
|
+
item.type === 'category' &&
|
|
263
|
+
item.link.type === 'generated-index' &&
|
|
264
|
+
item.link.permalink === categoryGeneratedIndexPermalink
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const sidebarName = Object.entries(sidebarNameToNavigationItems).find(
|
|
269
|
+
([, navigationItems]) =>
|
|
270
|
+
navigationItems.find(isCurrentCategoryGeneratedIndexItem),
|
|
271
|
+
)![0];
|
|
272
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName]!;
|
|
273
|
+
const currentItemIndex = navigationItems.findIndex(
|
|
274
|
+
isCurrentCategoryGeneratedIndexItem,
|
|
275
|
+
);
|
|
276
|
+
return {
|
|
277
|
+
sidebarName,
|
|
278
|
+
previous: navigationItems[currentItemIndex - 1],
|
|
279
|
+
next: navigationItems[currentItemIndex + 1],
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function checkSidebarsDocIds(validDocIds: string[], sidebarFilePath: string) {
|
|
284
|
+
const allSidebarDocIds = Object.values(sidebarNameToDocIds).flat();
|
|
285
|
+
const invalidSidebarDocIds = _.difference(allSidebarDocIds, validDocIds);
|
|
286
|
+
if (invalidSidebarDocIds.length > 0) {
|
|
287
|
+
throw new Error(
|
|
288
|
+
`Invalid sidebar file at "${toMessageRelativeFilePath(
|
|
289
|
+
sidebarFilePath,
|
|
290
|
+
)}".
|
|
291
|
+
These sidebar document ids do not exist:
|
|
292
|
+
- ${invalidSidebarDocIds.sort().join('\n- ')}
|
|
293
|
+
|
|
294
|
+
Available document ids are:
|
|
295
|
+
- ${_.uniq(validDocIds).sort().join('\n- ')}`,
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function getFirstLink(sidebar: Sidebar):
|
|
301
|
+
| {
|
|
302
|
+
type: 'doc';
|
|
303
|
+
id: string;
|
|
304
|
+
label: string;
|
|
305
|
+
}
|
|
306
|
+
| {
|
|
307
|
+
type: 'generated-index';
|
|
308
|
+
permalink: string;
|
|
309
|
+
label: string;
|
|
310
|
+
}
|
|
311
|
+
| undefined {
|
|
312
|
+
for (const item of sidebar) {
|
|
313
|
+
if (item.type === 'doc') {
|
|
314
|
+
return {
|
|
315
|
+
type: 'doc',
|
|
316
|
+
id: item.id,
|
|
317
|
+
label: item.label ?? item.id,
|
|
318
|
+
};
|
|
319
|
+
} else if (item.type === 'category') {
|
|
320
|
+
if (item.link?.type === 'doc') {
|
|
321
|
+
return {
|
|
322
|
+
type: 'doc',
|
|
323
|
+
id: item.link.id,
|
|
324
|
+
label: item.label,
|
|
325
|
+
};
|
|
326
|
+
} else if (item.link?.type === 'generated-index') {
|
|
327
|
+
return {
|
|
328
|
+
type: 'generated-index',
|
|
329
|
+
permalink: item.link.permalink,
|
|
330
|
+
label: item.label,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
const firstSubItem = getFirstLink(item.items);
|
|
334
|
+
if (firstSubItem) {
|
|
335
|
+
return firstSubItem;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return undefined;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return {
|
|
343
|
+
sidebars,
|
|
344
|
+
getFirstDocIdOfFirstSidebar,
|
|
345
|
+
getSidebarNameByDocId,
|
|
346
|
+
getDocNavigation,
|
|
347
|
+
getCategoryGeneratedIndexList,
|
|
348
|
+
getCategoryGeneratedIndexNavigation,
|
|
349
|
+
checkSidebarsDocIds,
|
|
350
|
+
getFirstLink: (id) => getFirstLink(sidebars[id]!),
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export function toDocNavigationLink(doc: DocMetadataBase): PropNavigationLink {
|
|
355
|
+
const {
|
|
356
|
+
title,
|
|
357
|
+
permalink,
|
|
358
|
+
frontMatter: {
|
|
359
|
+
pagination_label: paginationLabel,
|
|
360
|
+
sidebar_label: sidebarLabel,
|
|
361
|
+
},
|
|
362
|
+
} = doc;
|
|
363
|
+
return {title: paginationLabel ?? sidebarLabel ?? title, permalink};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export function toNavigationLink(
|
|
367
|
+
navigationItem: SidebarNavigationItem | undefined,
|
|
368
|
+
docsById: {[docId: string]: DocMetadataBase},
|
|
369
|
+
): PropNavigationLink | undefined {
|
|
370
|
+
function getDocById(docId: string) {
|
|
371
|
+
const doc = docsById[docId];
|
|
372
|
+
if (!doc) {
|
|
373
|
+
throw new Error(
|
|
374
|
+
`Can't create navigation link: no doc found with id=${docId}`,
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
return doc;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (!navigationItem) {
|
|
381
|
+
return undefined;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (navigationItem.type === 'category') {
|
|
385
|
+
return navigationItem.link.type === 'doc'
|
|
386
|
+
? toDocNavigationLink(getDocById(navigationItem.link.id))
|
|
387
|
+
: {
|
|
388
|
+
title: navigationItem.label,
|
|
389
|
+
permalink: navigationItem.link.permalink,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
return toDocNavigationLink(getDocById(navigationItem.id));
|
|
393
|
+
}
|