@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/lib/translations.js
CHANGED
|
@@ -7,19 +7,18 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.translateLoadedContent = exports.getLoadedContentTranslationFiles = void 0;
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const utils_1 = require("
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
|
+
const utils_1 = require("./sidebars/utils");
|
|
13
|
+
const utils_2 = require("@docusaurus/utils");
|
|
13
14
|
const constants_1 = require("./constants");
|
|
14
15
|
function getVersionFileName(versionName) {
|
|
15
16
|
if (versionName === constants_1.CURRENT_VERSION_NAME) {
|
|
16
17
|
return versionName;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return `version-${versionName}`;
|
|
22
|
-
}
|
|
19
|
+
// I don't like this "version-" prefix,
|
|
20
|
+
// but it's for consistency with site/versioned_docs
|
|
21
|
+
return `version-${versionName}`;
|
|
23
22
|
}
|
|
24
23
|
// TODO legacy, the sidebar name is like "version-2.0.0-alpha.66/docs"
|
|
25
24
|
// input: "version-2.0.0-alpha.66/docs"
|
|
@@ -32,8 +31,8 @@ function getNormalizedSidebarName({ versionName, sidebarName, }) {
|
|
|
32
31
|
return rest.join('/');
|
|
33
32
|
}
|
|
34
33
|
/*
|
|
35
|
-
// Do we need to translate doc
|
|
36
|
-
// It seems translating
|
|
34
|
+
// Do we need to translate doc metadata?
|
|
35
|
+
// It seems translating front matter labels is good enough
|
|
37
36
|
function getDocTranslations(doc: DocMetadata): TranslationFileContent {
|
|
38
37
|
return {
|
|
39
38
|
[`${doc.unversionedId}.title`]: {
|
|
@@ -44,7 +43,8 @@ function getDocTranslations(doc: DocMetadata): TranslationFileContent {
|
|
|
44
43
|
? {
|
|
45
44
|
[`${doc.unversionedId}.sidebar_label`]: {
|
|
46
45
|
message: doc.sidebar_label,
|
|
47
|
-
description:
|
|
46
|
+
description:
|
|
47
|
+
`The sidebar label for doc with id=${doc.unversionedId}`,
|
|
48
48
|
},
|
|
49
49
|
}
|
|
50
50
|
: undefined),
|
|
@@ -74,44 +74,88 @@ function translateDocs(
|
|
|
74
74
|
}
|
|
75
75
|
*/
|
|
76
76
|
function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
77
|
-
const categories =
|
|
78
|
-
const categoryContent =
|
|
79
|
-
|
|
80
|
-
.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
77
|
+
const categories = (0, utils_1.collectSidebarCategories)(sidebar);
|
|
78
|
+
const categoryContent = Object.fromEntries(categories.flatMap((category) => {
|
|
79
|
+
const entries = [];
|
|
80
|
+
entries.push([
|
|
81
|
+
`sidebar.${sidebarName}.category.${category.label}`,
|
|
82
|
+
{
|
|
83
|
+
message: category.label,
|
|
84
|
+
description: `The label for category ${category.label} in sidebar ${sidebarName}`,
|
|
85
|
+
},
|
|
86
|
+
]);
|
|
87
|
+
if (category.link) {
|
|
88
|
+
if (category.link.type === 'generated-index') {
|
|
89
|
+
if (category.link.title) {
|
|
90
|
+
entries.push([
|
|
91
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`,
|
|
92
|
+
{
|
|
93
|
+
message: category.link.title,
|
|
94
|
+
description: `The generated-index page title for category ${category.label} in sidebar ${sidebarName}`,
|
|
95
|
+
},
|
|
96
|
+
]);
|
|
97
|
+
}
|
|
98
|
+
if (category.link.description) {
|
|
99
|
+
entries.push([
|
|
100
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`,
|
|
101
|
+
{
|
|
102
|
+
message: category.link.description,
|
|
103
|
+
description: `The generated-index page description for category ${category.label} in sidebar ${sidebarName}`,
|
|
104
|
+
},
|
|
105
|
+
]);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return entries;
|
|
110
|
+
}));
|
|
111
|
+
const links = (0, utils_1.collectSidebarLinks)(sidebar);
|
|
112
|
+
const linksContent = Object.fromEntries(links.map((link) => [
|
|
113
|
+
`sidebar.${sidebarName}.link.${link.label}`,
|
|
114
|
+
{
|
|
115
|
+
message: link.label,
|
|
116
|
+
description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
|
|
117
|
+
},
|
|
118
|
+
]));
|
|
119
|
+
return (0, utils_2.mergeTranslations)([categoryContent, linksContent]);
|
|
94
120
|
}
|
|
95
121
|
function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
96
|
-
|
|
97
|
-
|
|
122
|
+
function transformSidebarCategoryLink(category) {
|
|
123
|
+
if (!category.link) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
if (category.link.type === 'generated-index') {
|
|
127
|
+
const title = sidebarsTranslations[`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`]?.message ?? category.link.title;
|
|
128
|
+
const description = sidebarsTranslations[`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`]?.message ?? category.link.description;
|
|
129
|
+
return {
|
|
130
|
+
...category.link,
|
|
131
|
+
title,
|
|
132
|
+
description,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return category.link;
|
|
136
|
+
}
|
|
137
|
+
return (0, utils_1.transformSidebarItems)(sidebar, (item) => {
|
|
98
138
|
if (item.type === 'category') {
|
|
139
|
+
const link = transformSidebarCategoryLink(item);
|
|
99
140
|
return {
|
|
100
141
|
...item,
|
|
101
|
-
label:
|
|
142
|
+
label: sidebarsTranslations[`sidebar.${sidebarName}.category.${item.label}`]
|
|
143
|
+
?.message ?? item.label,
|
|
144
|
+
...(link && { link }),
|
|
102
145
|
};
|
|
103
146
|
}
|
|
104
147
|
if (item.type === 'link') {
|
|
105
148
|
return {
|
|
106
149
|
...item,
|
|
107
|
-
label:
|
|
150
|
+
label: sidebarsTranslations[`sidebar.${sidebarName}.link.${item.label}`]
|
|
151
|
+
?.message ?? item.label,
|
|
108
152
|
};
|
|
109
153
|
}
|
|
110
154
|
return item;
|
|
111
155
|
});
|
|
112
156
|
}
|
|
113
157
|
function getSidebarsTranslations(version) {
|
|
114
|
-
return
|
|
158
|
+
return (0, utils_2.mergeTranslations)(Object.entries(version.sidebars).map(([sidebarName, sidebar]) => {
|
|
115
159
|
const normalizedSidebarName = getNormalizedSidebarName({
|
|
116
160
|
sidebarName,
|
|
117
161
|
versionName: version.versionName,
|
|
@@ -120,16 +164,14 @@ function getSidebarsTranslations(version) {
|
|
|
120
164
|
}));
|
|
121
165
|
}
|
|
122
166
|
function translateSidebars(version, sidebarsTranslations) {
|
|
123
|
-
return lodash_1.mapValues(version.sidebars, (sidebar, sidebarName) => {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
sidebarName
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
});
|
|
132
|
-
});
|
|
167
|
+
return lodash_1.default.mapValues(version.sidebars, (sidebar, sidebarName) => translateSidebar({
|
|
168
|
+
sidebar,
|
|
169
|
+
sidebarName: getNormalizedSidebarName({
|
|
170
|
+
sidebarName,
|
|
171
|
+
versionName: version.versionName,
|
|
172
|
+
}),
|
|
173
|
+
sidebarsTranslations,
|
|
174
|
+
}));
|
|
133
175
|
}
|
|
134
176
|
function getVersionTranslationFiles(version) {
|
|
135
177
|
const versionTranslations = {
|
|
@@ -139,11 +181,12 @@ function getVersionTranslationFiles(version) {
|
|
|
139
181
|
},
|
|
140
182
|
};
|
|
141
183
|
const sidebarsTranslations = getSidebarsTranslations(version);
|
|
142
|
-
// const docsTranslations: TranslationFileContent =
|
|
184
|
+
// const docsTranslations: TranslationFileContent =
|
|
185
|
+
// getDocsTranslations(version);
|
|
143
186
|
return [
|
|
144
187
|
{
|
|
145
188
|
path: getVersionFileName(version.versionName),
|
|
146
|
-
content:
|
|
189
|
+
content: (0, utils_2.mergeTranslations)([
|
|
147
190
|
versionTranslations,
|
|
148
191
|
sidebarsTranslations,
|
|
149
192
|
// docsTranslations,
|
|
@@ -152,17 +195,16 @@ function getVersionTranslationFiles(version) {
|
|
|
152
195
|
];
|
|
153
196
|
}
|
|
154
197
|
function translateVersion(version, translationFiles) {
|
|
155
|
-
var _a;
|
|
156
198
|
const versionTranslations = translationFiles[getVersionFileName(version.versionName)].content;
|
|
157
199
|
return {
|
|
158
200
|
...version,
|
|
159
|
-
versionLabel:
|
|
201
|
+
versionLabel: versionTranslations['version.label']?.message,
|
|
160
202
|
sidebars: translateSidebars(version, versionTranslations),
|
|
161
203
|
// docs: translateDocs(version.docs, versionTranslations),
|
|
162
204
|
};
|
|
163
205
|
}
|
|
164
206
|
function getVersionsTranslationFiles(versions) {
|
|
165
|
-
return
|
|
207
|
+
return versions.flatMap(getVersionTranslationFiles);
|
|
166
208
|
}
|
|
167
209
|
function translateVersions(versions, translationFiles) {
|
|
168
210
|
return versions.map((version) => translateVersion(version, translationFiles));
|
|
@@ -172,7 +214,7 @@ function getLoadedContentTranslationFiles(loadedContent) {
|
|
|
172
214
|
}
|
|
173
215
|
exports.getLoadedContentTranslationFiles = getLoadedContentTranslationFiles;
|
|
174
216
|
function translateLoadedContent(loadedContent, translationFiles) {
|
|
175
|
-
const translationFilesMap = lodash_1.keyBy(translationFiles, (f) => f.path);
|
|
217
|
+
const translationFilesMap = lodash_1.default.keyBy(translationFiles, (f) => f.path);
|
|
176
218
|
return {
|
|
177
219
|
loadedVersions: translateVersions(loadedContent.loadedVersions, translationFilesMap),
|
|
178
220
|
};
|
package/lib/types.d.ts
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
8
|
-
import {
|
|
7
|
+
import type { Sidebars } from './sidebars/types';
|
|
8
|
+
import type { Tag, FrontMatterTag } from '@docusaurus/utils';
|
|
9
|
+
import type { BrokenMarkdownLink as IBrokenMarkdownLink, ContentPaths } from '@docusaurus/utils/lib/markdownLinks';
|
|
10
|
+
import type { VersionBanner } from '@docusaurus/plugin-content-docs';
|
|
9
11
|
export declare type DocFile = {
|
|
10
12
|
contentPath: string;
|
|
11
13
|
filePath: string;
|
|
@@ -13,114 +15,20 @@ export declare type DocFile = {
|
|
|
13
15
|
content: string;
|
|
14
16
|
lastUpdate: LastUpdateData;
|
|
15
17
|
};
|
|
16
|
-
export declare type VersionName = string;
|
|
17
18
|
export declare type VersionMetadata = ContentPaths & {
|
|
18
|
-
versionName:
|
|
19
|
+
versionName: string;
|
|
19
20
|
versionLabel: string;
|
|
20
21
|
versionPath: string;
|
|
22
|
+
tagsPath: string;
|
|
21
23
|
versionEditUrl?: string | undefined;
|
|
22
24
|
versionEditUrlLocalized?: string | undefined;
|
|
23
|
-
versionBanner: VersionBanner;
|
|
25
|
+
versionBanner: VersionBanner | null;
|
|
26
|
+
versionBadge: boolean;
|
|
27
|
+
versionClassName: string;
|
|
24
28
|
isLast: boolean;
|
|
25
29
|
sidebarFilePath: string | false | undefined;
|
|
26
30
|
routePriority: number | undefined;
|
|
27
31
|
};
|
|
28
|
-
export declare type EditUrlFunction = (editUrlParams: {
|
|
29
|
-
version: string;
|
|
30
|
-
versionDocsDirPath: string;
|
|
31
|
-
docPath: string;
|
|
32
|
-
permalink: string;
|
|
33
|
-
locale: string;
|
|
34
|
-
}) => string | undefined;
|
|
35
|
-
export declare type MetadataOptions = {
|
|
36
|
-
routeBasePath: string;
|
|
37
|
-
homePageId?: string;
|
|
38
|
-
editUrl?: string | EditUrlFunction;
|
|
39
|
-
editCurrentVersion: boolean;
|
|
40
|
-
editLocalizedFiles: boolean;
|
|
41
|
-
showLastUpdateTime?: boolean;
|
|
42
|
-
showLastUpdateAuthor?: boolean;
|
|
43
|
-
numberPrefixParser: NumberPrefixParser;
|
|
44
|
-
};
|
|
45
|
-
export declare type PathOptions = {
|
|
46
|
-
path: string;
|
|
47
|
-
sidebarPath?: string | false | undefined;
|
|
48
|
-
};
|
|
49
|
-
export declare type VersionBanner = 'none' | 'unreleased' | 'unmaintained';
|
|
50
|
-
export declare type VersionOptions = {
|
|
51
|
-
path?: string;
|
|
52
|
-
label?: string;
|
|
53
|
-
banner?: VersionBanner;
|
|
54
|
-
};
|
|
55
|
-
export declare type VersionsOptions = {
|
|
56
|
-
lastVersion?: string;
|
|
57
|
-
versions: Record<string, VersionOptions>;
|
|
58
|
-
onlyIncludeVersions?: string[];
|
|
59
|
-
};
|
|
60
|
-
export declare type PluginOptions = MetadataOptions & PathOptions & VersionsOptions & RemarkAndRehypePluginOptions & {
|
|
61
|
-
id: string;
|
|
62
|
-
include: string[];
|
|
63
|
-
docLayoutComponent: string;
|
|
64
|
-
docItemComponent: string;
|
|
65
|
-
admonitions: Record<string, unknown>;
|
|
66
|
-
disableVersioning: boolean;
|
|
67
|
-
includeCurrentVersion: boolean;
|
|
68
|
-
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
69
|
-
};
|
|
70
|
-
export declare type SidebarItemBase = {
|
|
71
|
-
customProps?: Record<string, unknown>;
|
|
72
|
-
};
|
|
73
|
-
export declare type SidebarItemDoc = SidebarItemBase & {
|
|
74
|
-
type: 'doc' | 'ref';
|
|
75
|
-
label?: string;
|
|
76
|
-
id: string;
|
|
77
|
-
};
|
|
78
|
-
export declare type SidebarItemLink = SidebarItemBase & {
|
|
79
|
-
type: 'link';
|
|
80
|
-
href: string;
|
|
81
|
-
label: string;
|
|
82
|
-
};
|
|
83
|
-
export declare type SidebarItemCategory = SidebarItemBase & {
|
|
84
|
-
type: 'category';
|
|
85
|
-
label: string;
|
|
86
|
-
items: SidebarItem[];
|
|
87
|
-
collapsed: boolean;
|
|
88
|
-
};
|
|
89
|
-
export declare type UnprocessedSidebarItemAutogenerated = {
|
|
90
|
-
type: 'autogenerated';
|
|
91
|
-
dirName: string;
|
|
92
|
-
};
|
|
93
|
-
export declare type UnprocessedSidebarItemCategory = SidebarItemBase & {
|
|
94
|
-
type: 'category';
|
|
95
|
-
label: string;
|
|
96
|
-
items: UnprocessedSidebarItem[];
|
|
97
|
-
collapsed: boolean;
|
|
98
|
-
};
|
|
99
|
-
export declare type UnprocessedSidebarItem = SidebarItemDoc | SidebarItemLink | UnprocessedSidebarItemCategory | UnprocessedSidebarItemAutogenerated;
|
|
100
|
-
export declare type UnprocessedSidebar = UnprocessedSidebarItem[];
|
|
101
|
-
export declare type UnprocessedSidebars = Record<string, UnprocessedSidebar>;
|
|
102
|
-
export declare type SidebarItem = SidebarItemDoc | SidebarItemLink | SidebarItemCategory;
|
|
103
|
-
export declare type Sidebar = SidebarItem[];
|
|
104
|
-
export declare type SidebarItemType = SidebarItem['type'];
|
|
105
|
-
export declare type Sidebars = Record<string, Sidebar>;
|
|
106
|
-
export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
|
|
107
|
-
export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
|
|
108
|
-
export declare type SidebarItemsGeneratorArgs = {
|
|
109
|
-
item: UnprocessedSidebarItemAutogenerated;
|
|
110
|
-
version: SidebarItemsGeneratorVersion;
|
|
111
|
-
docs: SidebarItemsGeneratorDoc[];
|
|
112
|
-
numberPrefixParser: NumberPrefixParser;
|
|
113
|
-
};
|
|
114
|
-
export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<SidebarItem[]>;
|
|
115
|
-
export declare type SidebarItemsGeneratorOptionArgs = {
|
|
116
|
-
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
117
|
-
} & SidebarItemsGeneratorArgs;
|
|
118
|
-
export declare type SidebarItemsGeneratorOption = (generatorArgs: SidebarItemsGeneratorOptionArgs) => Promise<SidebarItem[]>;
|
|
119
|
-
export declare type OrderMetadata = {
|
|
120
|
-
previous?: string;
|
|
121
|
-
next?: string;
|
|
122
|
-
sidebar?: string;
|
|
123
|
-
};
|
|
124
32
|
export declare type LastUpdateData = {
|
|
125
33
|
lastUpdatedAt?: number;
|
|
126
34
|
formattedLastUpdatedAt?: string;
|
|
@@ -129,6 +37,7 @@ export declare type LastUpdateData = {
|
|
|
129
37
|
export declare type DocFrontMatter = {
|
|
130
38
|
id?: string;
|
|
131
39
|
title?: string;
|
|
40
|
+
tags?: FrontMatterTag[];
|
|
132
41
|
hide_title?: boolean;
|
|
133
42
|
hide_table_of_contents?: boolean;
|
|
134
43
|
keywords?: string[];
|
|
@@ -137,15 +46,21 @@ export declare type DocFrontMatter = {
|
|
|
137
46
|
slug?: string;
|
|
138
47
|
sidebar_label?: string;
|
|
139
48
|
sidebar_position?: number;
|
|
49
|
+
sidebar_class_name?: string;
|
|
50
|
+
sidebar_custom_props?: Record<string, unknown>;
|
|
51
|
+
displayed_sidebar?: string | null;
|
|
140
52
|
pagination_label?: string;
|
|
141
53
|
custom_edit_url?: string | null;
|
|
142
54
|
parse_number_prefixes?: boolean;
|
|
55
|
+
toc_min_heading_level?: number;
|
|
56
|
+
toc_max_heading_level?: number;
|
|
57
|
+
pagination_next?: string | null;
|
|
58
|
+
pagination_prev?: string | null;
|
|
143
59
|
};
|
|
144
60
|
export declare type DocMetadataBase = LastUpdateData & {
|
|
145
|
-
version: VersionName;
|
|
146
|
-
unversionedId: string;
|
|
147
61
|
id: string;
|
|
148
|
-
|
|
62
|
+
unversionedId: string;
|
|
63
|
+
version: string;
|
|
149
64
|
title: string;
|
|
150
65
|
description: string;
|
|
151
66
|
source: string;
|
|
@@ -154,6 +69,7 @@ export declare type DocMetadataBase = LastUpdateData & {
|
|
|
154
69
|
permalink: string;
|
|
155
70
|
sidebarPosition?: number;
|
|
156
71
|
editUrl?: string | null;
|
|
72
|
+
tags: Tag[];
|
|
157
73
|
frontMatter: DocFrontMatter & Record<string, unknown>;
|
|
158
74
|
};
|
|
159
75
|
export declare type DocNavLink = {
|
|
@@ -165,36 +81,38 @@ export declare type DocMetadata = DocMetadataBase & {
|
|
|
165
81
|
previous?: DocNavLink;
|
|
166
82
|
next?: DocNavLink;
|
|
167
83
|
};
|
|
84
|
+
export declare type CategoryGeneratedIndexMetadata = {
|
|
85
|
+
title: string;
|
|
86
|
+
description?: string;
|
|
87
|
+
slug: string;
|
|
88
|
+
permalink: string;
|
|
89
|
+
sidebar: string;
|
|
90
|
+
previous?: DocNavLink;
|
|
91
|
+
next?: DocNavLink;
|
|
92
|
+
image?: string;
|
|
93
|
+
keywords?: string | readonly string[];
|
|
94
|
+
};
|
|
168
95
|
export declare type SourceToPermalink = {
|
|
169
96
|
[source: string]: string;
|
|
170
97
|
};
|
|
98
|
+
export declare type VersionTag = {
|
|
99
|
+
name: string;
|
|
100
|
+
docIds: string[];
|
|
101
|
+
permalink: string;
|
|
102
|
+
};
|
|
103
|
+
export declare type VersionTags = {
|
|
104
|
+
[key: string]: VersionTag;
|
|
105
|
+
};
|
|
171
106
|
export declare type LoadedVersion = VersionMetadata & {
|
|
172
107
|
versionPath: string;
|
|
173
108
|
mainDocId: string;
|
|
174
109
|
docs: DocMetadata[];
|
|
175
110
|
sidebars: Sidebars;
|
|
176
|
-
|
|
111
|
+
categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
|
|
177
112
|
};
|
|
178
113
|
export declare type LoadedContent = {
|
|
179
114
|
loadedVersions: LoadedVersion[];
|
|
180
115
|
};
|
|
181
|
-
export declare type GlobalDoc = {
|
|
182
|
-
id: string;
|
|
183
|
-
path: string;
|
|
184
|
-
sidebar: string | undefined;
|
|
185
|
-
};
|
|
186
|
-
export declare type GlobalVersion = {
|
|
187
|
-
name: VersionName;
|
|
188
|
-
label: string;
|
|
189
|
-
isLast: boolean;
|
|
190
|
-
path: string;
|
|
191
|
-
mainDocId: string;
|
|
192
|
-
docs: GlobalDoc[];
|
|
193
|
-
};
|
|
194
|
-
export declare type GlobalPluginData = {
|
|
195
|
-
path: string;
|
|
196
|
-
versions: GlobalVersion[];
|
|
197
|
-
};
|
|
198
116
|
export declare type BrokenMarkdownLink = IBrokenMarkdownLink<VersionMetadata>;
|
|
199
117
|
export declare type DocsMarkdownOption = {
|
|
200
118
|
versionsMetadata: VersionMetadata[];
|
|
@@ -202,7 +120,3 @@ export declare type DocsMarkdownOption = {
|
|
|
202
120
|
sourceToPermalink: SourceToPermalink;
|
|
203
121
|
onBrokenMarkdownLink: (brokenMarkdownLink: BrokenMarkdownLink) => void;
|
|
204
122
|
};
|
|
205
|
-
export declare type NumberPrefixParser = (filename: string) => {
|
|
206
|
-
filename: string;
|
|
207
|
-
numberPrefix?: number;
|
|
208
|
-
};
|
package/lib/versions.d.ts
CHANGED
|
@@ -4,13 +4,38 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import type { VersionMetadata } from './types';
|
|
8
|
+
import type { PluginOptions, VersionBanner } from '@docusaurus/plugin-content-docs';
|
|
9
|
+
import type { LoadContext } from '@docusaurus/types';
|
|
9
10
|
export declare function getVersionedDocsDirPath(siteDir: string, pluginId: string): string;
|
|
10
11
|
export declare function getVersionedSidebarsDirPath(siteDir: string, pluginId: string): string;
|
|
11
12
|
export declare function getVersionsFilePath(siteDir: string, pluginId: string): string;
|
|
13
|
+
export declare function readVersionsFile(siteDir: string, pluginId: string): Promise<string[] | null>;
|
|
14
|
+
export declare function readVersionNames(siteDir: string, options: Pick<PluginOptions, 'id' | 'disableVersioning' | 'includeCurrentVersion'>): Promise<string[]>;
|
|
15
|
+
export declare function getDefaultVersionBanner({ versionName, versionNames, lastVersionName, }: {
|
|
16
|
+
versionName: string;
|
|
17
|
+
versionNames: string[];
|
|
18
|
+
lastVersionName: string;
|
|
19
|
+
}): VersionBanner | null;
|
|
20
|
+
export declare function getVersionBanner({ versionName, versionNames, lastVersionName, options, }: {
|
|
21
|
+
versionName: string;
|
|
22
|
+
versionNames: string[];
|
|
23
|
+
lastVersionName: string;
|
|
24
|
+
options: Pick<PluginOptions, 'versions'>;
|
|
25
|
+
}): VersionBanner | null;
|
|
26
|
+
export declare function getVersionBadge({ versionName, versionNames, options, }: {
|
|
27
|
+
versionName: string;
|
|
28
|
+
versionNames: string[];
|
|
29
|
+
options: Pick<PluginOptions, 'versions'>;
|
|
30
|
+
}): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Filter versions according to provided options.
|
|
33
|
+
* Note: we preserve the order in which versions are provided;
|
|
34
|
+
* the order of the onlyIncludeVersions array does not matter
|
|
35
|
+
*/
|
|
36
|
+
export declare function filterVersions(versionNamesUnfiltered: string[], options: Pick<PluginOptions, 'onlyIncludeVersions'>): string[];
|
|
12
37
|
export declare function readVersionsMetadata({ context, options, }: {
|
|
13
38
|
context: Pick<LoadContext, 'siteDir' | 'baseUrl' | 'i18n'>;
|
|
14
|
-
options: Pick<PluginOptions, 'id' | 'path' | 'sidebarPath' | 'routeBasePath' | 'includeCurrentVersion' | 'disableVersioning' | 'lastVersion' | 'versions' | 'onlyIncludeVersions' | 'editUrl' | 'editCurrentVersion'>;
|
|
15
|
-
}): VersionMetadata[]
|
|
39
|
+
options: Pick<PluginOptions, 'id' | 'path' | 'sidebarPath' | 'routeBasePath' | 'tagsBasePath' | 'includeCurrentVersion' | 'disableVersioning' | 'lastVersion' | 'versions' | 'onlyIncludeVersions' | 'editUrl' | 'editCurrentVersion'>;
|
|
40
|
+
}): Promise<VersionMetadata[]>;
|
|
16
41
|
export declare function getDocsDirPaths(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>): [string, string];
|