@docusaurus/plugin-content-docs 3.9.1 → 3.9.2

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.
@@ -24,6 +24,7 @@ exports.DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
24
24
  // See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
25
25
  description: utils_validation_1.JoiFrontMatter.string().allow(''),
26
26
  slug: utils_validation_1.JoiFrontMatter.string(),
27
+ sidebar_key: utils_validation_1.JoiFrontMatter.string(),
27
28
  sidebar_label: utils_validation_1.JoiFrontMatter.string(),
28
29
  sidebar_position: utils_validation_1.JoiFrontMatter.number(),
29
30
  sidebar_class_name: utils_validation_1.JoiFrontMatter.string(),
@@ -91,7 +91,7 @@ Available doc IDs:
91
91
  */
92
92
  function generateSidebar(fsModel) {
93
93
  function createDocItem(id, fullPath, fileName) {
94
- const { sidebarPosition: position, frontMatter: { sidebar_label: label, sidebar_class_name: className, sidebar_custom_props: customProps, }, } = getDoc(id);
94
+ const { sidebarPosition: position, frontMatter: { sidebar_key: key, sidebar_label: label, sidebar_class_name: className, sidebar_custom_props: customProps, }, } = getDoc(id);
95
95
  return {
96
96
  type: 'doc',
97
97
  id,
@@ -99,6 +99,7 @@ Available doc IDs:
99
99
  source: fileName,
100
100
  // We don't want these fields to magically appear in the generated
101
101
  // sidebar
102
+ ...(key !== undefined && { key }),
102
103
  ...(label !== undefined && { label }),
103
104
  ...(className !== undefined && { className }),
104
105
  ...(customProps !== undefined && { customProps }),
@@ -139,6 +140,7 @@ Available doc IDs:
139
140
  return {
140
141
  id,
141
142
  position: doc.sidebarPosition,
143
+ key: doc.frontMatter.sidebar_key,
142
144
  label: doc.frontMatter.sidebar_label ?? doc.title,
143
145
  customProps: doc.frontMatter.sidebar_custom_props,
144
146
  className: doc.frontMatter.sidebar_class_name,
@@ -156,6 +158,7 @@ Available doc IDs:
156
158
  const className = categoryMetadata?.className ?? categoryLinkedDoc?.className;
157
159
  const customProps = categoryMetadata?.customProps ?? categoryLinkedDoc?.customProps;
158
160
  const { filename, numberPrefix } = numberPrefixParser(folderName);
161
+ const key = categoryMetadata?.key ?? categoryLinkedDoc?.key;
159
162
  return {
160
163
  type: 'category',
161
164
  label: categoryMetadata?.label ?? categoryLinkedDoc?.label ?? filename,
@@ -171,7 +174,7 @@ Available doc IDs:
171
174
  ...(categoryMetadata?.description && {
172
175
  description: categoryMetadata?.description,
173
176
  }),
174
- ...(categoryMetadata?.key && { key: categoryMetadata?.key }),
177
+ ...(key && { key }),
175
178
  ...(link && { link }),
176
179
  };
177
180
  }
@@ -39,7 +39,10 @@ function ensureNoSidebarDuplicateEntries(translationEntries) {
39
39
  .join('\n\n- ')}
40
40
 
41
41
  To avoid translation key conflicts, use the ${logger_1.default.code('key')} attribute on the sidebar items above to uniquely identify them.
42
- `);
42
+
43
+ When using autogenerated sidebars, you can provide a unique translation key by adding:
44
+ - the ${logger_1.default.code('key')} attribute to category item metadata (${logger_1.default.code('_category_.json')} / ${logger_1.default.code('_category_.yml')})
45
+ - the ${logger_1.default.code('sidebar_key')} attribute to doc item metadata (front matter in ${logger_1.default.code('Category/index.mdx')})`);
43
46
  }
44
47
  }
45
48
  function getSidebarTranslationFileContent(sidebar, sidebarName) {
@@ -51,7 +54,7 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
51
54
  `sidebar.${sidebarName}.category.${categoryKey}`,
52
55
  {
53
56
  message: category.label,
54
- description: `The label for category ${category.label} in sidebar ${sidebarName}`,
57
+ description: `The label for category '${category.label}' in sidebar '${sidebarName}'`,
55
58
  },
56
59
  ]);
57
60
  if (category.link?.type === 'generated-index') {
@@ -60,7 +63,7 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
60
63
  `sidebar.${sidebarName}.category.${categoryKey}.link.generated-index.title`,
61
64
  {
62
65
  message: category.link.title,
63
- description: `The generated-index page title for category ${category.label} in sidebar ${sidebarName}`,
66
+ description: `The generated-index page title for category '${category.label}' in sidebar '${sidebarName}'`,
64
67
  },
65
68
  ]);
