@docusaurus/plugin-content-docs 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17
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 +38 -0
- package/lib/cli.d.ts +2 -2
- package/lib/cli.js +27 -44
- package/lib/client/docsClientUtils.d.ts +3 -25
- package/lib/client/docsClientUtils.js +25 -24
- package/lib/{theme/hooks/useDocs.d.ts → client/index.d.ts} +1 -2
- package/lib/{theme/hooks/useDocs.js → client/index.js} +26 -26
- package/lib/docFrontMatter.d.ts +1 -1
- package/lib/docFrontMatter.js +9 -3
- package/lib/docs.d.ts +39 -3
- package/lib/docs.js +157 -53
- package/lib/globalData.d.ts +5 -1
- package/lib/globalData.js +35 -2
- package/lib/index.d.ts +4 -3
- package/lib/index.js +110 -144
- package/lib/lastUpdate.js +15 -28
- 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 +2 -2
- package/lib/numberPrefix.d.ts +1 -1
- package/lib/numberPrefix.js +9 -9
- package/lib/options.d.ts +3 -3
- package/lib/options.js +50 -10
- package/lib/props.d.ts +7 -2
- package/lib/props.js +66 -11
- package/lib/routes.d.ts +28 -0
- package/lib/routes.js +110 -0
- package/lib/server-export.d.ts +8 -0
- package/lib/server-export.js +23 -0
- package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +1 -6
- package/lib/sidebars/generator.js +193 -0
- package/lib/sidebars/index.d.ts +13 -0
- package/lib/sidebars/index.js +88 -0
- package/lib/sidebars/normalization.d.ts +13 -0
- package/lib/sidebars/normalization.js +55 -0
- package/lib/sidebars/postProcessor.d.ts +8 -0
- package/lib/sidebars/postProcessor.js +70 -0
- package/lib/sidebars/processor.d.ts +8 -0
- package/lib/sidebars/processor.js +79 -0
- package/lib/sidebars/types.d.ts +166 -0
- package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js → lib/sidebars/types.js} +2 -10
- package/lib/sidebars/utils.d.ts +43 -0
- package/lib/sidebars/utils.js +259 -0
- package/lib/sidebars/validation.d.ts +9 -0
- package/lib/sidebars/validation.js +137 -0
- package/lib/slug.d.ts +6 -4
- package/lib/slug.js +28 -17
- package/{src/__tests__/__fixtures__/site-with-doc-label/docusaurus.config.js → lib/tags.d.ts} +2 -8
- package/lib/tags.js +21 -0
- package/lib/translations.d.ts +2 -2
- package/lib/translations.js +91 -49
- package/lib/types.d.ts +40 -126
- package/lib/versions.d.ts +29 -4
- package/lib/versions.js +92 -87
- package/package.json +30 -27
- package/src/categoryGeneratedIndex.ts +59 -0
- package/src/cli.ts +34 -54
- package/src/client/docsClientUtils.ts +32 -57
- package/src/{theme/hooks/useDocs.ts → client/index.ts} +11 -10
- package/{types.d.ts → src/deps.d.ts} +0 -0
- package/src/docFrontMatter.ts +12 -5
- package/src/docs.ts +213 -47
- package/src/globalData.ts +53 -2
- package/src/index.ts +151 -197
- package/src/lastUpdate.ts +14 -37
- package/src/markdown/index.ts +9 -13
- package/src/markdown/linkify.ts +1 -1
- package/src/numberPrefix.ts +11 -8
- package/src/options.ts +59 -15
- package/src/plugin-content-docs.d.ts +249 -54
- package/src/props.ts +97 -18
- package/src/routes.ts +185 -0
- package/src/server-export.ts +24 -0
- package/src/sidebars/README.md +9 -0
- package/src/sidebars/generator.ts +269 -0
- package/src/sidebars/index.ts +113 -0
- package/src/sidebars/normalization.ts +85 -0
- package/src/sidebars/postProcessor.ts +94 -0
- package/src/sidebars/processor.ts +126 -0
- package/src/sidebars/types.ts +273 -0
- package/src/sidebars/utils.ts +392 -0
- package/src/sidebars/validation.ts +173 -0
- package/src/slug.ts +39 -21
- package/src/tags.ts +19 -0
- package/src/translations.ts +121 -62
- package/src/types.ts +46 -183
- package/src/versions.ts +136 -102
- package/lib/.tsbuildinfo +0 -1
- package/lib/sidebarItemsGenerator.js +0 -211
- package/lib/sidebars.d.ts +0 -43
- package/lib/sidebars.js +0 -320
- package/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-first-level-not-category.js +0 -20
- package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-link.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-unknown-type.json +0 -14
- package/src/__tests__/__fixtures__/sidebars/sidebars-wrong-field.json +0 -20
- package/src/__tests__/__fixtures__/sidebars/sidebars.json +0 -20
- package/src/__tests__/__fixtures__/simple-site/docs/foo/bar.md +0 -69
- package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +0 -70
- package/src/__tests__/__fixtures__/simple-site/docs/headingAsTitle.md +0 -1
- package/src/__tests__/__fixtures__/simple-site/docs/hello.md +0 -53
- package/src/__tests__/__fixtures__/simple-site/docs/ipsum.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/lorem.md +0 -6
- package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/absoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/relativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/resolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/tryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docusaurus.config.js +0 -14
- package/src/__tests__/__fixtures__/simple-site/sidebars.json +0 -23
- package/src/__tests__/__fixtures__/simple-site/wrong-sidebars.json +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/0-getting-started.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/1-installation.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/00_api-overview.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/0 --- Client API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/1 --- Server API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/0. Plugin API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/1. Theme API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/_category_.yml +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/03_api-end.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/_category_.json +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/0-guide2.5.md +0 -8
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/02-guide2.md +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/_category_.json +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/a-guide4.md +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/b-guide5.md +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/guide3.md +0 -8
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/z-guide1.md +0 -8
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/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/sidebars.json +0 -14
- package/src/__tests__/__fixtures__/versioned-site/community/team.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/community_sidebars.json +0 -3
- package/src/__tests__/__fixtures__/versioned-site/community_versioned_docs/version-1.0.0/team.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/community_versioned_sidebars/version-1.0.0-sidebars.json +0 -3
- package/src/__tests__/__fixtures__/versioned-site/community_versions.json +0 -1
- package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +0 -4
- package/src/__tests__/__fixtures__/versioned-site/docs/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/absoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/relativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/resolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/tryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docusaurus.config.js +0 -18
- package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs-community/current/team.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/sidebars.json +0 -10
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/bar.md +0 -4
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/baz.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/foo/bar.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootAbsoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootRelativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootResolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootTryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/absoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/relativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/resolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/tryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.0-sidebars.json +0 -11
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +0 -10
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-withSlugs-sidebars.json +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versions.json +0 -5
- package/src/__tests__/__snapshots__/cli.test.ts.snap +0 -90
- package/src/__tests__/__snapshots__/index.test.ts.snap +0 -1916
- package/src/__tests__/__snapshots__/sidebars.test.ts.snap +0 -218
- package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -487
- package/src/__tests__/cli.test.ts +0 -333
- package/src/__tests__/docFrontMatter.test.ts +0 -244
- package/src/__tests__/docs.test.ts +0 -878
- package/src/__tests__/index.test.ts +0 -1871
- package/src/__tests__/lastUpdate.test.ts +0 -69
- package/src/__tests__/numberPrefix.test.ts +0 -199
- package/src/__tests__/options.test.ts +0 -231
- package/src/__tests__/sidebarItemsGenerator.test.ts +0 -336
- package/src/__tests__/sidebars.test.ts +0 -639
- package/src/__tests__/slug.test.ts +0 -109
- package/src/__tests__/translations.test.ts +0 -159
- package/src/__tests__/versions.test.ts +0 -741
- package/src/client/__tests__/docsClientUtils.test.ts +0 -371
- package/src/markdown/__tests__/__fixtures__/docs/doc-localized.md +0 -1
- package/src/markdown/__tests__/__fixtures__/docs/doc1.md +0 -13
- package/src/markdown/__tests__/__fixtures__/docs/doc2.md +0 -12
- package/src/markdown/__tests__/__fixtures__/docs/doc4.md +0 -19
- package/src/markdown/__tests__/__fixtures__/docs/doc5.md +0 -6
- package/src/markdown/__tests__/__fixtures__/docs/subdir/doc3.md +0 -3
- package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/doc2.md +0 -7
- package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/subdir/doc1.md +0 -3
- package/src/markdown/__tests__/__snapshots__/linkify.test.ts.snap +0 -82
- package/src/markdown/__tests__/linkify.test.ts +0 -190
- package/src/sidebarItemsGenerator.ts +0 -307
- package/src/sidebars.ts +0 -522
- package/tsconfig.json +0 -9
package/src/translations.ts
CHANGED
|
@@ -5,24 +5,25 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import type {LoadedVersion, LoadedContent} from './types';
|
|
9
|
+
import type {
|
|
10
10
|
Sidebar,
|
|
11
|
-
|
|
11
|
+
SidebarItemCategory,
|
|
12
|
+
SidebarItemCategoryLink,
|
|
12
13
|
Sidebars,
|
|
13
|
-
|
|
14
|
-
} from './types';
|
|
14
|
+
} from './sidebars/types';
|
|
15
15
|
|
|
16
|
-
import
|
|
16
|
+
import _ from 'lodash';
|
|
17
17
|
import {
|
|
18
18
|
collectSidebarCategories,
|
|
19
19
|
transformSidebarItems,
|
|
20
20
|
collectSidebarLinks,
|
|
21
|
-
} from './sidebars';
|
|
22
|
-
import {
|
|
21
|
+
} from './sidebars/utils';
|
|
22
|
+
import type {
|
|
23
23
|
TranslationFileContent,
|
|
24
24
|
TranslationFile,
|
|
25
25
|
TranslationFiles,
|
|
26
|
+
TranslationMessage,
|
|
26
27
|
} from '@docusaurus/types';
|
|
27
28
|
import {mergeTranslations} from '@docusaurus/utils';
|
|
28
29
|
import {CURRENT_VERSION_NAME} from './constants';
|
|
@@ -30,11 +31,10 @@ import {CURRENT_VERSION_NAME} from './constants';
|
|
|
30
31
|
function getVersionFileName(versionName: string): string {
|
|
31
32
|
if (versionName === CURRENT_VERSION_NAME) {
|
|
32
33
|
return versionName;
|
|
33
|
-
} else {
|
|
34
|
-
// I don't like this "version-" prefix,
|
|
35
|
-
// but it's for consistency with site/versioned_docs
|
|
36
|
-
return `version-${versionName}`;
|
|
37
34
|
}
|
|
35
|
+
// I don't like this "version-" prefix,
|
|
36
|
+
// but it's for consistency with site/versioned_docs
|
|
37
|
+
return `version-${versionName}`;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// TODO legacy, the sidebar name is like "version-2.0.0-alpha.66/docs"
|
|
@@ -55,8 +55,8 @@ function getNormalizedSidebarName({
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/*
|
|
58
|
-
// Do we need to translate doc
|
|
59
|
-
// It seems translating
|
|
58
|
+
// Do we need to translate doc metadata?
|
|
59
|
+
// It seems translating front matter labels is good enough
|
|
60
60
|
function getDocTranslations(doc: DocMetadata): TranslationFileContent {
|
|
61
61
|
return {
|
|
62
62
|
[`${doc.unversionedId}.title`]: {
|
|
@@ -67,7 +67,8 @@ function getDocTranslations(doc: DocMetadata): TranslationFileContent {
|
|
|
67
67
|
? {
|
|
68
68
|
[`${doc.unversionedId}.sidebar_label`]: {
|
|
69
69
|
message: doc.sidebar_label,
|
|
70
|
-
description:
|
|
70
|
+
description:
|
|
71
|
+
`The sidebar label for doc with id=${doc.unversionedId}`,
|
|
71
72
|
},
|
|
72
73
|
}
|
|
73
74
|
: undefined),
|
|
@@ -101,23 +102,59 @@ function getSidebarTranslationFileContent(
|
|
|
101
102
|
sidebar: Sidebar,
|
|
102
103
|
sidebarName: string,
|
|
103
104
|
): TranslationFileContent {
|
|
105
|
+
type TranslationMessageEntry = [string, TranslationMessage];
|
|
106
|
+
|
|
104
107
|
const categories = collectSidebarCategories(sidebar);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
|
|
109
|
+
const categoryContent: TranslationFileContent = Object.fromEntries(
|
|
110
|
+
categories.flatMap((category) => {
|
|
111
|
+
const entries: TranslationMessageEntry[] = [];
|
|
112
|
+
|
|
113
|
+
entries.push([
|
|
114
|
+
`sidebar.${sidebarName}.category.${category.label}`,
|
|
115
|
+
{
|
|
116
|
+
message: category.label,
|
|
117
|
+
description: `The label for category ${category.label} in sidebar ${sidebarName}`,
|
|
118
|
+
},
|
|
119
|
+
]);
|
|
120
|
+
|
|
121
|
+
if (category.link) {
|
|
122
|
+
if (category.link.type === 'generated-index') {
|
|
123
|
+
if (category.link.title) {
|
|
124
|
+
entries.push([
|
|
125
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`,
|
|
126
|
+
{
|
|
127
|
+
message: category.link.title,
|
|
128
|
+
description: `The generated-index page title for category ${category.label} in sidebar ${sidebarName}`,
|
|
129
|
+
},
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
if (category.link.description) {
|
|
133
|
+
entries.push([
|
|
134
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`,
|
|
135
|
+
{
|
|
136
|
+
message: category.link.description,
|
|
137
|
+
description: `The generated-index page description for category ${category.label} in sidebar ${sidebarName}`,
|
|
138
|
+
},
|
|
139
|
+
]);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return entries;
|
|
145
|
+
}),
|
|
146
|
+
);
|
|
112
147
|
|
|
113
148
|
const links = collectSidebarLinks(sidebar);
|
|
114
|
-
const linksContent: TranslationFileContent =
|
|
115
|
-
.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
149
|
+
const linksContent: TranslationFileContent = Object.fromEntries(
|
|
150
|
+
links.map((link) => [
|
|
151
|
+
`sidebar.${sidebarName}.link.${link.label}`,
|
|
152
|
+
{
|
|
153
|
+
message: link.label,
|
|
154
|
+
description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
|
|
155
|
+
},
|
|
156
|
+
]),
|
|
157
|
+
);
|
|
121
158
|
|
|
122
159
|
return mergeTranslations([categoryContent, linksContent]);
|
|
123
160
|
}
|
|
@@ -131,29 +168,51 @@ function translateSidebar({
|
|
|
131
168
|
sidebarName: string;
|
|
132
169
|
sidebarsTranslations: TranslationFileContent;
|
|
133
170
|
}): Sidebar {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
171
|
+
function transformSidebarCategoryLink(
|
|
172
|
+
category: SidebarItemCategory,
|
|
173
|
+
): SidebarItemCategoryLink | undefined {
|
|
174
|
+
if (!category.link) {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
if (category.link.type === 'generated-index') {
|
|
178
|
+
const title =
|
|
179
|
+
sidebarsTranslations[
|
|
180
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`
|
|
181
|
+
]?.message ?? category.link.title;
|
|
182
|
+
const description =
|
|
183
|
+
sidebarsTranslations[
|
|
184
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`
|
|
185
|
+
]?.message ?? category.link.description;
|
|
186
|
+
return {
|
|
187
|
+
...category.link,
|
|
188
|
+
title,
|
|
189
|
+
description,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
return category.link;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return transformSidebarItems(sidebar, (item) => {
|
|
196
|
+
if (item.type === 'category') {
|
|
197
|
+
const link = transformSidebarCategoryLink(item);
|
|
198
|
+
return {
|
|
199
|
+
...item,
|
|
200
|
+
label:
|
|
201
|
+
sidebarsTranslations[`sidebar.${sidebarName}.category.${item.label}`]
|
|
202
|
+
?.message ?? item.label,
|
|
203
|
+
...(link && {link}),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
if (item.type === 'link') {
|
|
207
|
+
return {
|
|
208
|
+
...item,
|
|
209
|
+
label:
|
|
210
|
+
sidebarsTranslations[`sidebar.${sidebarName}.link.${item.label}`]
|
|
211
|
+
?.message ?? item.label,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return item;
|
|
215
|
+
});
|
|
157
216
|
}
|
|
158
217
|
|
|
159
218
|
function getSidebarsTranslations(
|
|
@@ -173,16 +232,16 @@ function translateSidebars(
|
|
|
173
232
|
version: LoadedVersion,
|
|
174
233
|
sidebarsTranslations: TranslationFileContent,
|
|
175
234
|
): Sidebars {
|
|
176
|
-
return mapValues(version.sidebars, (sidebar, sidebarName) =>
|
|
177
|
-
|
|
235
|
+
return _.mapValues(version.sidebars, (sidebar, sidebarName) =>
|
|
236
|
+
translateSidebar({
|
|
178
237
|
sidebar,
|
|
179
238
|
sidebarName: getNormalizedSidebarName({
|
|
180
239
|
sidebarName,
|
|
181
240
|
versionName: version.versionName,
|
|
182
241
|
}),
|
|
183
242
|
sidebarsTranslations,
|
|
184
|
-
})
|
|
185
|
-
|
|
243
|
+
}),
|
|
244
|
+
);
|
|
186
245
|
}
|
|
187
246
|
|
|
188
247
|
function getVersionTranslationFiles(version: LoadedVersion): TranslationFiles {
|
|
@@ -193,11 +252,11 @@ function getVersionTranslationFiles(version: LoadedVersion): TranslationFiles {
|
|
|
193
252
|
},
|
|
194
253
|
};
|
|
195
254
|
|
|
196
|
-
const sidebarsTranslations: TranslationFileContent =
|
|
197
|
-
version
|
|
198
|
-
);
|
|
255
|
+
const sidebarsTranslations: TranslationFileContent =
|
|
256
|
+
getSidebarsTranslations(version);
|
|
199
257
|
|
|
200
|
-
// const docsTranslations: TranslationFileContent =
|
|
258
|
+
// const docsTranslations: TranslationFileContent =
|
|
259
|
+
// getDocsTranslations(version);
|
|
201
260
|
|
|
202
261
|
return [
|
|
203
262
|
{
|
|
@@ -227,7 +286,7 @@ function translateVersion(
|
|
|
227
286
|
function getVersionsTranslationFiles(
|
|
228
287
|
versions: LoadedVersion[],
|
|
229
288
|
): TranslationFiles {
|
|
230
|
-
return
|
|
289
|
+
return versions.flatMap(getVersionTranslationFiles);
|
|
231
290
|
}
|
|
232
291
|
function translateVersions(
|
|
233
292
|
versions: LoadedVersion[],
|
|
@@ -245,7 +304,7 @@ export function translateLoadedContent(
|
|
|
245
304
|
loadedContent: LoadedContent,
|
|
246
305
|
translationFiles: TranslationFile[],
|
|
247
306
|
): LoadedContent {
|
|
248
|
-
const translationFilesMap: Record<string, TranslationFile> = keyBy(
|
|
307
|
+
const translationFilesMap: Record<string, TranslationFile> = _.keyBy(
|
|
249
308
|
translationFiles,
|
|
250
309
|
(f) => f.path,
|
|
251
310
|
);
|
package/src/types.ts
CHANGED
|
@@ -5,14 +5,15 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
// eslint-disable-next-line spaced-comment
|
|
9
8
|
/// <reference types="@docusaurus/module-type-aliases" />
|
|
10
9
|
|
|
11
|
-
import type {
|
|
12
|
-
import {
|
|
10
|
+
import type {Sidebars} from './sidebars/types';
|
|
11
|
+
import type {Tag, FrontMatterTag} from '@docusaurus/utils';
|
|
12
|
+
import type {
|
|
13
13
|
BrokenMarkdownLink as IBrokenMarkdownLink,
|
|
14
14
|
ContentPaths,
|
|
15
15
|
} from '@docusaurus/utils/lib/markdownLinks';
|
|
16
|
+
import type {VersionBanner} from '@docusaurus/plugin-content-docs';
|
|
16
17
|
|
|
17
18
|
export type DocFile = {
|
|
18
19
|
contentPath: string; // /!\ may be localized
|
|
@@ -22,163 +23,21 @@ export type DocFile = {
|
|
|
22
23
|
lastUpdate: LastUpdateData;
|
|
23
24
|
};
|
|
24
25
|
|
|
25
|
-
export type VersionName = string;
|
|
26
|
-
|
|
27
26
|
export type VersionMetadata = ContentPaths & {
|
|
28
|
-
versionName:
|
|
27
|
+
versionName: string; // 1.0.0
|
|
29
28
|
versionLabel: string; // Version 1.0.0
|
|
30
29
|
versionPath: string; // /baseUrl/docs/1.0.0
|
|
30
|
+
tagsPath: string;
|
|
31
31
|
versionEditUrl?: string | undefined;
|
|
32
32
|
versionEditUrlLocalized?: string | undefined;
|
|
33
|
-
versionBanner: VersionBanner;
|
|
33
|
+
versionBanner: VersionBanner | null;
|
|
34
|
+
versionBadge: boolean;
|
|
35
|
+
versionClassName: string;
|
|
34
36
|
isLast: boolean;
|
|
35
37
|
sidebarFilePath: string | false | undefined; // versioned_sidebars/1.0.0.json
|
|
36
38
|
routePriority: number | undefined; // -1 for the latest docs
|
|
37
39
|
};
|
|
38
40
|
|
|
39
|
-
export type EditUrlFunction = (editUrlParams: {
|
|
40
|
-
version: string;
|
|
41
|
-
versionDocsDirPath: string;
|
|
42
|
-
docPath: string;
|
|
43
|
-
permalink: string;
|
|
44
|
-
locale: string;
|
|
45
|
-
}) => string | undefined;
|
|
46
|
-
|
|
47
|
-
export type MetadataOptions = {
|
|
48
|
-
routeBasePath: string;
|
|
49
|
-
homePageId?: string;
|
|
50
|
-
editUrl?: string | EditUrlFunction;
|
|
51
|
-
editCurrentVersion: boolean;
|
|
52
|
-
editLocalizedFiles: boolean;
|
|
53
|
-
showLastUpdateTime?: boolean;
|
|
54
|
-
showLastUpdateAuthor?: boolean;
|
|
55
|
-
numberPrefixParser: NumberPrefixParser;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export type PathOptions = {
|
|
59
|
-
path: string;
|
|
60
|
-
sidebarPath?: string | false | undefined;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// TODO support custom version banner? {type: "error", content: "html content"}
|
|
64
|
-
export type VersionBanner = 'none' | 'unreleased' | 'unmaintained';
|
|
65
|
-
|
|
66
|
-
export type VersionOptions = {
|
|
67
|
-
path?: string;
|
|
68
|
-
label?: string;
|
|
69
|
-
banner?: VersionBanner;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export type VersionsOptions = {
|
|
73
|
-
lastVersion?: string;
|
|
74
|
-
versions: Record<string, VersionOptions>;
|
|
75
|
-
onlyIncludeVersions?: string[];
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export type PluginOptions = MetadataOptions &
|
|
79
|
-
PathOptions &
|
|
80
|
-
VersionsOptions &
|
|
81
|
-
RemarkAndRehypePluginOptions & {
|
|
82
|
-
id: string;
|
|
83
|
-
include: string[];
|
|
84
|
-
docLayoutComponent: string;
|
|
85
|
-
docItemComponent: string;
|
|
86
|
-
admonitions: Record<string, unknown>;
|
|
87
|
-
disableVersioning: boolean;
|
|
88
|
-
includeCurrentVersion: boolean;
|
|
89
|
-
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export type SidebarItemBase = {
|
|
93
|
-
customProps?: Record<string, unknown>;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export type SidebarItemDoc = SidebarItemBase & {
|
|
97
|
-
type: 'doc' | 'ref';
|
|
98
|
-
label?: string;
|
|
99
|
-
id: string;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export type SidebarItemLink = SidebarItemBase & {
|
|
103
|
-
type: 'link';
|
|
104
|
-
href: string;
|
|
105
|
-
label: string;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
export type SidebarItemCategory = SidebarItemBase & {
|
|
109
|
-
type: 'category';
|
|
110
|
-
label: string;
|
|
111
|
-
items: SidebarItem[];
|
|
112
|
-
collapsed: boolean;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export type UnprocessedSidebarItemAutogenerated = {
|
|
116
|
-
type: 'autogenerated';
|
|
117
|
-
dirName: string;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export type UnprocessedSidebarItemCategory = SidebarItemBase & {
|
|
121
|
-
type: 'category';
|
|
122
|
-
label: string;
|
|
123
|
-
items: UnprocessedSidebarItem[];
|
|
124
|
-
collapsed: boolean;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
export type UnprocessedSidebarItem =
|
|
128
|
-
| SidebarItemDoc
|
|
129
|
-
| SidebarItemLink
|
|
130
|
-
| UnprocessedSidebarItemCategory
|
|
131
|
-
| UnprocessedSidebarItemAutogenerated;
|
|
132
|
-
|
|
133
|
-
export type UnprocessedSidebar = UnprocessedSidebarItem[];
|
|
134
|
-
export type UnprocessedSidebars = Record<string, UnprocessedSidebar>;
|
|
135
|
-
|
|
136
|
-
export type SidebarItem =
|
|
137
|
-
| SidebarItemDoc
|
|
138
|
-
| SidebarItemLink
|
|
139
|
-
| SidebarItemCategory;
|
|
140
|
-
|
|
141
|
-
export type Sidebar = SidebarItem[];
|
|
142
|
-
export type SidebarItemType = SidebarItem['type'];
|
|
143
|
-
export type Sidebars = Record<string, Sidebar>;
|
|
144
|
-
|
|
145
|
-
// Reduce API surface for options.sidebarItemsGenerator
|
|
146
|
-
// The user-provided generator fn should receive only a subset of metadatas
|
|
147
|
-
// A change to any of these metadatas can be considered as a breaking change
|
|
148
|
-
export type SidebarItemsGeneratorDoc = Pick<
|
|
149
|
-
DocMetadataBase,
|
|
150
|
-
'id' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'
|
|
151
|
-
>;
|
|
152
|
-
export type SidebarItemsGeneratorVersion = Pick<
|
|
153
|
-
VersionMetadata,
|
|
154
|
-
'versionName' | 'contentPath'
|
|
155
|
-
>;
|
|
156
|
-
|
|
157
|
-
export type SidebarItemsGeneratorArgs = {
|
|
158
|
-
item: UnprocessedSidebarItemAutogenerated;
|
|
159
|
-
version: SidebarItemsGeneratorVersion;
|
|
160
|
-
docs: SidebarItemsGeneratorDoc[];
|
|
161
|
-
numberPrefixParser: NumberPrefixParser;
|
|
162
|
-
};
|
|
163
|
-
export type SidebarItemsGenerator = (
|
|
164
|
-
generatorArgs: SidebarItemsGeneratorArgs,
|
|
165
|
-
) => Promise<SidebarItem[]>;
|
|
166
|
-
|
|
167
|
-
// Also inject the default generator to conveniently wrap/enhance/sort the default sidebar gen logic
|
|
168
|
-
// see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320
|
|
169
|
-
export type SidebarItemsGeneratorOptionArgs = {
|
|
170
|
-
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
171
|
-
} & SidebarItemsGeneratorArgs;
|
|
172
|
-
export type SidebarItemsGeneratorOption = (
|
|
173
|
-
generatorArgs: SidebarItemsGeneratorOptionArgs,
|
|
174
|
-
) => Promise<SidebarItem[]>;
|
|
175
|
-
|
|
176
|
-
export type OrderMetadata = {
|
|
177
|
-
previous?: string;
|
|
178
|
-
next?: string;
|
|
179
|
-
sidebar?: string;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
41
|
export type LastUpdateData = {
|
|
183
42
|
lastUpdatedAt?: number;
|
|
184
43
|
formattedLastUpdatedAt?: string;
|
|
@@ -187,9 +46,9 @@ export type LastUpdateData = {
|
|
|
187
46
|
|
|
188
47
|
export type DocFrontMatter = {
|
|
189
48
|
// Front matter uses snake case
|
|
190
|
-
/* eslint-disable camelcase */
|
|
191
49
|
id?: string;
|
|
192
50
|
title?: string;
|
|
51
|
+
tags?: FrontMatterTag[];
|
|
193
52
|
hide_title?: boolean;
|
|
194
53
|
hide_table_of_contents?: boolean;
|
|
195
54
|
keywords?: string[];
|
|
@@ -198,25 +57,31 @@ export type DocFrontMatter = {
|
|
|
198
57
|
slug?: string;
|
|
199
58
|
sidebar_label?: string;
|
|
200
59
|
sidebar_position?: number;
|
|
60
|
+
sidebar_class_name?: string;
|
|
61
|
+
sidebar_custom_props?: Record<string, unknown>;
|
|
62
|
+
displayed_sidebar?: string | null;
|
|
201
63
|
pagination_label?: string;
|
|
202
64
|
custom_edit_url?: string | null;
|
|
203
65
|
parse_number_prefixes?: boolean;
|
|
204
|
-
|
|
66
|
+
toc_min_heading_level?: number;
|
|
67
|
+
toc_max_heading_level?: number;
|
|
68
|
+
pagination_next?: string | null;
|
|
69
|
+
pagination_prev?: string | null;
|
|
205
70
|
};
|
|
206
71
|
|
|
207
72
|
export type DocMetadataBase = LastUpdateData & {
|
|
208
|
-
|
|
209
|
-
unversionedId: string;
|
|
210
|
-
|
|
211
|
-
isDocsHomePage: boolean;
|
|
73
|
+
id: string; // TODO legacy versioned id => try to remove
|
|
74
|
+
unversionedId: string; // TODO new unversioned id => try to rename to "id"
|
|
75
|
+
version: string;
|
|
212
76
|
title: string;
|
|
213
77
|
description: string;
|
|
214
|
-
source: string;
|
|
215
|
-
sourceDirName: string; // relative to the docs folder (can be ".")
|
|
78
|
+
source: string; // @site aliased posix source => "@site/docs/folder/subFolder/subSubFolder/myDoc.md"
|
|
79
|
+
sourceDirName: string; // posix path relative to the versioned docs folder (can be ".") => "folder/subFolder/subSubFolder"
|
|
216
80
|
slug: string;
|
|
217
81
|
permalink: string;
|
|
218
82
|
sidebarPosition?: number;
|
|
219
83
|
editUrl?: string | null;
|
|
84
|
+
tags: Tag[];
|
|
220
85
|
frontMatter: DocFrontMatter & Record<string, unknown>;
|
|
221
86
|
};
|
|
222
87
|
|
|
@@ -231,41 +96,43 @@ export type DocMetadata = DocMetadataBase & {
|
|
|
231
96
|
next?: DocNavLink;
|
|
232
97
|
};
|
|
233
98
|
|
|
99
|
+
export type CategoryGeneratedIndexMetadata = {
|
|
100
|
+
title: string;
|
|
101
|
+
description?: string;
|
|
102
|
+
slug: string;
|
|
103
|
+
permalink: string;
|
|
104
|
+
sidebar: string;
|
|
105
|
+
previous?: DocNavLink;
|
|
106
|
+
next?: DocNavLink;
|
|
107
|
+
image?: string;
|
|
108
|
+
keywords?: string | readonly string[];
|
|
109
|
+
};
|
|
110
|
+
|
|
234
111
|
export type SourceToPermalink = {
|
|
235
112
|
[source: string]: string;
|
|
236
113
|
};
|
|
114
|
+
|
|
115
|
+
export type VersionTag = {
|
|
116
|
+
name: string; // normalized name/label of the tag
|
|
117
|
+
docIds: string[]; // all doc ids having this tag
|
|
118
|
+
permalink: string; // pathname of the tag
|
|
119
|
+
};
|
|
120
|
+
export type VersionTags = {
|
|
121
|
+
[key: string]: VersionTag;
|
|
122
|
+
};
|
|
123
|
+
|
|
237
124
|
export type LoadedVersion = VersionMetadata & {
|
|
238
125
|
versionPath: string;
|
|
239
126
|
mainDocId: string;
|
|
240
127
|
docs: DocMetadata[];
|
|
241
128
|
sidebars: Sidebars;
|
|
242
|
-
|
|
129
|
+
categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
|
|
243
130
|
};
|
|
244
131
|
|
|
245
132
|
export type LoadedContent = {
|
|
246
133
|
loadedVersions: LoadedVersion[];
|
|
247
134
|
};
|
|
248
135
|
|
|
249
|
-
export type GlobalDoc = {
|
|
250
|
-
id: string;
|
|
251
|
-
path: string;
|
|
252
|
-
sidebar: string | undefined;
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
export type GlobalVersion = {
|
|
256
|
-
name: VersionName;
|
|
257
|
-
label: string;
|
|
258
|
-
isLast: boolean;
|
|
259
|
-
path: string;
|
|
260
|
-
mainDocId: string; // home doc (if docs homepage configured), or first doc
|
|
261
|
-
docs: GlobalDoc[];
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
export type GlobalPluginData = {
|
|
265
|
-
path: string;
|
|
266
|
-
versions: GlobalVersion[];
|
|
267
|
-
};
|
|
268
|
-
|
|
269
136
|
export type BrokenMarkdownLink = IBrokenMarkdownLink<VersionMetadata>;
|
|
270
137
|
|
|
271
138
|
export type DocsMarkdownOption = {
|
|
@@ -274,7 +141,3 @@ export type DocsMarkdownOption = {
|
|
|
274
141
|
sourceToPermalink: SourceToPermalink;
|
|
275
142
|
onBrokenMarkdownLink: (brokenMarkdownLink: BrokenMarkdownLink) => void;
|
|
276
143
|
};
|
|
277
|
-
|
|
278
|
-
export type NumberPrefixParser = (
|
|
279
|
-
filename: string,
|
|
280
|
-
) => {filename: string; numberPrefix?: number};
|