@docusaurus/plugin-content-docs 3.9.1-canary-6425 → 3.9.2-alpha.0
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/client/docsUtils.js +12 -5
- package/lib/docs.js +2 -2
- package/lib/index.js +1 -1
- package/lib/translations.js +43 -3
- package/package.json +11 -11
- package/src/client/docsUtils.tsx +14 -7
- package/src/docs.ts +2 -0
- package/src/index.ts +1 -2
- package/src/translations.ts +52 -3
package/lib/client/docsUtils.js
CHANGED
|
@@ -148,11 +148,18 @@ function getSidebarBreadcrumbs({ sidebarItems, pathname, onlyCategories = false,
|
|
|
148
148
|
const breadcrumbs = [];
|
|
149
149
|
function extract(items) {
|
|
150
150
|
for (const item of items) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
(
|
|
154
|
-
|
|
155
|
-
|
|
151
|
+
// Extract category item
|
|
152
|
+
if (item.type === 'category') {
|
|
153
|
+
if (isSamePath(item.href, pathname) || extract(item.items)) {
|
|
154
|
+
breadcrumbs.unshift(item);
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// Extract doc item
|
|
159
|
+
else if (item.type === 'link' &&
|
|
160
|
+
item.docId &&
|
|
161
|
+
isSamePath(item.href, pathname)) {
|
|
162
|
+
if (!onlyCategories) {
|
|
156
163
|
breadcrumbs.unshift(item);
|
|
157
164
|
}
|
|
158
165
|
return true;
|
package/lib/docs.js
CHANGED
|
@@ -38,7 +38,7 @@ async function readVersionDocs(versionMetadata, options) {
|
|
|
38
38
|
}
|
|
39
39
|
async function doProcessDocMetadata({ docFile, versionMetadata, context, options, env, tagsFile, }) {
|
|
40
40
|
const { source, content, contentPath, filePath } = docFile;
|
|
41
|
-
const { siteDir, siteConfig: { markdown: { parseFrontMatter }, }, } = context;
|
|
41
|
+
const { siteDir, siteConfig: { markdown: { parseFrontMatter }, future: { experimental_vcs: vcs }, }, } = context;
|
|
42
42
|
const { frontMatter: unsafeFrontMatter, contentTitle, excerpt, } = await (0, utils_1.parseMarkdownFile)({
|
|
43
43
|
filePath,
|
|
44
44
|
fileContent: content,
|
|
@@ -50,7 +50,7 @@ async function doProcessDocMetadata({ docFile, versionMetadata, context, options
|
|
|
50
50
|
// (01-MyFolder/01-MyDoc.md => MyFolder/MyDoc)
|
|
51
51
|
// but allow to disable this behavior with front matter
|
|
52
52
|
parse_number_prefixes: parseNumberPrefixes = true, last_update: lastUpdateFrontMatter, } = frontMatter;
|
|
53
|
-
const lastUpdate = await (0, utils_1.readLastUpdateData)(filePath, options, lastUpdateFrontMatter);
|
|
53
|
+
const lastUpdate = await (0, utils_1.readLastUpdateData)(filePath, options, lastUpdateFrontMatter, vcs);
|
|
54
54
|
// E.g. api/plugins/myDoc -> myDoc; myDoc -> myDoc
|
|
55
55
|
const sourceFileNameWithoutExtension = path_1.default.basename(source, path_1.default.extname(source));
|
|
56
56
|
// E.g. api/plugins/myDoc -> api/plugins; myDoc -> .
|
package/lib/index.js
CHANGED
|
@@ -75,7 +75,7 @@ async function pluginContentDocs(context, options) {
|
|
|
75
75
|
versionsMetadata,
|
|
76
76
|
}),
|
|
77
77
|
].filter((d) => typeof d === 'string'),
|
|
78
|
-
useCrossCompilerCache: siteConfig.future.
|
|
78
|
+
useCrossCompilerCache: siteConfig.future.faster.mdxCrossCompilerCache,
|
|
79
79
|
admonitions: options.admonitions,
|
|
80
80
|
remarkPlugins,
|
|
81
81
|
rehypePlugins,
|
package/lib/translations.js
CHANGED
|
@@ -113,8 +113,9 @@ function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
|
113
113
|
return undefined;
|
|
114
114
|
}
|
|
115
115
|
if (category.link.type === 'generated-index') {
|
|
116
|
-
const
|
|
117
|
-
const
|
|
116
|
+
const categoryKey = category.key ?? category.label;
|
|
117
|
+
const title = sidebarsTranslations[`sidebar.${sidebarName}.category.${categoryKey}.link.generated-index.title`]?.message ?? category.link.title;
|
|
118
|
+
const description = sidebarsTranslations[`sidebar.${sidebarName}.category.${categoryKey}.link.generated-index.description`]?.message ?? category.link.description;
|
|
118
119
|
return {
|
|
119
120
|
...category.link,
|
|
120
121
|
title,
|
|
@@ -178,12 +179,51 @@ function getVersionTranslationFiles(version) {
|
|
|
178
179
|
},
|
|
179
180
|
];
|
|
180
181
|
}
|
|
182
|
+
// TODO Docusaurus v4 or later
|
|
183
|
+
// this temporarily works, but it is not an ideal solution
|
|
184
|
+
// The docs navigation can be computed and shouldn't be part of LoadedVersion
|
|
185
|
+
// We need to derive the navigation from already translated content
|
|
186
|
+
// See https://github.com/facebook/docusaurus/pull/11794
|
|
187
|
+
function translateDocNavigation(docs, translatedSidebars) {
|
|
188
|
+
// Build a map of permalink -> translated label for generated-index categories
|
|
189
|
+
const translatedLabelByPermalink = new Map();
|
|
190
|
+
for (const sidebar of Object.values(translatedSidebars)) {
|
|
191
|
+
for (const category of (0, utils_2.collectSidebarCategories)(sidebar)) {
|
|
192
|
+
if (category.link?.type === 'generated-index') {
|
|
193
|
+
translatedLabelByPermalink.set(category.link.permalink, category.label);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (translatedLabelByPermalink.size === 0) {
|
|
198
|
+
return docs;
|
|
199
|
+
}
|
|
200
|
+
return docs.map((doc) => {
|
|
201
|
+
const previous = doc.previous && translatedLabelByPermalink.has(doc.previous.permalink)
|
|
202
|
+
? {
|
|
203
|
+
...doc.previous,
|
|
204
|
+
title: translatedLabelByPermalink.get(doc.previous.permalink),
|
|
205
|
+
}
|
|
206
|
+
: doc.previous;
|
|
207
|
+
const next = doc.next && translatedLabelByPermalink.has(doc.next.permalink)
|
|
208
|
+
? {
|
|
209
|
+
...doc.next,
|
|
210
|
+
title: translatedLabelByPermalink.get(doc.next.permalink),
|
|
211
|
+
}
|
|
212
|
+
: doc.next;
|
|
213
|
+
if (previous === doc.previous && next === doc.next) {
|
|
214
|
+
return doc;
|
|
215
|
+
}
|
|
216
|
+
return { ...doc, previous, next };
|
|
217
|
+
});
|
|
218
|
+
}
|
|
181
219
|
function translateVersion(version, translationFiles) {
|
|
182
220
|
const versionTranslations = translationFiles[getVersionFileName(version.versionName)].content;
|
|
221
|
+
const translatedSidebars = translateSidebars(version, versionTranslations);
|
|
183
222
|
return {
|
|
184
223
|
...version,
|
|
185
224
|
label: versionTranslations['version.label']?.message ?? version.label,
|
|
186
|
-
sidebars:
|
|
225
|
+
sidebars: translatedSidebars,
|
|
226
|
+
docs: translateDocNavigation(version.docs, translatedSidebars),
|
|
187
227
|
};
|
|
188
228
|
}
|
|
189
229
|
function getVersionsTranslationFiles(versions) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "3.9.
|
|
3
|
+
"version": "3.9.2-alpha.0",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
},
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@docusaurus/core": "3.9.
|
|
39
|
-
"@docusaurus/logger": "3.9.
|
|
40
|
-
"@docusaurus/mdx-loader": "3.9.
|
|
41
|
-
"@docusaurus/module-type-aliases": "3.9.
|
|
42
|
-
"@docusaurus/theme-common": "3.9.
|
|
43
|
-
"@docusaurus/types": "3.9.
|
|
44
|
-
"@docusaurus/utils": "3.9.
|
|
45
|
-
"@docusaurus/utils-common": "3.9.
|
|
46
|
-
"@docusaurus/utils-validation": "3.9.
|
|
38
|
+
"@docusaurus/core": "3.9.2-alpha.0",
|
|
39
|
+
"@docusaurus/logger": "3.9.2-alpha.0",
|
|
40
|
+
"@docusaurus/mdx-loader": "3.9.2-alpha.0",
|
|
41
|
+
"@docusaurus/module-type-aliases": "3.9.2-alpha.0",
|
|
42
|
+
"@docusaurus/theme-common": "3.9.2-alpha.0",
|
|
43
|
+
"@docusaurus/types": "3.9.2-alpha.0",
|
|
44
|
+
"@docusaurus/utils": "3.9.2-alpha.0",
|
|
45
|
+
"@docusaurus/utils-common": "3.9.2-alpha.0",
|
|
46
|
+
"@docusaurus/utils-validation": "3.9.2-alpha.0",
|
|
47
47
|
"@types/react-router-config": "^5.0.7",
|
|
48
48
|
"combine-promises": "^1.1.0",
|
|
49
49
|
"fs-extra": "^11.1.1",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"engines": {
|
|
68
68
|
"node": ">=20.0"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "27626cdd7a102277935f10cc4d8d3f93e211eafe"
|
|
71
71
|
}
|
package/src/client/docsUtils.tsx
CHANGED
|
@@ -234,15 +234,22 @@ function getSidebarBreadcrumbs({
|
|
|
234
234
|
}): PropSidebarBreadcrumbsItem[] {
|
|
235
235
|
const breadcrumbs: PropSidebarBreadcrumbsItem[] = [];
|
|
236
236
|
|
|
237
|
-
function extract(items: PropSidebarItem[]) {
|
|
237
|
+
function extract(items: PropSidebarItem[]): boolean {
|
|
238
238
|
for (const item of items) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
239
|
+
// Extract category item
|
|
240
|
+
if (item.type === 'category') {
|
|
241
|
+
if (isSamePath(item.href, pathname) || extract(item.items)) {
|
|
242
|
+
breadcrumbs.unshift(item);
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
// Extract doc item
|
|
247
|
+
else if (
|
|
248
|
+
item.type === 'link' &&
|
|
249
|
+
item.docId &&
|
|
250
|
+
isSamePath(item.href, pathname)
|
|
243
251
|
) {
|
|
244
|
-
|
|
245
|
-
if (!filtered) {
|
|
252
|
+
if (!onlyCategories) {
|
|
246
253
|
breadcrumbs.unshift(item);
|
|
247
254
|
}
|
|
248
255
|
return true;
|
package/src/docs.ts
CHANGED
|
@@ -97,6 +97,7 @@ async function doProcessDocMetadata({
|
|
|
97
97
|
siteDir,
|
|
98
98
|
siteConfig: {
|
|
99
99
|
markdown: {parseFrontMatter},
|
|
100
|
+
future: {experimental_vcs: vcs},
|
|
100
101
|
},
|
|
101
102
|
} = context;
|
|
102
103
|
|
|
@@ -125,6 +126,7 @@ async function doProcessDocMetadata({
|
|
|
125
126
|
filePath,
|
|
126
127
|
options,
|
|
127
128
|
lastUpdateFrontMatter,
|
|
129
|
+
vcs,
|
|
128
130
|
);
|
|
129
131
|
|
|
130
132
|
// E.g. api/plugins/myDoc -> myDoc; myDoc -> myDoc
|
package/src/index.ts
CHANGED
|
@@ -131,8 +131,7 @@ export default async function pluginContentDocs(
|
|
|
131
131
|
}),
|
|
132
132
|
].filter((d): d is string => typeof d === 'string'),
|
|
133
133
|
|
|
134
|
-
useCrossCompilerCache:
|
|
135
|
-
siteConfig.future.experimental_faster.mdxCrossCompilerCache,
|
|
134
|
+
useCrossCompilerCache: siteConfig.future.faster.mdxCrossCompilerCache,
|
|
136
135
|
admonitions: options.admonitions,
|
|
137
136
|
remarkPlugins,
|
|
138
137
|
rehypePlugins,
|
package/src/translations.ts
CHANGED
|
@@ -177,13 +177,14 @@ function translateSidebar({
|
|
|
177
177
|
return undefined;
|
|
178
178
|
}
|
|
179
179
|
if (category.link.type === 'generated-index') {
|
|
180
|
+
const categoryKey = category.key ?? category.label;
|
|
180
181
|
const title =
|
|
181
182
|
sidebarsTranslations[
|
|
182
|
-
`sidebar.${sidebarName}.category.${
|
|
183
|
+
`sidebar.${sidebarName}.category.${categoryKey}.link.generated-index.title`
|
|
183
184
|
]?.message ?? category.link.title;
|
|
184
185
|
const description =
|
|
185
186
|
sidebarsTranslations[
|
|
186
|
-
`sidebar.${sidebarName}.category.${
|
|
187
|
+
`sidebar.${sidebarName}.category.${categoryKey}.link.generated-index.description`
|
|
187
188
|
]?.message ?? category.link.description;
|
|
188
189
|
return {
|
|
189
190
|
...category.link,
|
|
@@ -268,16 +269,64 @@ function getVersionTranslationFiles(version: LoadedVersion): TranslationFile[] {
|
|
|
268
269
|
},
|
|
269
270
|
];
|
|
270
271
|
}
|
|
272
|
+
|
|
273
|
+
// TODO Docusaurus v4 or later
|
|
274
|
+
// this temporarily works, but it is not an ideal solution
|
|
275
|
+
// The docs navigation can be computed and shouldn't be part of LoadedVersion
|
|
276
|
+
// We need to derive the navigation from already translated content
|
|
277
|
+
// See https://github.com/facebook/docusaurus/pull/11794
|
|
278
|
+
function translateDocNavigation(
|
|
279
|
+
docs: LoadedVersion['docs'],
|
|
280
|
+
translatedSidebars: Sidebars,
|
|
281
|
+
): LoadedVersion['docs'] {
|
|
282
|
+
// Build a map of permalink -> translated label for generated-index categories
|
|
283
|
+
const translatedLabelByPermalink = new Map<string, string>();
|
|
284
|
+
for (const sidebar of Object.values(translatedSidebars)) {
|
|
285
|
+
for (const category of collectSidebarCategories(sidebar)) {
|
|
286
|
+
if (category.link?.type === 'generated-index') {
|
|
287
|
+
translatedLabelByPermalink.set(category.link.permalink, category.label);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (translatedLabelByPermalink.size === 0) {
|
|
293
|
+
return docs;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return docs.map((doc) => {
|
|
297
|
+
const previous =
|
|
298
|
+
doc.previous && translatedLabelByPermalink.has(doc.previous.permalink)
|
|
299
|
+
? {
|
|
300
|
+
...doc.previous,
|
|
301
|
+
title: translatedLabelByPermalink.get(doc.previous.permalink)!,
|
|
302
|
+
}
|
|
303
|
+
: doc.previous;
|
|
304
|
+
const next =
|
|
305
|
+
doc.next && translatedLabelByPermalink.has(doc.next.permalink)
|
|
306
|
+
? {
|
|
307
|
+
...doc.next,
|
|
308
|
+
title: translatedLabelByPermalink.get(doc.next.permalink)!,
|
|
309
|
+
}
|
|
310
|
+
: doc.next;
|
|
311
|
+
if (previous === doc.previous && next === doc.next) {
|
|
312
|
+
return doc;
|
|
313
|
+
}
|
|
314
|
+
return {...doc, previous, next};
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
271
318
|
function translateVersion(
|
|
272
319
|
version: LoadedVersion,
|
|
273
320
|
translationFiles: {[fileName: string]: TranslationFile},
|
|
274
321
|
): LoadedVersion {
|
|
275
322
|
const versionTranslations =
|
|
276
323
|
translationFiles[getVersionFileName(version.versionName)]!.content;
|
|
324
|
+
const translatedSidebars = translateSidebars(version, versionTranslations);
|
|
277
325
|
return {
|
|
278
326
|
...version,
|
|
279
327
|
label: versionTranslations['version.label']?.message ?? version.label,
|
|
280
|
-
sidebars:
|
|
328
|
+
sidebars: translatedSidebars,
|
|
329
|
+
docs: translateDocNavigation(version.docs, translatedSidebars),
|
|
281
330
|
};
|
|
282
331
|
}
|
|
283
332
|
|