66
69
  }
@@ -69,7 +72,7 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
69
72
  `sidebar.${sidebarName}.category.${categoryKey}.link.generated-index.description`,
70
73
  {
71
74
  message: category.link.description,
72
- description: `The generated-index page description for category ${category.label} in sidebar ${sidebarName}`,
75
+ description: `The generated-index page description for category '${category.label}' in sidebar '${sidebarName}'`,
73
76
  },
74
77
  ]);
75
78
  }
@@ -83,7 +86,7 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
83
86
  `sidebar.${sidebarName}.link.${linkKey}`,
84
87
  {
85
88
  message: link.label,
86
- description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
89
+ description: `The label for link '${link.label}' in sidebar '${sidebarName}', linking to '${link.href}'`,
87
90
  },
88
91
  ];
89
92
  });
@@ -96,7 +99,7 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
96
99
  `sidebar.${sidebarName}.doc.${docKey}`,
97
100
  {
98
101
  message: doc.label,
99
- description: `The label for the doc item ${doc.label} in sidebar ${sidebarName}, linking to the doc ${doc.id}`,
102
+ description: `The label for the doc item '${doc.label}' in sidebar '${sidebarName}', linking to the doc ${doc.id}`,
100
103
  },
101
104
  ];
102
105
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "3.9.1",
3
+ "version": "3.9.2",
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.1",
39
- "@docusaurus/logger": "3.9.1",
40
- "@docusaurus/mdx-loader": "3.9.1",
41
- "@docusaurus/module-type-aliases": "3.9.1",
42
- "@docusaurus/theme-common": "3.9.1",
43
- "@docusaurus/types": "3.9.1",
44
- "@docusaurus/utils": "3.9.1",
45
- "@docusaurus/utils-common": "3.9.1",
46
- "@docusaurus/utils-validation": "3.9.1",
38
+ "@docusaurus/core": "3.9.2",
39
+ "@docusaurus/logger": "3.9.2",
40
+ "@docusaurus/mdx-loader": "3.9.2",
41
+ "@docusaurus/module-type-aliases": "3.9.2",
42
+ "@docusaurus/theme-common": "3.9.2",
43
+ "@docusaurus/types": "3.9.2",
44
+ "@docusaurus/utils": "3.9.2",
45
+ "@docusaurus/utils-common": "3.9.2",
46
+ "@docusaurus/utils-validation": "3.9.2",
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": "c0dd59f0e712f85b6053c59e46b0514b5d2d1414"
70
+ "gitHead": "abfbe5621b08407bc3dcbe6111ff118d4c22f7a1"
71
71
  }
@@ -30,6 +30,7 @@ export const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
30
30
  // See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
31
31
  description: Joi.string().allow(''),
32
32
  slug: Joi.string(),
33
+ sidebar_key: Joi.string(),
33
34
  sidebar_label: Joi.string(),
34
35
  sidebar_position: Joi.number(),
35
36
  sidebar_class_name: Joi.string(),
