@docusaurus/plugin-content-docs 2.0.0-beta.15d451942 → 2.0.0-beta.18
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 +35 -0
- package/lib/cli.d.ts +2 -2
- package/lib/cli.js +37 -51
- package/lib/client/docsClientUtils.d.ts +6 -26
- package/lib/client/docsClientUtils.js +28 -34
- package/lib/{theme/hooks/useDocs.d.ts → client/index.d.ts} +4 -3
- package/lib/{theme/hooks/useDocs.js → client/index.js} +28 -25
- package/lib/docs.d.ts +31 -4
- package/lib/docs.js +160 -54
- package/{src/__tests__/__fixtures__/simple-site/docusaurus.config.js → lib/frontMatter.d.ts} +4 -8
- package/lib/{docFrontMatter.js → frontMatter.js} +13 -6
- package/lib/globalData.d.ts +2 -2
- package/lib/globalData.js +32 -3
- package/lib/index.d.ts +4 -3
- package/lib/index.js +123 -136
- 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 -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 +55 -19
- package/lib/props.d.ts +7 -2
- package/lib/props.js +70 -14
- 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 +209 -0
- package/lib/sidebars/index.d.ts +13 -0
- package/lib/sidebars/index.js +94 -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 +65 -0
- package/lib/sidebars/processor.d.ts +10 -0
- package/lib/sidebars/processor.js +79 -0
- package/lib/sidebars/types.d.ts +174 -0
- package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js → lib/sidebars/types.js} +2 -10
- package/lib/sidebars/utils.d.ts +54 -0
- package/lib/sidebars/utils.js +255 -0
- package/lib/sidebars/validation.d.ts +11 -0
- package/lib/sidebars/validation.js +138 -0
- package/lib/slug.d.ts +6 -4
- package/lib/slug.js +29 -19
- package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/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 +89 -49
- package/lib/types.d.ts +60 -130
- package/lib/versions.d.ts +29 -4
- package/lib/versions.js +134 -97
- package/package.json +30 -26
- package/src/categoryGeneratedIndex.ts +55 -0
- package/src/cli.ts +47 -63
- package/src/client/docsClientUtils.ts +38 -73
- package/src/{theme/hooks/useDocs.ts → client/index.ts} +16 -11
- package/{types.d.ts → src/deps.d.ts} +1 -1
- package/src/docs.ts +212 -46
- package/src/{docFrontMatter.ts → frontMatter.ts} +21 -26
- package/src/globalData.ts +53 -3
- package/src/index.ts +168 -178
- package/src/lastUpdate.ts +26 -33
- package/src/markdown/index.ts +10 -16
- package/src/markdown/linkify.ts +6 -2
- package/src/numberPrefix.ts +19 -26
- package/src/options.ts +60 -32
- package/src/plugin-content-docs.d.ts +263 -40
- package/src/props.ts +105 -21
- 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 +292 -0
- package/src/sidebars/index.ts +120 -0
- package/src/sidebars/normalization.ts +85 -0
- package/src/sidebars/postProcessor.ts +89 -0
- package/src/sidebars/processor.ts +120 -0
- package/src/sidebars/types.ts +274 -0
- package/src/sidebars/utils.ts +388 -0
- package/src/sidebars/validation.ts +174 -0
- package/src/slug.ts +40 -23
- package/src/tags.ts +19 -0
- package/src/translations.ts +124 -66
- package/src/types.ts +67 -187
- package/src/versions.ts +205 -110
- package/lib/.tsbuildinfo +0 -4717
- package/lib/docFrontMatter.d.ts +0 -21
- package/lib/sidebarItemsGenerator.js +0 -211
- package/lib/sidebars.d.ts +0 -42
- package/lib/sidebars.js +0 -309
- 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 -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/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-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/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/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,57 @@ 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?.type === 'generated-index') {
|
|
122
|
+
if (category.link.title) {
|
|
123
|
+
entries.push([
|
|
124
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`,
|
|
125
|
+
{
|
|
126
|
+
message: category.link.title,
|
|
127
|
+
description: `The generated-index page title for category ${category.label} in sidebar ${sidebarName}`,
|
|
128
|
+
},
|
|
129
|
+
]);
|
|
130
|
+
}
|
|
131
|
+
if (category.link.description) {
|
|
132
|
+
entries.push([
|
|
133
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`,
|
|
134
|
+
{
|
|
135
|
+
message: category.link.description,
|
|
136
|
+
description: `The generated-index page description for category ${category.label} in sidebar ${sidebarName}`,
|
|
137
|
+
},
|
|
138
|
+
]);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return entries;
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
112
145
|
|
|
113
146
|
const links = collectSidebarLinks(sidebar);
|
|
114
|
-
const linksContent: TranslationFileContent =
|
|
115
|
-
.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
147
|
+
const linksContent: TranslationFileContent = Object.fromEntries(
|
|
148
|
+
links.map((link) => [
|
|
149
|
+
`sidebar.${sidebarName}.link.${link.label}`,
|
|
150
|
+
{
|
|
151
|
+
message: link.label,
|
|
152
|
+
description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
|
|
153
|
+
},
|
|
154
|
+
]),
|
|
155
|
+
);
|
|
121
156
|
|
|
122
157
|
return mergeTranslations([categoryContent, linksContent]);
|
|
123
158
|
}
|
|
@@ -131,29 +166,51 @@ function translateSidebar({
|
|
|
131
166
|
sidebarName: string;
|
|
132
167
|
sidebarsTranslations: TranslationFileContent;
|
|
133
168
|
}): Sidebar {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
169
|
+
function transformSidebarCategoryLink(
|
|
170
|
+
category: SidebarItemCategory,
|
|
171
|
+
): SidebarItemCategoryLink | undefined {
|
|
172
|
+
if (!category.link) {
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
if (category.link.type === 'generated-index') {
|
|
176
|
+
const title =
|
|
177
|
+
sidebarsTranslations[
|
|
178
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`
|
|
179
|
+
]?.message ?? category.link.title;
|
|
180
|
+
const description =
|
|
181
|
+
sidebarsTranslations[
|
|
182
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`
|
|
183
|
+
]?.message ?? category.link.description;
|
|
184
|
+
return {
|
|
185
|
+
...category.link,
|
|
186
|
+
title,
|
|
187
|
+
description,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
return category.link;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return transformSidebarItems(sidebar, (item) => {
|
|
194
|
+
if (item.type === 'category') {
|
|
195
|
+
const link = transformSidebarCategoryLink(item);
|
|
196
|
+
return {
|
|
197
|
+
...item,
|
|
198
|
+
label:
|
|
199
|
+
sidebarsTranslations[`sidebar.${sidebarName}.category.${item.label}`]
|
|
200
|
+
?.message ?? item.label,
|
|
201
|
+
...(link && {link}),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
if (item.type === 'link') {
|
|
205
|
+
return {
|
|
206
|
+
...item,
|
|
207
|
+
label:
|
|
208
|
+
sidebarsTranslations[`sidebar.${sidebarName}.link.${item.label}`]
|
|
209
|
+
?.message ?? item.label,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
return item;
|
|
213
|
+
});
|
|
157
214
|
}
|
|
158
215
|
|
|
159
216
|
function getSidebarsTranslations(
|
|
@@ -173,16 +230,16 @@ function translateSidebars(
|
|
|
173
230
|
version: LoadedVersion,
|
|
174
231
|
sidebarsTranslations: TranslationFileContent,
|
|
175
232
|
): Sidebars {
|
|
176
|
-
return mapValues(version.sidebars, (sidebar, sidebarName) =>
|
|
177
|
-
|
|
233
|
+
return _.mapValues(version.sidebars, (sidebar, sidebarName) =>
|
|
234
|
+
translateSidebar({
|
|
178
235
|
sidebar,
|
|
179
236
|
sidebarName: getNormalizedSidebarName({
|
|
180
237
|
sidebarName,
|
|
181
238
|
versionName: version.versionName,
|
|
182
239
|
}),
|
|
183
240
|
sidebarsTranslations,
|
|
184
|
-
})
|
|
185
|
-
|
|
241
|
+
}),
|
|
242
|
+
);
|
|
186
243
|
}
|
|
187
244
|
|
|
188
245
|
function getVersionTranslationFiles(version: LoadedVersion): TranslationFiles {
|
|
@@ -193,11 +250,11 @@ function getVersionTranslationFiles(version: LoadedVersion): TranslationFiles {
|
|
|
193
250
|
},
|
|
194
251
|
};
|
|
195
252
|
|
|
196
|
-
const sidebarsTranslations: TranslationFileContent =
|
|
197
|
-
version
|
|
198
|
-
);
|
|
253
|
+
const sidebarsTranslations: TranslationFileContent =
|
|
254
|
+
getSidebarsTranslations(version);
|
|
199
255
|
|
|
200
|
-
// const docsTranslations: TranslationFileContent =
|
|
256
|
+
// const docsTranslations: TranslationFileContent =
|
|
257
|
+
// getDocsTranslations(version);
|
|
201
258
|
|
|
202
259
|
return [
|
|
203
260
|
{
|
|
@@ -212,13 +269,14 @@ function getVersionTranslationFiles(version: LoadedVersion): TranslationFiles {
|
|
|
212
269
|
}
|
|
213
270
|
function translateVersion(
|
|
214
271
|
version: LoadedVersion,
|
|
215
|
-
translationFiles:
|
|
272
|
+
translationFiles: {[fileName: string]: TranslationFile},
|
|
216
273
|
): LoadedVersion {
|
|
217
274
|
const versionTranslations =
|
|
218
|
-
translationFiles[getVersionFileName(version.versionName)]
|
|
275
|
+
translationFiles[getVersionFileName(version.versionName)]!.content;
|
|
219
276
|
return {
|
|
220
277
|
...version,
|
|
221
|
-
versionLabel:
|
|
278
|
+
versionLabel:
|
|
279
|
+
versionTranslations['version.label']?.message ?? version.versionLabel,
|
|
222
280
|
sidebars: translateSidebars(version, versionTranslations),
|
|
223
281
|
// docs: translateDocs(version.docs, versionTranslations),
|
|
224
282
|
};
|
|
@@ -227,11 +285,11 @@ function translateVersion(
|
|
|
227
285
|
function getVersionsTranslationFiles(
|
|
228
286
|
versions: LoadedVersion[],
|
|
229
287
|
): TranslationFiles {
|
|
230
|
-
return
|
|
288
|
+
return versions.flatMap(getVersionTranslationFiles);
|
|
231
289
|
}
|
|
232
290
|
function translateVersions(
|
|
233
291
|
versions: LoadedVersion[],
|
|
234
|
-
translationFiles:
|
|
292
|
+
translationFiles: {[fileName: string]: TranslationFile},
|
|
235
293
|
): LoadedVersion[] {
|
|
236
294
|
return versions.map((version) => translateVersion(version, translationFiles));
|
|
237
295
|
}
|
|
@@ -245,7 +303,7 @@ export function translateLoadedContent(
|
|
|
245
303
|
loadedContent: LoadedContent,
|
|
246
304
|
translationFiles: TranslationFile[],
|
|
247
305
|
): LoadedContent {
|
|
248
|
-
const translationFilesMap:
|
|
306
|
+
const translationFilesMap: {[fileName: string]: TranslationFile} = _.keyBy(
|
|
249
307
|
translationFiles,
|
|
250
308
|
(f) => f.path,
|
|
251
309
|
);
|
package/src/types.ts
CHANGED
|
@@ -5,14 +5,16 @@
|
|
|
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 {
|
|
13
|
-
|
|
10
|
+
import type {Sidebars} from './sidebars/types';
|
|
11
|
+
import type {
|
|
12
|
+
Tag,
|
|
13
|
+
FrontMatterTag,
|
|
14
|
+
BrokenMarkdownLink,
|
|
14
15
|
ContentPaths,
|
|
15
|
-
} from '@docusaurus/utils
|
|
16
|
+
} from '@docusaurus/utils';
|
|
17
|
+
import type {VersionBanner} from '@docusaurus/plugin-content-docs';
|
|
16
18
|
|
|
17
19
|
export type DocFile = {
|
|
18
20
|
contentPath: string; // /!\ may be localized
|
|
@@ -22,186 +24,66 @@ export type DocFile = {
|
|
|
22
24
|
lastUpdate: LastUpdateData;
|
|
23
25
|
};
|
|
24
26
|
|
|
25
|
-
export type VersionName = string;
|
|
26
|
-
|
|
27
27
|
export type VersionMetadata = ContentPaths & {
|
|
28
|
-
versionName:
|
|
28
|
+
versionName: string; // 1.0.0
|
|
29
29
|
versionLabel: string; // Version 1.0.0
|
|
30
30
|
versionPath: string; // /baseUrl/docs/1.0.0
|
|
31
|
+
tagsPath: string;
|
|
31
32
|
versionEditUrl?: string | undefined;
|
|
32
33
|
versionEditUrlLocalized?: string | undefined;
|
|
34
|
+
versionBanner: VersionBanner | null;
|
|
35
|
+
versionBadge: boolean;
|
|
36
|
+
versionClassName: string;
|
|
33
37
|
isLast: boolean;
|
|
34
38
|
sidebarFilePath: string | false | undefined; // versioned_sidebars/1.0.0.json
|
|
35
39
|
routePriority: number | undefined; // -1 for the latest docs
|
|
36
40
|
};
|
|
37
41
|
|
|
38
|
-
export type EditUrlFunction = (editUrlParams: {
|
|
39
|
-
version: string;
|
|
40
|
-
versionDocsDirPath: string;
|
|
41
|
-
docPath: string;
|
|
42
|
-
permalink: string;
|
|
43
|
-
locale: string;
|
|
44
|
-
}) => string | undefined;
|
|
45
|
-
|
|
46
|
-
export type MetadataOptions = {
|
|
47
|
-
routeBasePath: string;
|
|
48
|
-
homePageId?: string;
|
|
49
|
-
editUrl?: string | EditUrlFunction;
|
|
50
|
-
editCurrentVersion: boolean;
|
|
51
|
-
editLocalizedFiles: boolean;
|
|
52
|
-
showLastUpdateTime?: boolean;
|
|
53
|
-
showLastUpdateAuthor?: boolean;
|
|
54
|
-
numberPrefixParser: NumberPrefixParser;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export type PathOptions = {
|
|
58
|
-
path: string;
|
|
59
|
-
sidebarPath?: string | false | undefined;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export type VersionOptions = {
|
|
63
|
-
path?: string;
|
|
64
|
-
label?: string;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export type VersionsOptions = {
|
|
68
|
-
lastVersion?: string;
|
|
69
|
-
versions: Record<string, VersionOptions>;
|
|
70
|
-
onlyIncludeVersions?: string[];
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export type PluginOptions = MetadataOptions &
|
|
74
|
-
PathOptions &
|
|
75
|
-
VersionsOptions &
|
|
76
|
-
RemarkAndRehypePluginOptions & {
|
|
77
|
-
id: string;
|
|
78
|
-
include: string[];
|
|
79
|
-
docLayoutComponent: string;
|
|
80
|
-
docItemComponent: string;
|
|
81
|
-
admonitions: Record<string, unknown>;
|
|
82
|
-
disableVersioning: boolean;
|
|
83
|
-
excludeNextVersionDocs?: boolean;
|
|
84
|
-
includeCurrentVersion: boolean;
|
|
85
|
-
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export type SidebarItemBase = {
|
|
89
|
-
customProps?: Record<string, unknown>;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export type SidebarItemDoc = SidebarItemBase & {
|
|
93
|
-
type: 'doc' | 'ref';
|
|
94
|
-
label?: string;
|
|
95
|
-
id: string;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export type SidebarItemLink = SidebarItemBase & {
|
|
99
|
-
type: 'link';
|
|
100
|
-
href: string;
|
|
101
|
-
label: string;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
export type SidebarItemCategory = SidebarItemBase & {
|
|
105
|
-
type: 'category';
|
|
106
|
-
label: string;
|
|
107
|
-
items: SidebarItem[];
|
|
108
|
-
collapsed: boolean;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
export type UnprocessedSidebarItemAutogenerated = {
|
|
112
|
-
type: 'autogenerated';
|
|
113
|
-
dirName: string;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export type UnprocessedSidebarItemCategory = SidebarItemBase & {
|
|
117
|
-
type: 'category';
|
|
118
|
-
label: string;
|
|
119
|
-
items: UnprocessedSidebarItem[];
|
|
120
|
-
collapsed: boolean;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
export type UnprocessedSidebarItem =
|
|
124
|
-
| SidebarItemDoc
|
|
125
|
-
| SidebarItemLink
|
|
126
|
-
| UnprocessedSidebarItemCategory
|
|
127
|
-
| UnprocessedSidebarItemAutogenerated;
|
|
128
|
-
|
|
129
|
-
export type UnprocessedSidebar = UnprocessedSidebarItem[];
|
|
130
|
-
export type UnprocessedSidebars = Record<string, UnprocessedSidebar>;
|
|
131
|
-
|
|
132
|
-
export type SidebarItem =
|
|
133
|
-
| SidebarItemDoc
|
|
134
|
-
| SidebarItemLink
|
|
135
|
-
| SidebarItemCategory;
|
|
136
|
-
|
|
137
|
-
export type Sidebar = SidebarItem[];
|
|
138
|
-
export type SidebarItemType = SidebarItem['type'];
|
|
139
|
-
export type Sidebars = Record<string, Sidebar>;
|
|
140
|
-
|
|
141
|
-
// Reduce API surface for options.sidebarItemsGenerator
|
|
142
|
-
// The user-provided generator fn should receive only a subset of metadatas
|
|
143
|
-
// A change to any of these metadatas can be considered as a breaking change
|
|
144
|
-
export type SidebarItemsGeneratorDoc = Pick<
|
|
145
|
-
DocMetadataBase,
|
|
146
|
-
'id' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'
|
|
147
|
-
>;
|
|
148
|
-
export type SidebarItemsGeneratorVersion = Pick<
|
|
149
|
-
VersionMetadata,
|
|
150
|
-
'versionName' | 'contentPath'
|
|
151
|
-
>;
|
|
152
|
-
|
|
153
|
-
export type SidebarItemsGeneratorArgs = {
|
|
154
|
-
item: UnprocessedSidebarItemAutogenerated;
|
|
155
|
-
version: SidebarItemsGeneratorVersion;
|
|
156
|
-
docs: SidebarItemsGeneratorDoc[];
|
|
157
|
-
numberPrefixParser: NumberPrefixParser;
|
|
158
|
-
};
|
|
159
|
-
export type SidebarItemsGenerator = (
|
|
160
|
-
generatorArgs: SidebarItemsGeneratorArgs,
|
|
161
|
-
) => Promise<SidebarItem[]>;
|
|
162
|
-
|
|
163
|
-
// Also inject the default generator to conveniently wrap/enhance/sort the default sidebar gen logic
|
|
164
|
-
// see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320
|
|
165
|
-
export type SidebarItemsGeneratorOptionArgs = {
|
|
166
|
-
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
167
|
-
} & SidebarItemsGeneratorArgs;
|
|
168
|
-
export type SidebarItemsGeneratorOption = (
|
|
169
|
-
generatorArgs: SidebarItemsGeneratorOptionArgs,
|
|
170
|
-
) => Promise<SidebarItem[]>;
|
|
171
|
-
|
|
172
|
-
export type OrderMetadata = {
|
|
173
|
-
previous?: string;
|
|
174
|
-
next?: string;
|
|
175
|
-
sidebar?: string;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
42
|
export type LastUpdateData = {
|
|
179
43
|
lastUpdatedAt?: number;
|
|
180
44
|
formattedLastUpdatedAt?: string;
|
|
181
45
|
lastUpdatedBy?: string;
|
|
182
46
|
};
|
|
183
47
|
|
|
184
|
-
export type
|
|
185
|
-
//
|
|
186
|
-
|
|
48
|
+
export type DocFrontMatter = {
|
|
49
|
+
// Front matter uses snake case
|
|
50
|
+
id?: string;
|
|
51
|
+
title?: string;
|
|
52
|
+
tags?: FrontMatterTag[];
|
|
53
|
+
hide_title?: boolean;
|
|
54
|
+
hide_table_of_contents?: boolean;
|
|
55
|
+
keywords?: string[];
|
|
56
|
+
image?: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
slug?: string;
|
|
59
|
+
sidebar_label?: string;
|
|
60
|
+
sidebar_position?: number;
|
|
61
|
+
sidebar_class_name?: string;
|
|
62
|
+
sidebar_custom_props?: {[key: string]: unknown};
|
|
63
|
+
displayed_sidebar?: string | null;
|
|
64
|
+
pagination_label?: string;
|
|
65
|
+
custom_edit_url?: string | null;
|
|
66
|
+
parse_number_prefixes?: boolean;
|
|
67
|
+
toc_min_heading_level?: number;
|
|
68
|
+
toc_max_heading_level?: number;
|
|
69
|
+
pagination_next?: string | null;
|
|
70
|
+
pagination_prev?: string | null;
|
|
187
71
|
};
|
|
188
72
|
|
|
189
73
|
export type DocMetadataBase = LastUpdateData & {
|
|
190
|
-
|
|
191
|
-
unversionedId: string;
|
|
192
|
-
|
|
193
|
-
isDocsHomePage: boolean;
|
|
74
|
+
id: string; // TODO legacy versioned id => try to remove
|
|
75
|
+
unversionedId: string; // TODO new unversioned id => try to rename to "id"
|
|
76
|
+
version: string;
|
|
194
77
|
title: string;
|
|
195
78
|
description: string;
|
|
196
|
-
source: string;
|
|
197
|
-
sourceDirName: string; // relative to the docs folder (can be ".")
|
|
79
|
+
source: string; // @site aliased posix source => "@site/docs/folder/subFolder/subSubFolder/myDoc.md"
|
|
80
|
+
sourceDirName: string; // posix path relative to the versioned docs folder (can be ".") => "folder/subFolder/subSubFolder"
|
|
198
81
|
slug: string;
|
|
199
82
|
permalink: string;
|
|
200
|
-
// eslint-disable-next-line camelcase
|
|
201
|
-
sidebar_label?: string;
|
|
202
83
|
sidebarPosition?: number;
|
|
203
84
|
editUrl?: string | null;
|
|
204
|
-
|
|
85
|
+
tags: Tag[];
|
|
86
|
+
frontMatter: DocFrontMatter & {[key: string]: unknown};
|
|
205
87
|
};
|
|
206
88
|
|
|
207
89
|
export type DocNavLink = {
|
|
@@ -215,50 +97,48 @@ export type DocMetadata = DocMetadataBase & {
|
|
|
215
97
|
next?: DocNavLink;
|
|
216
98
|
};
|
|
217
99
|
|
|
100
|
+
export type CategoryGeneratedIndexMetadata = {
|
|
101
|
+
title: string;
|
|
102
|
+
description?: string;
|
|
103
|
+
slug: string;
|
|
104
|
+
permalink: string;
|
|
105
|
+
sidebar: string;
|
|
106
|
+
previous?: DocNavLink;
|
|
107
|
+
next?: DocNavLink;
|
|
108
|
+
image?: string;
|
|
109
|
+
keywords?: string | readonly string[];
|
|
110
|
+
};
|
|
111
|
+
|
|
218
112
|
export type SourceToPermalink = {
|
|
219
113
|
[source: string]: string;
|
|
220
114
|
};
|
|
115
|
+
|
|
116
|
+
export type VersionTag = {
|
|
117
|
+
name: string; // normalized name/label of the tag
|
|
118
|
+
docIds: string[]; // all doc ids having this tag
|
|
119
|
+
permalink: string; // pathname of the tag
|
|
120
|
+
};
|
|
121
|
+
export type VersionTags = {
|
|
122
|
+
[key: string]: VersionTag;
|
|
123
|
+
};
|
|
124
|
+
|
|
221
125
|
export type LoadedVersion = VersionMetadata & {
|
|
222
126
|
versionPath: string;
|
|
223
127
|
mainDocId: string;
|
|
224
128
|
docs: DocMetadata[];
|
|
225
129
|
sidebars: Sidebars;
|
|
226
|
-
|
|
130
|
+
categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
|
|
227
131
|
};
|
|
228
132
|
|
|
229
133
|
export type LoadedContent = {
|
|
230
134
|
loadedVersions: LoadedVersion[];
|
|
231
135
|
};
|
|
232
136
|
|
|
233
|
-
export type
|
|
234
|
-
id: string;
|
|
235
|
-
path: string;
|
|
236
|
-
sidebar: string | undefined;
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
export type GlobalVersion = {
|
|
240
|
-
name: VersionName;
|
|
241
|
-
label: string;
|
|
242
|
-
isLast: boolean;
|
|
243
|
-
path: string;
|
|
244
|
-
mainDocId: string; // home doc (if docs homepage configured), or first doc
|
|
245
|
-
docs: GlobalDoc[];
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
export type GlobalPluginData = {
|
|
249
|
-
path: string;
|
|
250
|
-
versions: GlobalVersion[];
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
export type BrokenMarkdownLink = IBrokenMarkdownLink<VersionMetadata>;
|
|
137
|
+
export type DocBrokenMarkdownLink = BrokenMarkdownLink<VersionMetadata>;
|
|
254
138
|
|
|
255
139
|
export type DocsMarkdownOption = {
|
|
256
140
|
versionsMetadata: VersionMetadata[];
|
|
257
141
|
siteDir: string;
|
|
258
142
|
sourceToPermalink: SourceToPermalink;
|
|
259
|
-
onBrokenMarkdownLink: (brokenMarkdownLink:
|
|
143
|
+
onBrokenMarkdownLink: (brokenMarkdownLink: DocBrokenMarkdownLink) => void;
|
|
260
144
|
};
|
|
261
|
-
|
|
262
|
-
export type NumberPrefixParser = (
|
|
263
|
-
filename: string,
|
|
264
|
-
) => {filename: string; numberPrefix?: number};
|