@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/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 = (0, 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,31 +74,75 @@ 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
|
-
|
|
122
|
+
function transformSidebarCategoryLink(category) {
|
|
123
|
+
var _a, _b, _c, _d;
|
|
124
|
+
if (!category.link) {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
if (category.link.type === 'generated-index') {
|
|
128
|
+
const title = (_b = (_a = sidebarsTranslations[`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`]) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : category.link.title;
|
|
129
|
+
const description = (_d = (_c = sidebarsTranslations[`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`]) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : category.link.description;
|
|
130
|
+
return {
|
|
131
|
+
...category.link,
|
|
132
|
+
title,
|
|
133
|
+
description,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return category.link;
|
|
137
|
+
}
|
|
138
|
+
return (0, utils_1.transformSidebarItems)(sidebar, (item) => {
|
|
97
139
|
var _a, _b, _c, _d;
|
|
98
140
|
if (item.type === 'category') {
|
|
141
|
+
const link = transformSidebarCategoryLink(item);
|
|
99
142
|
return {
|
|
100
143
|
...item,
|
|
101
144
|
label: (_b = (_a = sidebarsTranslations[`sidebar.${sidebarName}.category.${item.label}`]) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : item.label,
|
|
145
|
+
...(link && { link }),
|
|
102
146
|
};
|
|
103
147
|
}
|
|
104
148
|
if (item.type === 'link') {
|
|
@@ -111,7 +155,7 @@ function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
|
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,
|
|
@@ -162,7 +205,7 @@ function translateVersion(version, translationFiles) {
|
|
|
162
205
|
};
|
|
163
206
|
}
|
|
164
207
|
function getVersionsTranslationFiles(versions) {
|
|
165
|
-
return
|
|
208
|
+
return versions.flatMap(getVersionTranslationFiles);
|
|
166
209
|
}
|
|
167
210
|
function translateVersions(versions, translationFiles) {
|
|
168
211
|
return versions.map((version) => translateVersion(version, translationFiles));
|
|
@@ -172,7 +215,7 @@ function getLoadedContentTranslationFiles(loadedContent) {
|
|
|
172
215
|
}
|
|
173
216
|
exports.getLoadedContentTranslationFiles = getLoadedContentTranslationFiles;
|
|
174
217
|
function translateLoadedContent(loadedContent, translationFiles) {
|
|
175
|
-
const translationFilesMap = lodash_1.keyBy(translationFiles, (f) => f.path);
|
|
218
|
+
const translationFilesMap = lodash_1.default.keyBy(translationFiles, (f) => f.path);
|
|
176
219
|
return {
|
|
177
220
|
loadedVersions: translateVersions(loadedContent.loadedVersions, translationFilesMap),
|
|
178
221
|
};
|
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,135 +15,62 @@ 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;
|
|
25
|
+
versionBanner: VersionBanner | null;
|
|
26
|
+
versionBadge: boolean;
|
|
27
|
+
versionClassName: string;
|
|
23
28
|
isLast: boolean;
|
|
24
29
|
sidebarFilePath: string | false | undefined;
|
|
25
30
|
routePriority: number | undefined;
|
|
26
31
|
};
|
|
27
|
-
export declare type EditUrlFunction = (editUrlParams: {
|
|
28
|
-
version: string;
|
|
29
|
-
versionDocsDirPath: string;
|
|
30
|
-
docPath: string;
|
|
31
|
-
permalink: string;
|
|
32
|
-
locale: string;
|
|
33
|
-
}) => string | undefined;
|
|
34
|
-
export declare type MetadataOptions = {
|
|
35
|
-
routeBasePath: string;
|
|
36
|
-
homePageId?: string;
|
|
37
|
-
editUrl?: string | EditUrlFunction;
|
|
38
|
-
editCurrentVersion: boolean;
|
|
39
|
-
editLocalizedFiles: boolean;
|
|
40
|
-
showLastUpdateTime?: boolean;
|
|
41
|
-
showLastUpdateAuthor?: boolean;
|
|
42
|
-
numberPrefixParser: NumberPrefixParser;
|
|
43
|
-
};
|
|
44
|
-
export declare type PathOptions = {
|
|
45
|
-
path: string;
|
|
46
|
-
sidebarPath?: string | false | undefined;
|
|
47
|
-
};
|
|
48
|
-
export declare type VersionOptions = {
|
|
49
|
-
path?: string;
|
|
50
|
-
label?: string;
|
|
51
|
-
};
|
|
52
|
-
export declare type VersionsOptions = {
|
|
53
|
-
lastVersion?: string;
|
|
54
|
-
versions: Record<string, VersionOptions>;
|
|
55
|
-
onlyIncludeVersions?: string[];
|
|
56
|
-
};
|
|
57
|
-
export declare type PluginOptions = MetadataOptions & PathOptions & VersionsOptions & RemarkAndRehypePluginOptions & {
|
|
58
|
-
id: string;
|
|
59
|
-
include: string[];
|
|
60
|
-
docLayoutComponent: string;
|
|
61
|
-
docItemComponent: string;
|
|
62
|
-
admonitions: Record<string, unknown>;
|
|
63
|
-
disableVersioning: boolean;
|
|
64
|
-
excludeNextVersionDocs?: boolean;
|
|
65
|
-
includeCurrentVersion: boolean;
|
|
66
|
-
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
67
|
-
};
|
|
68
|
-
export declare type SidebarItemBase = {
|
|
69
|
-
customProps?: Record<string, unknown>;
|
|
70
|
-
};
|
|
71
|
-
export declare type SidebarItemDoc = SidebarItemBase & {
|
|
72
|
-
type: 'doc' | 'ref';
|
|
73
|
-
label?: string;
|
|
74
|
-
id: string;
|
|
75
|
-
};
|
|
76
|
-
export declare type SidebarItemLink = SidebarItemBase & {
|
|
77
|
-
type: 'link';
|
|
78
|
-
href: string;
|
|
79
|
-
label: string;
|
|
80
|
-
};
|
|
81
|
-
export declare type SidebarItemCategory = SidebarItemBase & {
|
|
82
|
-
type: 'category';
|
|
83
|
-
label: string;
|
|
84
|
-
items: SidebarItem[];
|
|
85
|
-
collapsed: boolean;
|
|
86
|
-
};
|
|
87
|
-
export declare type UnprocessedSidebarItemAutogenerated = {
|
|
88
|
-
type: 'autogenerated';
|
|
89
|
-
dirName: string;
|
|
90
|
-
};
|
|
91
|
-
export declare type UnprocessedSidebarItemCategory = SidebarItemBase & {
|
|
92
|
-
type: 'category';
|
|
93
|
-
label: string;
|
|
94
|
-
items: UnprocessedSidebarItem[];
|
|
95
|
-
collapsed: boolean;
|
|
96
|
-
};
|
|
97
|
-
export declare type UnprocessedSidebarItem = SidebarItemDoc | SidebarItemLink | UnprocessedSidebarItemCategory | UnprocessedSidebarItemAutogenerated;
|
|
98
|
-
export declare type UnprocessedSidebar = UnprocessedSidebarItem[];
|
|
99
|
-
export declare type UnprocessedSidebars = Record<string, UnprocessedSidebar>;
|
|
100
|
-
export declare type SidebarItem = SidebarItemDoc | SidebarItemLink | SidebarItemCategory;
|
|
101
|
-
export declare type Sidebar = SidebarItem[];
|
|
102
|
-
export declare type SidebarItemType = SidebarItem['type'];
|
|
103
|
-
export declare type Sidebars = Record<string, Sidebar>;
|
|
104
|
-
export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
|
|
105
|
-
export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
|
|
106
|
-
export declare type SidebarItemsGeneratorArgs = {
|
|
107
|
-
item: UnprocessedSidebarItemAutogenerated;
|
|
108
|
-
version: SidebarItemsGeneratorVersion;
|
|
109
|
-
docs: SidebarItemsGeneratorDoc[];
|
|
110
|
-
numberPrefixParser: NumberPrefixParser;
|
|
111
|
-
};
|
|
112
|
-
export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<SidebarItem[]>;
|
|
113
|
-
export declare type SidebarItemsGeneratorOptionArgs = {
|
|
114
|
-
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
115
|
-
} & SidebarItemsGeneratorArgs;
|
|
116
|
-
export declare type SidebarItemsGeneratorOption = (generatorArgs: SidebarItemsGeneratorOptionArgs) => Promise<SidebarItem[]>;
|
|
117
|
-
export declare type OrderMetadata = {
|
|
118
|
-
previous?: string;
|
|
119
|
-
next?: string;
|
|
120
|
-
sidebar?: string;
|
|
121
|
-
};
|
|
122
32
|
export declare type LastUpdateData = {
|
|
123
33
|
lastUpdatedAt?: number;
|
|
124
34
|
formattedLastUpdatedAt?: string;
|
|
125
35
|
lastUpdatedBy?: string;
|
|
126
36
|
};
|
|
127
|
-
export declare type
|
|
128
|
-
|
|
37
|
+
export declare type DocFrontMatter = {
|
|
38
|
+
id?: string;
|
|
39
|
+
title?: string;
|
|
40
|
+
tags?: FrontMatterTag[];
|
|
41
|
+
hide_title?: boolean;
|
|
42
|
+
hide_table_of_contents?: boolean;
|
|
43
|
+
keywords?: string[];
|
|
44
|
+
image?: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
slug?: string;
|
|
47
|
+
sidebar_label?: string;
|
|
48
|
+
sidebar_position?: number;
|
|
49
|
+
sidebar_class_name?: string;
|
|
50
|
+
sidebar_custom_props?: Record<string, unknown>;
|
|
51
|
+
displayed_sidebar?: string | null;
|
|
52
|
+
pagination_label?: string;
|
|
53
|
+
custom_edit_url?: string | null;
|
|
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;
|
|
129
59
|
};
|
|
130
60
|
export declare type DocMetadataBase = LastUpdateData & {
|
|
131
|
-
version: VersionName;
|
|
132
|
-
unversionedId: string;
|
|
133
61
|
id: string;
|
|
134
|
-
|
|
62
|
+
unversionedId: string;
|
|
63
|
+
version: string;
|
|
135
64
|
title: string;
|
|
136
65
|
description: string;
|
|
137
66
|
source: string;
|
|
138
67
|
sourceDirName: string;
|
|
139
68
|
slug: string;
|
|
140
69
|
permalink: string;
|
|
141
|
-
sidebar_label?: string;
|
|
142
70
|
sidebarPosition?: number;
|
|
143
71
|
editUrl?: string | null;
|
|
144
|
-
|
|
72
|
+
tags: Tag[];
|
|
73
|
+
frontMatter: DocFrontMatter & Record<string, unknown>;
|
|
145
74
|
};
|
|
146
75
|
export declare type DocNavLink = {
|
|
147
76
|
title: string;
|
|
@@ -152,36 +81,38 @@ export declare type DocMetadata = DocMetadataBase & {
|
|
|
152
81
|
previous?: DocNavLink;
|
|
153
82
|
next?: DocNavLink;
|
|
154
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
|
+
};
|
|
155
95
|
export declare type SourceToPermalink = {
|
|
156
96
|
[source: string]: string;
|
|
157
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
|
+
};
|
|
158
106
|
export declare type LoadedVersion = VersionMetadata & {
|
|
159
107
|
versionPath: string;
|
|
160
108
|
mainDocId: string;
|
|
161
109
|
docs: DocMetadata[];
|
|
162
110
|
sidebars: Sidebars;
|
|
163
|
-
|
|
111
|
+
categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
|
|
164
112
|
};
|
|
165
113
|
export declare type LoadedContent = {
|
|
166
114
|
loadedVersions: LoadedVersion[];
|
|
167
115
|
};
|
|
168
|
-
export declare type GlobalDoc = {
|
|
169
|
-
id: string;
|
|
170
|
-
path: string;
|
|
171
|
-
sidebar: string | undefined;
|
|
172
|
-
};
|
|
173
|
-
export declare type GlobalVersion = {
|
|
174
|
-
name: VersionName;
|
|
175
|
-
label: string;
|
|
176
|
-
isLast: boolean;
|
|
177
|
-
path: string;
|
|
178
|
-
mainDocId: string;
|
|
179
|
-
docs: GlobalDoc[];
|
|
180
|
-
};
|
|
181
|
-
export declare type GlobalPluginData = {
|
|
182
|
-
path: string;
|
|
183
|
-
versions: GlobalVersion[];
|
|
184
|
-
};
|
|
185
116
|
export declare type BrokenMarkdownLink = IBrokenMarkdownLink<VersionMetadata>;
|
|
186
117
|
export declare type DocsMarkdownOption = {
|
|
187
118
|
versionsMetadata: VersionMetadata[];
|
|
@@ -189,7 +120,3 @@ export declare type DocsMarkdownOption = {
|
|
|
189
120
|
sourceToPermalink: SourceToPermalink;
|
|
190
121
|
onBrokenMarkdownLink: (brokenMarkdownLink: BrokenMarkdownLink) => void;
|
|
191
122
|
};
|
|
192
|
-
export declare type NumberPrefixParser = (filename: string) => {
|
|
193
|
-
filename: string;
|
|
194
|
-
numberPrefix?: number;
|
|
195
|
-
};
|
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];
|