@@ -339,7 +339,15 @@ declare module '@docusaurus/plugin-content-docs' {
339
339
  * @see {@link DocMetadata.slug}
340
340
  */
341
341
  slug?: string;
342
- /** Customizes the sidebar label for this doc. Will default to its title. */
342
+ /**
343
+ * Customizes the sidebar key for this doc,
344
+ * to uniquely identify it in translations.
345
+ */
346
+ sidebar_key?: string;
347
+ /**
348
+ * Customizes the sidebar label for this doc.
349
+ * Will default to its title.
350
+ */
343
351
  sidebar_label?: string;
344
352
  /**
345
353
  * Controls the position of a doc inside the generated sidebar slice when
@@ -139,6 +139,7 @@ Available doc IDs:
139
139
  const {
140
140
  sidebarPosition: position,
141
141
  frontMatter: {
142
+ sidebar_key: key,
142
143
  sidebar_label: label,
143
144
  sidebar_class_name: className,
144
145
  sidebar_custom_props: customProps,
@@ -151,6 +152,7 @@ Available doc IDs:
151
152
  source: fileName,
152
153
  // We don't want these fields to magically appear in the generated
153
154
  // sidebar
155
+ ...(key !== undefined && {key}),
154
156
  ...(label !== undefined && {label}),
155
157
  ...(className !== undefined && {className}),
156
158
  ...(customProps !== undefined && {customProps}),
@@ -191,6 +193,7 @@ Available doc IDs:
191
193
  function getCategoryLinkedDocMetadata():
192
194
  | {
193
195
  id: string;
196
+ key?: string;
194
197
  position?: number;
195
198
  label?: string;
196
199
  customProps?: {[key: string]: unknown};
@@ -212,6 +215,7 @@ Available doc IDs:
212
215
  return {
213
216
  id,
214
217
  position: doc.sidebarPosition,
218
+ key: doc.frontMatter.sidebar_key,
215
219
  label: doc.frontMatter.sidebar_label ?? doc.title,
216
220
  customProps: doc.frontMatter.sidebar_custom_props,
217
221
  className: doc.frontMatter.sidebar_class_name,
@@ -236,6 +240,8 @@ Available doc IDs:
236
240
  categoryMetadata?.customProps ?? categoryLinkedDoc?.customProps;
237
241
  const {filename, numberPrefix} = numberPrefixParser(folderName);
238
242
 
243
+ const key = categoryMetadata?.key ?? categoryLinkedDoc?.key;
244
+
239
245
  return {
240
246
  type: 'category',
241
247
  label: categoryMetadata?.label ?? categoryLinkedDoc?.label ?? filename,
@@ -252,7 +258,7 @@ Available doc IDs:
252
258
  ...(categoryMetadata?.description && {
253
259
  description: categoryMetadata?.description,
254
260
  }),
255
- ...(categoryMetadata?.key && {key: categoryMetadata?.key}),
261
+ ...(key && {key}),
256
262
  ...(link && {link}),
257
263
  };
258
264
  }
@@ -71,7 +71,16 @@ function ensureNoSidebarDuplicateEntries(
71
71
  To avoid translation key conflicts, use the ${logger.code(
72
72
  'key',
73
73
  )} attribute on the sidebar items above to uniquely identify them.
74
- `);
74
+
75
+ When using autogenerated sidebars, you can provide a unique translation key by adding:
76
+ - the ${logger.code('key')} attribute to category item metadata (${logger.code(
77
+ '_category_.json',
78
+ )} / ${logger.code('_category_.yml')})
79
+ - the ${logger.code(
80
+ 'sidebar_key',
81
+ )} attribute to doc item metadata (front matter in ${logger.code(
82
+ 'Category/index.mdx',
83
+ )})`);
75
84
  }
76
85
  }
77
86
 
@@ -90,7 +99,7 @@ function getSidebarTranslationFileContent(
90
99
  `sidebar.${sidebarName}.category.${categoryKey}`,
91
100
  {
92
101
  message: category.label,
93
- description: `The label for category ${category.label} in sidebar ${sidebarName}`,
102
+ description: `The label for category '${category.label}' in sidebar '${sidebarName}'`,
94
103
  },
95
104
  ]);
96
105
 
@@ -100,7 +109,7 @@ function getSidebarTranslationFileContent(
100
109
  `sidebar.${sidebarName}.category.${categoryKey}.link.generated-index.title`,
101
110
  {
102
111
  message: category.link.title,
103
- description: `The generated-index page title for category ${category.label} in sidebar ${sidebarName}`,
112
+ description: `The generated-index page title for category '${category.label}' in sidebar '${sidebarName}'`,
104
113
  },
105
114
  ]);
106
115
  }
@@ -109,7 +118,7 @@ function getSidebarTranslationFileContent(
109
118
  `sidebar.${sidebarName}.category.${categoryKey}.link.generated-index.description`,
110
119
  {
111
120
  message: category.link.description,
112
- description: `The generated-index page description for category ${category.label} in sidebar ${sidebarName}`,
121
+ description: `The generated-index page description for category '${category.label}' in sidebar '${sidebarName}'`,
113
122
  },
114
123
  ]);
115
124
  }
@@ -126,7 +135,7 @@ function getSidebarTranslationFileContent(
126
135
  `sidebar.${sidebarName}.link.${linkKey}`,
127
136
  {
128
137
  message: link.label,
129
- description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
138
+ description: `The label for link '${link.label}' in sidebar '${sidebarName}', linking to '${link.href}'`,
130
139
  },
131
140
  ];
132
141
  });
@@ -140,7 +149,7 @@ function getSidebarTranslationFileContent(
140
149
  `sidebar.${sidebarName}.doc.${docKey}`,
141
150
  {
142
151
  message: doc.label!,
143
- description: `The label for the doc item ${doc.label!} in sidebar ${sidebarName}, linking to the doc ${
152
+ description: `The label for the doc item '${doc.label!}' in sidebar '${sidebarName}', linking to the doc ${
144
153
  doc.id
145
154
  }`,
146
155
  },