@docusaurus/plugin-content-docs 2.0.0-beta.15d451942 → 2.0.0-beta.16
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 +39 -0
- package/lib/cli.d.ts +2 -2
- package/lib/cli.js +40 -52
- package/lib/client/docsClientUtils.d.ts +3 -25
- package/lib/client/docsClientUtils.js +27 -33
- package/lib/{theme/hooks/useDocs.d.ts → client/index.d.ts} +1 -2
- package/lib/client/index.js +75 -0
- package/lib/docFrontMatter.d.ts +1 -14
- package/lib/docFrontMatter.js +13 -6
- package/lib/docs.d.ts +40 -4
- package/lib/docs.js +170 -54
- package/lib/globalData.d.ts +5 -1
- package/lib/globalData.js +35 -2
- package/lib/index.d.ts +4 -3
- package/lib/index.js +124 -136
- package/lib/lastUpdate.js +16 -29
- 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 +3 -3
- package/lib/numberPrefix.d.ts +1 -1
- package/lib/numberPrefix.js +7 -6
- package/lib/options.d.ts +3 -3
- package/lib/options.js +52 -17
- package/lib/props.d.ts +7 -2
- package/lib/props.js +71 -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 +190 -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 +72 -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 +265 -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 +29 -18
- 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 +87 -44
- package/lib/types.d.ts +55 -128
- package/lib/versions.d.ts +29 -4
- package/lib/versions.js +131 -89
- package/package.json +30 -26
- package/src/categoryGeneratedIndex.ts +59 -0
- package/src/cli.ts +48 -62
- package/src/client/docsClientUtils.ts +36 -71
- package/src/{theme/hooks/useDocs.ts → client/index.ts} +15 -10
- package/{types.d.ts → src/deps.d.ts} +0 -0
- package/src/docFrontMatter.ts +17 -22
- package/src/docs.ts +229 -45
- package/src/globalData.ts +53 -2
- package/src/index.ts +168 -177
- package/src/lastUpdate.ts +14 -33
- package/src/markdown/index.ts +9 -13
- package/src/markdown/linkify.ts +2 -2
- package/src/numberPrefix.ts +11 -8
- package/src/options.ts +59 -29
- package/src/plugin-content-docs.d.ts +256 -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 +263 -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 +40 -22
- package/src/tags.ts +19 -0
- package/src/translations.ts +121 -62
- package/src/types.ts +62 -183
- package/src/versions.ts +202 -107
- package/lib/.tsbuildinfo +0 -4717
- package/lib/sidebarItemsGenerator.js +0 -211
- package/lib/sidebars.d.ts +0 -42
- package/lib/sidebars.js +0 -309
- package/lib/theme/hooks/useDocs.js +0 -72
- 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/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 -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,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,186 +23,66 @@ 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 | null;
|
|
34
|
+
versionBadge: boolean;
|
|
35
|
+
versionClassName: string;
|
|
33
36
|
isLast: boolean;
|
|
34
37
|
sidebarFilePath: string | false | undefined; // versioned_sidebars/1.0.0.json
|
|
35
38
|
routePriority: number | undefined; // -1 for the latest docs
|
|
36
39
|
};
|
|
37
40
|
|
|
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
41
|
export type LastUpdateData = {
|
|
179
42
|
lastUpdatedAt?: number;
|
|
180
43
|
formattedLastUpdatedAt?: string;
|
|
181
44
|
lastUpdatedBy?: string;
|
|
182
45
|
};
|
|
183
46
|
|
|
184
|
-
export type
|
|
185
|
-
//
|
|
186
|
-
|
|
47
|
+
export type DocFrontMatter = {
|
|
48
|
+
// Front matter uses snake case
|
|
49
|
+
id?: string;
|
|
50
|
+
title?: string;
|
|
51
|
+
tags?: FrontMatterTag[];
|
|
52
|
+
hide_title?: boolean;
|
|
53
|
+
hide_table_of_contents?: boolean;
|
|
54
|
+
keywords?: string[];
|
|
55
|
+
image?: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
slug?: string;
|
|
58
|
+
sidebar_label?: string;
|
|
59
|
+
sidebar_position?: number;
|
|
60
|
+
sidebar_class_name?: string;
|
|
61
|
+
sidebar_custom_props?: Record<string, unknown>;
|
|
62
|
+
displayed_sidebar?: string | null;
|
|
63
|
+
pagination_label?: string;
|
|
64
|
+
custom_edit_url?: string | null;
|
|
65
|
+
parse_number_prefixes?: boolean;
|
|
66
|
+
toc_min_heading_level?: number;
|
|
67
|
+
toc_max_heading_level?: number;
|
|
68
|
+
pagination_next?: string | null;
|
|
69
|
+
pagination_prev?: string | null;
|
|
187
70
|
};
|
|
188
71
|
|
|
189
72
|
export type DocMetadataBase = LastUpdateData & {
|
|
190
|
-
|
|
191
|
-
unversionedId: string;
|
|
192
|
-
|
|
193
|
-
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;
|
|
194
76
|
title: string;
|
|
195
77
|
description: string;
|
|
196
|
-
source: string;
|
|
197
|
-
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"
|
|
198
80
|
slug: string;
|
|
199
81
|
permalink: string;
|
|
200
|
-
// eslint-disable-next-line camelcase
|
|
201
|
-
sidebar_label?: string;
|
|
202
82
|
sidebarPosition?: number;
|
|
203
83
|
editUrl?: string | null;
|
|
204
|
-
|
|
84
|
+
tags: Tag[];
|
|
85
|
+
frontMatter: DocFrontMatter & Record<string, unknown>;
|
|
205
86
|
};
|
|
206
87
|
|
|
207
88
|
export type DocNavLink = {
|
|
@@ -215,41 +96,43 @@ export type DocMetadata = DocMetadataBase & {
|
|
|
215
96
|
next?: DocNavLink;
|
|
216
97
|
};
|
|
217
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
|
+
|
|
218
111
|
export type SourceToPermalink = {
|
|
219
112
|
[source: string]: string;
|
|
220
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
|
+
|
|
221
124
|
export type LoadedVersion = VersionMetadata & {
|
|
222
125
|
versionPath: string;
|
|
223
126
|
mainDocId: string;
|
|
224
127
|
docs: DocMetadata[];
|
|
225
128
|
sidebars: Sidebars;
|
|
226
|
-
|
|
129
|
+
categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
|
|
227
130
|
};
|
|
228
131
|
|
|
229
132
|
export type LoadedContent = {
|
|
230
133
|
loadedVersions: LoadedVersion[];
|
|
231
134
|
};
|
|
232
135
|
|
|
233
|
-
export type GlobalDoc = {
|
|
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
136
|
export type BrokenMarkdownLink = IBrokenMarkdownLink<VersionMetadata>;
|
|
254
137
|
|
|
255
138
|
export type DocsMarkdownOption = {
|
|
@@ -258,7 +141,3 @@ export type DocsMarkdownOption = {
|
|
|
258
141
|
sourceToPermalink: SourceToPermalink;
|
|
259
142
|
onBrokenMarkdownLink: (brokenMarkdownLink: BrokenMarkdownLink) => void;
|
|
260
143
|
};
|
|
261
|
-
|
|
262
|
-
export type NumberPrefixParser = (
|
|
263
|
-
filename: string,
|
|
264
|
-
) => {filename: string; numberPrefix?: number};
|