@docusaurus/plugin-content-docs 2.0.0-beta.21 → 2.0.0-beta.22
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/cli.js +3 -4
- package/lib/client/index.d.ts +60 -1
- package/lib/client/index.js +8 -0
- package/lib/docs.d.ts +2 -4
- package/lib/docs.js +43 -21
- package/lib/frontMatter.js +10 -0
- package/lib/index.js +3 -7
- package/lib/lastUpdate.d.ts +1 -1
- package/lib/options.js +2 -10
- 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/lib/types.d.ts +1 -2
- package/lib/versions/files.d.ts +2 -3
- package/lib/versions/files.js +3 -5
- package/lib/versions/index.js +1 -2
- package/package.json +24 -15
- package/src/cli.ts +7 -4
- package/src/client/index.ts +60 -8
- package/src/docs.ts +57 -22
- package/src/frontMatter.ts +12 -0
- package/src/index.ts +6 -10
- package/src/lastUpdate.ts +1 -1
- package/src/options.ts +2 -11
- package/src/plugin-content-docs.d.ts +20 -97
- 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/src/types.ts +0 -2
- package/src/versions/files.ts +4 -8
- package/src/versions/index.ts +1 -2
- package/src/deps.d.ts +0 -13
|
@@ -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
|
}
|
package/src/types.ts
CHANGED
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
import type {BrokenMarkdownLink, Tag} from '@docusaurus/utils';
|
|
9
9
|
import type {
|
|
10
10
|
VersionMetadata,
|
|
11
|
-
LastUpdateData,
|
|
12
11
|
LoadedVersion,
|
|
13
12
|
CategoryGeneratedIndexMetadata,
|
|
14
13
|
} from '@docusaurus/plugin-content-docs';
|
|
@@ -19,7 +18,6 @@ export type DocFile = {
|
|
|
19
18
|
filePath: string; // /!\ may be localized
|
|
20
19
|
source: string;
|
|
21
20
|
content: string;
|
|
22
|
-
lastUpdate: LastUpdateData;
|
|
23
21
|
};
|
|
24
22
|
|
|
25
23
|
export type SourceToPermalink = {
|
package/src/versions/files.ts
CHANGED
|
@@ -55,19 +55,16 @@ export function getVersionSidebarsPath(
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export function getDocsDirPathLocalized({
|
|
58
|
-
|
|
59
|
-
locale,
|
|
58
|
+
localizationDir,
|
|
60
59
|
pluginId,
|
|
61
60
|
versionName,
|
|
62
61
|
}: {
|
|
63
|
-
|
|
64
|
-
locale: string;
|
|
62
|
+
localizationDir: string;
|
|
65
63
|
pluginId: string;
|
|
66
64
|
versionName: string;
|
|
67
65
|
}): string {
|
|
68
66
|
return getPluginI18nPath({
|
|
69
|
-
|
|
70
|
-
locale,
|
|
67
|
+
localizationDir,
|
|
71
68
|
pluginName: 'docusaurus-plugin-content-docs',
|
|
72
69
|
pluginId,
|
|
73
70
|
subPaths: [
|
|
@@ -175,8 +172,7 @@ export async function getVersionMetadataPaths({
|
|
|
175
172
|
> {
|
|
176
173
|
const isCurrent = versionName === CURRENT_VERSION_NAME;
|
|
177
174
|
const contentPathLocalized = getDocsDirPathLocalized({
|
|
178
|
-
|
|
179
|
-
locale: context.i18n.currentLocale,
|
|
175
|
+
localizationDir: context.localizationDir,
|
|
180
176
|
pluginId: options.id,
|
|
181
177
|
versionName,
|
|
182
178
|
});
|
package/src/versions/index.ts
CHANGED
|
@@ -49,8 +49,7 @@ function getVersionEditUrls({
|
|
|
49
49
|
const editDirPath = options.editCurrentVersion ? options.path : contentPath;
|
|
50
50
|
const editDirPathLocalized = options.editCurrentVersion
|
|
51
51
|
? getDocsDirPathLocalized({
|
|
52
|
-
|
|
53
|
-
locale: context.i18n.currentLocale,
|
|
52
|
+
localizationDir: context.localizationDir,
|
|
54
53
|
versionName: CURRENT_VERSION_NAME,
|
|
55
54
|
pluginId: options.id,
|
|
56
55
|
})
|
package/src/deps.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
declare module 'remark-admonitions' {
|
|
9
|
-
type Options = {[key: string]: unknown};
|
|
10
|
-
|
|
11
|
-
const plugin: (options?: Options) => void;
|
|
12
|
-
export = plugin;
|
|
13
|
-
}
|