@docusaurus/plugin-content-docs 0.0.0-5127 → 0.0.0-5130
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/props.js +15 -1
- package/lib/sidebars/normalization.js +4 -0
- package/lib/sidebars/types.d.ts +6 -1
- package/lib/sidebars/utils.d.ts +1 -0
- package/lib/sidebars/utils.js +5 -1
- package/lib/sidebars/validation.js +1 -0
- package/lib/translations.js +18 -1
- package/package.json +9 -9
- package/src/props.ts +19 -1
- package/src/sidebars/normalization.ts +6 -0
- package/src/sidebars/types.ts +6 -1
- package/src/sidebars/utils.ts +3 -0
- package/src/sidebars/validation.ts +1 -0
- package/src/translations.ts +26 -1
package/lib/props.js
CHANGED
|
@@ -43,10 +43,24 @@ Available document ids are:
|
|
|
43
43
|
return undefined;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
function getCategoryLinkCustomProps(link) {
|
|
47
|
+
switch (link?.type) {
|
|
48
|
+
case 'doc':
|
|
49
|
+
return getDocById(link.id).frontMatter.sidebar_custom_props;
|
|
50
|
+
default:
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
46
54
|
function convertCategory(item) {
|
|
47
55
|
const { link, ...rest } = item;
|
|
48
56
|
const href = getCategoryLinkHref(link);
|
|
49
|
-
|
|
57
|
+
const customProps = item.customProps ?? getCategoryLinkCustomProps(link);
|
|
58
|
+
return {
|
|
59
|
+
...rest,
|
|
60
|
+
items: item.items.map(normalizeItem),
|
|
61
|
+
...(href && { href }),
|
|
62
|
+
...(customProps && { customProps }),
|
|
63
|
+
};
|
|
50
64
|
}
|
|
51
65
|
function normalizeItem(item) {
|
|
52
66
|
switch (item.type) {
|
|
@@ -30,6 +30,10 @@ function normalizeItem(item) {
|
|
|
30
30
|
// This will never throw anyways
|
|
31
31
|
return normalizeSidebar(item, 'sidebar items slice');
|
|
32
32
|
}
|
|
33
|
+
if ((item.type === 'doc' || item.type === 'ref') &&
|
|
34
|
+
typeof item.label === 'string') {
|
|
35
|
+
return [{ ...item, translatable: true }];
|
|
36
|
+
}
|
|
33
37
|
if (item.type === 'category') {
|
|
34
38
|
const normalizedCategory = {
|
|
35
39
|
...item,
|
package/lib/sidebars/types.d.ts
CHANGED
|
@@ -22,6 +22,11 @@ export declare type SidebarItemDoc = SidebarItemBase & {
|
|
|
22
22
|
type: 'doc' | 'ref';
|
|
23
23
|
label?: string;
|
|
24
24
|
id: string;
|
|
25
|
+
/**
|
|
26
|
+
* This is an internal marker. Items with labels defined in the config needs
|
|
27
|
+
* to be translated with JSON
|
|
28
|
+
*/
|
|
29
|
+
translatable?: true;
|
|
25
30
|
};
|
|
26
31
|
export declare type SidebarItemHtml = SidebarItemBase & {
|
|
27
32
|
type: 'html';
|
|
@@ -73,7 +78,7 @@ export declare type SidebarItemCategoryConfig = Expand<Optional<SidebarItemCateg
|
|
|
73
78
|
export declare type SidebarCategoriesShorthand = {
|
|
74
79
|
[sidebarCategory: string]: SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
75
80
|
};
|
|
76
|
-
export declare type SidebarItemConfig = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | SidebarItemAutogenerated | SidebarItemCategoryConfig | string | SidebarCategoriesShorthand;
|
|
81
|
+
export declare type SidebarItemConfig = Omit<SidebarItemDoc, 'translatable'> | SidebarItemHtml | SidebarItemLink | SidebarItemAutogenerated | SidebarItemCategoryConfig | string | SidebarCategoriesShorthand;
|
|
77
82
|
export declare type SidebarConfig = SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
78
83
|
export declare type SidebarsConfig = {
|
|
79
84
|
[sidebarId: string]: SidebarConfig;
|
package/lib/sidebars/utils.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare function transformSidebarItems(sidebar: Sidebar, updateFn: (item:
|
|
|
11
11
|
export declare function collectSidebarDocItems(sidebar: Sidebar): SidebarItemDoc[];
|
|
12
12
|
export declare function collectSidebarCategories(sidebar: Sidebar): SidebarItemCategory[];
|
|
13
13
|
export declare function collectSidebarLinks(sidebar: Sidebar): SidebarItemLink[];
|
|
14
|
+
export declare function collectSidebarRefs(sidebar: Sidebar): SidebarItemDoc[];
|
|
14
15
|
export declare function collectSidebarDocIds(sidebar: Sidebar): string[];
|
|
15
16
|
export declare function collectSidebarNavigation(sidebar: Sidebar): SidebarNavigationItem[];
|
|
16
17
|
export declare function collectSidebarsDocIds(sidebars: Sidebars): {
|
package/lib/sidebars/utils.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.toNavigationLink = exports.toDocNavigationLink = exports.createSidebarsUtils = exports.collectSidebarsNavigations = exports.collectSidebarsDocIds = exports.collectSidebarNavigation = exports.collectSidebarDocIds = exports.collectSidebarLinks = exports.collectSidebarCategories = exports.collectSidebarDocItems = exports.transformSidebarItems = exports.isCategoriesShorthand = void 0;
|
|
9
|
+
exports.toNavigationLink = exports.toDocNavigationLink = exports.createSidebarsUtils = exports.collectSidebarsNavigations = exports.collectSidebarsDocIds = exports.collectSidebarNavigation = exports.collectSidebarDocIds = exports.collectSidebarRefs = exports.collectSidebarLinks = exports.collectSidebarCategories = exports.collectSidebarDocItems = exports.transformSidebarItems = exports.isCategoriesShorthand = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
@@ -55,6 +55,10 @@ function collectSidebarLinks(sidebar) {
|
|
|
55
55
|
return collectSidebarItemsOfType('link', sidebar);
|
|
56
56
|
}
|
|
57
57
|
exports.collectSidebarLinks = collectSidebarLinks;
|
|
58
|
+
function collectSidebarRefs(sidebar) {
|
|
59
|
+
return collectSidebarItemsOfType('ref', sidebar);
|
|
60
|
+
}
|
|
61
|
+
exports.collectSidebarRefs = collectSidebarRefs;
|
|
58
62
|
// /!\ docId order matters for navigation!
|
|
59
63
|
function collectSidebarDocIds(sidebar) {
|
|
60
64
|
return flattenSidebarItems(sidebar).flatMap((item) => {
|
|
@@ -26,6 +26,7 @@ const sidebarItemDocSchema = sidebarItemBaseSchema.append({
|
|
|
26
26
|
type: utils_validation_1.Joi.string().valid('doc', 'ref').required(),
|
|
27
27
|
id: utils_validation_1.Joi.string().required(),
|
|
28
28
|
label: utils_validation_1.Joi.string(),
|
|
29
|
+
translatable: utils_validation_1.Joi.boolean(),
|
|
29
30
|
});
|
|
30
31
|
const sidebarItemHtmlSchema = sidebarItemBaseSchema.append({
|
|
31
32
|
type: 'html',
|
package/lib/translations.js
CHANGED
|
@@ -71,7 +71,17 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
|
71
71
|
description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
|
|
72
72
|
},
|
|
73
73
|
]));
|
|
74
|
-
|
|
74
|
+
const docs = (0, utils_2.collectSidebarDocItems)(sidebar)
|
|
75
|
+
.concat((0, utils_2.collectSidebarRefs)(sidebar))
|
|
76
|
+
.filter((item) => item.translatable);
|
|
77
|
+
const docLinksContent = Object.fromEntries(docs.map((doc) => [
|
|
78
|
+
`sidebar.${sidebarName}.doc.${doc.label}`,
|
|
79
|
+
{
|
|
80
|
+
message: doc.label,
|
|
81
|
+
description: `The label for the doc item ${doc.label} in sidebar ${sidebarName}, linking to the doc ${doc.id}`,
|
|
82
|
+
},
|
|
83
|
+
]));
|
|
84
|
+
return (0, utils_1.mergeTranslations)([categoryContent, linksContent, docLinksContent]);
|
|
75
85
|
}
|
|
76
86
|
function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
77
87
|
function transformSidebarCategoryLink(category) {
|
|
@@ -106,6 +116,13 @@ function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
|
106
116
|
?.message ?? item.label,
|
|
107
117
|
};
|
|
108
118
|
}
|
|
119
|
+
if ((item.type === 'doc' || item.type === 'ref') && item.translatable) {
|
|
120
|
+
return {
|
|
121
|
+
...item,
|
|
122
|
+
label: sidebarsTranslations[`sidebar.${sidebarName}.doc.${item.label}`]
|
|
123
|
+
?.message ?? item.label,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
109
126
|
return item;
|
|
110
127
|
});
|
|
111
128
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-5130",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
},
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@docusaurus/core": "0.0.0-
|
|
38
|
-
"@docusaurus/logger": "0.0.0-
|
|
39
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
40
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
41
|
-
"@docusaurus/types": "0.0.0-
|
|
42
|
-
"@docusaurus/utils": "0.0.0-
|
|
43
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
37
|
+
"@docusaurus/core": "0.0.0-5130",
|
|
38
|
+
"@docusaurus/logger": "0.0.0-5130",
|
|
39
|
+
"@docusaurus/mdx-loader": "0.0.0-5130",
|
|
40
|
+
"@docusaurus/module-type-aliases": "0.0.0-5130",
|
|
41
|
+
"@docusaurus/types": "0.0.0-5130",
|
|
42
|
+
"@docusaurus/utils": "0.0.0-5130",
|
|
43
|
+
"@docusaurus/utils-validation": "0.0.0-5130",
|
|
44
44
|
"@types/react-router-config": "^5.0.6",
|
|
45
45
|
"combine-promises": "^1.1.0",
|
|
46
46
|
"fs-extra": "^10.1.0",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"engines": {
|
|
68
68
|
"node": ">=16.14"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "6130c50c8f8ae0cfd19c4b37a00018d5ccf9c001"
|
|
71
71
|
}
|
package/src/props.ts
CHANGED
|
@@ -73,10 +73,28 @@ Available document ids are:
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
function getCategoryLinkCustomProps(
|
|
77
|
+
link: SidebarItemCategoryLink | undefined,
|
|
78
|
+
) {
|
|
79
|
+
switch (link?.type) {
|
|
80
|
+
case 'doc':
|
|
81
|
+
return getDocById(link.id).frontMatter.sidebar_custom_props;
|
|
82
|
+
default:
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
76
87
|
function convertCategory(item: SidebarItemCategory): PropSidebarItemCategory {
|
|
77
88
|
const {link, ...rest} = item;
|
|
78
89
|
const href = getCategoryLinkHref(link);
|
|
79
|
-
|
|
90
|
+
const customProps = item.customProps ?? getCategoryLinkCustomProps(link);
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
...rest,
|
|
94
|
+
items: item.items.map(normalizeItem),
|
|
95
|
+
...(href && {href}),
|
|
96
|
+
...(customProps && {customProps}),
|
|
97
|
+
};
|
|
80
98
|
}
|
|
81
99
|
|
|
82
100
|
function normalizeItem(item: SidebarItem): PropSidebarItem {
|
|
@@ -44,6 +44,12 @@ export function normalizeItem(
|
|
|
44
44
|
// This will never throw anyways
|
|
45
45
|
return normalizeSidebar(item, 'sidebar items slice');
|
|
46
46
|
}
|
|
47
|
+
if (
|
|
48
|
+
(item.type === 'doc' || item.type === 'ref') &&
|
|
49
|
+
typeof item.label === 'string'
|
|
50
|
+
) {
|
|
51
|
+
return [{...item, translatable: true}];
|
|
52
|
+
}
|
|
47
53
|
if (item.type === 'category') {
|
|
48
54
|
const normalizedCategory: NormalizedSidebarItemCategory = {
|
|
49
55
|
...item,
|
package/src/sidebars/types.ts
CHANGED
|
@@ -27,6 +27,11 @@ export type SidebarItemDoc = SidebarItemBase & {
|
|
|
27
27
|
type: 'doc' | 'ref';
|
|
28
28
|
label?: string;
|
|
29
29
|
id: string;
|
|
30
|
+
/**
|
|
31
|
+
* This is an internal marker. Items with labels defined in the config needs
|
|
32
|
+
* to be translated with JSON
|
|
33
|
+
*/
|
|
34
|
+
translatable?: true;
|
|
30
35
|
};
|
|
31
36
|
|
|
32
37
|
export type SidebarItemHtml = SidebarItemBase & {
|
|
@@ -94,7 +99,7 @@ export type SidebarCategoriesShorthand = {
|
|
|
94
99
|
};
|
|
95
100
|
|
|
96
101
|
export type SidebarItemConfig =
|
|
97
|
-
| SidebarItemDoc
|
|
102
|
+
| Omit<SidebarItemDoc, 'translatable'>
|
|
98
103
|
| SidebarItemHtml
|
|
99
104
|
| SidebarItemLink
|
|
100
105
|
| SidebarItemAutogenerated
|
package/src/sidebars/utils.ts
CHANGED
|
@@ -81,6 +81,9 @@ export function collectSidebarCategories(
|
|
|
81
81
|
export function collectSidebarLinks(sidebar: Sidebar): SidebarItemLink[] {
|
|
82
82
|
return collectSidebarItemsOfType('link', sidebar);
|
|
83
83
|
}
|
|
84
|
+
export function collectSidebarRefs(sidebar: Sidebar): SidebarItemDoc[] {
|
|
85
|
+
return collectSidebarItemsOfType('ref', sidebar);
|
|
86
|
+
}
|
|
84
87
|
|
|
85
88
|
// /!\ docId order matters for navigation!
|
|
86
89
|
export function collectSidebarDocIds(sidebar: Sidebar): string[] {
|
|
@@ -47,6 +47,7 @@ const sidebarItemDocSchema = sidebarItemBaseSchema.append<SidebarItemDoc>({
|
|
|
47
47
|
type: Joi.string().valid('doc', 'ref').required(),
|
|
48
48
|
id: Joi.string().required(),
|
|
49
49
|
label: Joi.string(),
|
|
50
|
+
translatable: Joi.boolean(),
|
|
50
51
|
});
|
|
51
52
|
|
|
52
53
|
const sidebarItemHtmlSchema = sidebarItemBaseSchema.append<SidebarItemHtml>({
|
package/src/translations.ts
CHANGED
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
collectSidebarCategories,
|
|
13
13
|
transformSidebarItems,
|
|
14
14
|
collectSidebarLinks,
|
|
15
|
+
collectSidebarDocItems,
|
|
16
|
+
collectSidebarRefs,
|
|
15
17
|
} from './sidebars/utils';
|
|
16
18
|
import type {
|
|
17
19
|
LoadedVersion,
|
|
@@ -111,7 +113,22 @@ function getSidebarTranslationFileContent(
|
|
|
111
113
|
]),
|
|
112
114
|
);
|
|
113
115
|
|
|
114
|
-
|
|
116
|
+
const docs = collectSidebarDocItems(sidebar)
|
|
117
|
+
.concat(collectSidebarRefs(sidebar))
|
|
118
|
+
.filter((item) => item.translatable);
|
|
119
|
+
const docLinksContent: TranslationFileContent = Object.fromEntries(
|
|
120
|
+
docs.map((doc) => [
|
|
121
|
+
`sidebar.${sidebarName}.doc.${doc.label!}`,
|
|
122
|
+
{
|
|
123
|
+
message: doc.label!,
|
|
124
|
+
description: `The label for the doc item ${doc.label!} in sidebar ${sidebarName}, linking to the doc ${
|
|
125
|
+
doc.id
|
|
126
|
+
}`,
|
|
127
|
+
},
|
|
128
|
+
]),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
return mergeTranslations([categoryContent, linksContent, docLinksContent]);
|
|
115
132
|
}
|
|
116
133
|
|
|
117
134
|
function translateSidebar({
|
|
@@ -166,6 +183,14 @@ function translateSidebar({
|
|
|
166
183
|
?.message ?? item.label,
|
|
167
184
|
};
|
|
168
185
|
}
|
|
186
|
+
if ((item.type === 'doc' || item.type === 'ref') && item.translatable) {
|
|
187
|
+
return {
|
|
188
|
+
...item,
|
|
189
|
+
label:
|
|
190
|
+
sidebarsTranslations[`sidebar.${sidebarName}.doc.${item.label!}`]
|
|
191
|
+
?.message ?? item.label,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
169
194
|
return item;
|
|
170
195
|
});
|
|
171
196
|
}
|