@docusaurus/plugin-content-docs 3.9.2-canary-6526 → 3.9.2-canary-6541

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/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.experimental_faster.mdxCrossCompilerCache,
78
+ useCrossCompilerCache: siteConfig.future.faster.mdxCrossCompilerCache,
79
79
  admonitions: options.admonitions,
80
80
  remarkPlugins,
81
81
  rehypePlugins,
@@ -179,12 +179,51 @@ function getVersionTranslationFiles(version) {
179
179
  },
180
180
  ];
181
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
+ }
182
219
  function translateVersion(version, translationFiles) {
183
220
  const versionTranslations = translationFiles[getVersionFileName(version.versionName)].content;
221
+ const translatedSidebars = translateSidebars(version, versionTranslations);
184
222
  return {
185
223
  ...version,
186
224
  label: versionTranslations['version.label']?.message ?? version.label,
187
- sidebars: translateSidebars(version, versionTranslations),
225
+ sidebars: translatedSidebars,
226
+ docs: translateDocNavigation(version.docs, translatedSidebars),
188
227
  };
189
228
  }
190
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.2-canary-6526",
3
+ "version": "3.9.2-canary-6541",
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.2-canary-6526",
39
- "@docusaurus/logger": "3.9.2-canary-6526",
40
- "@docusaurus/mdx-loader": "3.9.2-canary-6526",
41
- "@docusaurus/module-type-aliases": "3.9.2-canary-6526",
42
- "@docusaurus/theme-common": "3.9.2-canary-6526",
43
- "@docusaurus/types": "3.9.2-canary-6526",
44
- "@docusaurus/utils": "3.9.2-canary-6526",
45
- "@docusaurus/utils-common": "3.9.2-canary-6526",
46
- "@docusaurus/utils-validation": "3.9.2-canary-6526",
38
+ "@docusaurus/core": "3.9.2-canary-6541",
39
+ "@docusaurus/logger": "3.9.2-canary-6541",
40
+ "@docusaurus/mdx-loader": "3.9.2-canary-6541",
41
+ "@docusaurus/module-type-aliases": "3.9.2-canary-6541",
42
+ "@docusaurus/theme-common": "3.9.2-canary-6541",
43
+ "@docusaurus/types": "3.9.2-canary-6541",
44
+ "@docusaurus/utils": "3.9.2-canary-6541",
45
+ "@docusaurus/utils-common": "3.9.2-canary-6541",
46
+ "@docusaurus/utils-validation": "3.9.2-canary-6541",
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": "a37ae138931cb80b31664f86a34f97671c00e409"
70
+ "gitHead": "60ac4995b8bfb7a1b649eb7c7ae6e812222438c5"
71
71
  }
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,
@@ -269,16 +269,64 @@ function getVersionTranslationFiles(version: LoadedVersion): TranslationFile[] {
269
269
  },
270
270
  ];
271
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
+
272
318
  function translateVersion(
273
319
  version: LoadedVersion,
274
320
  translationFiles: {[fileName: string]: TranslationFile},
275
321
  ): LoadedVersion {
276
322
  const versionTranslations =
277
323
  translationFiles[getVersionFileName(version.versionName)]!.content;
324
+ const translatedSidebars = translateSidebars(version, versionTranslations);
278
325
  return {
279
326
  ...version,
280
327
  label: versionTranslations['version.label']?.message ?? version.label,
281
- sidebars: translateSidebars(version, versionTranslations),
328
+ sidebars: translatedSidebars,
329
+ docs: translateDocNavigation(version.docs, translatedSidebars),
282
330
  };
283
331
  }
284
332