@docusaurus/plugin-content-docs 0.0.0-4677 → 0.0.0-4680

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.
@@ -104,6 +104,7 @@ const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, isCategoryInde
104
104
  function createCategoryItem(dir, fullPath, folderName) {
105
105
  const categoryMetadata = categoriesMetadata[(0, utils_1.posixPath)(path_1.default.join(autogenDir, fullPath))];
106
106
  const className = categoryMetadata?.className;
107
+ const customProps = categoryMetadata?.customProps;
107
108
  const { filename, numberPrefix } = numberPrefixParser(folderName);
108
109
  const allItems = Object.entries(dir).map(([key, content]) => dirToItem(content, key, `${fullPath}/${key}`));
109
110
  // Try to match a doc inside the category folder,
@@ -149,6 +150,7 @@ const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, isCategoryInde
149
150
  collapsed: categoryMetadata?.collapsed,
150
151
  position: categoryMetadata?.position ?? numberPrefix,
151
152
  source: folderName,
153
+ ...(customProps !== undefined && { customProps }),
152
154
  ...(className !== undefined && { className }),
153
155
  items,
154
156
  ...(link && { link }),
@@ -43,7 +43,7 @@ async function readCategoriesMetadata(contentPath) {
43
43
  });
44
44
  const categoryToFile = lodash_1.default.groupBy(categoryFiles, path_1.default.dirname);
45
45
  return (0, combine_promises_1.default)(lodash_1.default.mapValues(categoryToFile, async (files, folder) => {
46
- const [filePath] = files;
46
+ const filePath = files[0];
47
47
  if (files.length > 1) {
48
48
  logger_1.default.warn `There are more than one category metadata files for path=${folder}: ${files.join(', ')}. The behavior is undetermined.`;
49
49
  }
@@ -138,6 +138,7 @@ export declare type CategoryMetadataFile = {
138
138
  collapsible?: boolean;
139
139
  className?: string;
140
140
  link?: SidebarItemCategoryLinkConfig | null;
141
+ customProps?: Record<string, unknown>;
141
142
  };
142
143
  export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'unversionedId' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
143
144
  export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
@@ -119,10 +119,10 @@ function createSidebarsUtils(sidebars) {
119
119
  if (!sidebarName) {
120
120
  return emptySidebarNavigation();
121
121
  }
122
- if (!sidebarNameToNavigationItems[sidebarName]) {
122
+ const navigationItems = sidebarNameToNavigationItems[sidebarName];
123
+ if (!navigationItems) {
123
124
  throw new Error(`Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`);
124
125
  }
125
- const navigationItems = sidebarNameToNavigationItems[sidebarName];
126
126
  const currentItemIndex = navigationItems.findIndex((item) => {
127
127
  if (item.type === 'doc') {
128
128
  return item.id === docId;
@@ -130,6 +130,7 @@ const categoryMetadataFileSchema = utils_validation_1.Joi.object({
130
130
  collapsible: utils_validation_1.Joi.boolean(),
131
131
  className: utils_validation_1.Joi.string(),
132
132
  link: sidebarItemCategoryLinkSchema,
133
+ customProps: utils_validation_1.Joi.object().unknown(),
133
134
  });
134
135
  function validateCategoryMetadataFile(unsafeContent) {
135
136
  return utils_validation_1.Joi.attempt(unsafeContent, categoryMetadataFileSchema);
@@ -195,10 +195,13 @@ function getVersionTranslationFiles(version) {
195
195
  ];
196
196
  }
197
197
  function translateVersion(version, translationFiles) {
198
- const versionTranslations = translationFiles[getVersionFileName(version.versionName)].content;
198
+ const versionTranslations = translationFiles[getVersionFileName(version.versionName)]?.content;
199
+ if (!versionTranslations) {
200
+ return version;
201
+ }
199
202
  return {
200
203
  ...version,
201
- versionLabel: versionTranslations['version.label']?.message,
204
+ versionLabel: versionTranslations['version.label']?.message ?? version.versionLabel,
202
205
  sidebars: translateSidebars(version, versionTranslations),
203
206
  // docs: translateDocs(version.docs, versionTranslations),
204
207
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-4677",
3
+ "version": "0.0.0-4680",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -23,11 +23,11 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
- "@docusaurus/core": "0.0.0-4677",
27
- "@docusaurus/logger": "0.0.0-4677",
28
- "@docusaurus/mdx-loader": "0.0.0-4677",
29
- "@docusaurus/utils": "0.0.0-4677",
30
- "@docusaurus/utils-validation": "0.0.0-4677",
26
+ "@docusaurus/core": "0.0.0-4680",
27
+ "@docusaurus/logger": "0.0.0-4680",
28
+ "@docusaurus/mdx-loader": "0.0.0-4680",
29
+ "@docusaurus/utils": "0.0.0-4680",
30
+ "@docusaurus/utils-validation": "0.0.0-4680",
31
31
  "combine-promises": "^1.1.0",
32
32
  "fs-extra": "^10.0.1",
33
33
  "import-fresh": "^3.3.0",
@@ -39,8 +39,8 @@
39
39
  "webpack": "^5.69.1"
40
40
  },
41
41
  "devDependencies": {
42
- "@docusaurus/module-type-aliases": "0.0.0-4677",
43
- "@docusaurus/types": "0.0.0-4677",
42
+ "@docusaurus/module-type-aliases": "0.0.0-4680",
43
+ "@docusaurus/types": "0.0.0-4680",
44
44
  "@types/js-yaml": "^4.0.5",
45
45
  "@types/picomatch": "^2.3.0",
46
46
  "commander": "^5.1.0",
@@ -56,5 +56,5 @@
56
56
  "engines": {
57
57
  "node": ">=14"
58
58
  },
59
- "gitHead": "e4f370386120aba552fb9783ac8bcea85bf7fe53"
59
+ "gitHead": "367835b86a28dea97e2addba03291438a5f813f8"
60
60
  }
package/src/docs.ts CHANGED
@@ -363,7 +363,7 @@ export function getMainDocId({
363
363
  doc.unversionedId === firstDocIdOfFirstSidebar,
364
364
  )!;
365
365
  }
366
- return docs[0];
366
+ return docs[0]!;
367
367
  }
368
368
 
369
369
  return getMainDoc().unversionedId;
@@ -159,6 +159,7 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
159
159
  const categoryMetadata =
160
160
  categoriesMetadata[posixPath(path.join(autogenDir, fullPath))];
161
161
  const className = categoryMetadata?.className;
162
+ const customProps = categoryMetadata?.customProps;
162
163
  const {filename, numberPrefix} = numberPrefixParser(folderName);
163
164
  const allItems = Object.entries(dir).map(([key, content]) =>
164
165
  dirToItem(content, key, `${fullPath}/${key}`),
@@ -219,6 +220,7 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
219
220
  collapsed: categoryMetadata?.collapsed,
220
221
  position: categoryMetadata?.position ?? numberPrefix,
221
222
  source: folderName,
223
+ ...(customProps !== undefined && {customProps}),
222
224
  ...(className !== undefined && {className}),
223
225
  items,
224
226
  ...(link && {link}),
@@ -49,7 +49,7 @@ async function readCategoriesMetadata(contentPath: string) {
49
49
  const categoryToFile = _.groupBy(categoryFiles, path.dirname);
50
50
  return combinePromises(
51
51
  _.mapValues(categoryToFile, async (files, folder) => {
52
- const [filePath] = files;
52
+ const filePath = files[0]!;
53
53
  if (files.length > 1) {
54
54
  logger.warn`There are more than one category metadata files for path=${folder}: ${files.join(
55
55
  ', ',
@@ -216,6 +216,7 @@ export type CategoryMetadataFile = {
216
216
  collapsible?: boolean;
217
217
  className?: string;
218
218
  link?: SidebarItemCategoryLinkConfig | null;
219
+ customProps?: Record<string, unknown>;
219
220
 
220
221
  // TODO should we allow "items" here? how would this work? would an
221
222
  // "autogenerated" type be allowed?
@@ -201,12 +201,12 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
201
201
  if (!sidebarName) {
202
202
  return emptySidebarNavigation();
203
203
  }
204
- if (!sidebarNameToNavigationItems[sidebarName]) {
204
+ const navigationItems = sidebarNameToNavigationItems[sidebarName];
205
+ if (!navigationItems) {
205
206
  throw new Error(
206
207
  `Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`,
207
208
  );
208
209
  }
209
- const navigationItems = sidebarNameToNavigationItems[sidebarName];
210
210
  const currentItemIndex = navigationItems.findIndex((item) => {
211
211
  if (item.type === 'doc') {
212
212
  return item.id === docId;
@@ -263,7 +263,7 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
263
263
  if (!sidebarName) {
264
264
  return emptySidebarNavigation();
265
265
  }
266
- const navigationItems = sidebarNameToNavigationItems[sidebarName];
266
+ const navigationItems = sidebarNameToNavigationItems[sidebarName]!;
267
267
  const currentItemIndex = navigationItems.findIndex(
268
268
  isCurrentCategoryGeneratedIndexItem,
269
269
  );
@@ -341,7 +341,7 @@ Available document ids are:
341
341
  getCategoryGeneratedIndexList,
342
342
  getCategoryGeneratedIndexNavigation,
343
343
  checkSidebarsDocIds,
344
- getFirstLink: (id) => getFirstLink(sidebars[id]),
344
+ getFirstLink: (id) => getFirstLink(sidebars[id]!),
345
345
  };
346
346
  }
347
347
 
@@ -164,6 +164,7 @@ const categoryMetadataFileSchema = Joi.object<CategoryMetadataFile>({
164
164
  collapsible: Joi.boolean(),
165
165
  className: Joi.string(),
166
166
  link: sidebarItemCategoryLinkSchema,
167
+ customProps: Joi.object().unknown(),
167
168
  });
168
169
 
169
170
  export function validateCategoryMetadataFile(
@@ -274,10 +274,14 @@ function translateVersion(
274
274
  translationFiles: Record<string, TranslationFile>,
275
275
  ): LoadedVersion {
276
276
  const versionTranslations =
277
- translationFiles[getVersionFileName(version.versionName)].content;
277
+ translationFiles[getVersionFileName(version.versionName)]?.content;
278
+ if (!versionTranslations) {
279
+ return version;
280
+ }
278
281
  return {
279
282
  ...version,
280
- versionLabel: versionTranslations['version.label']?.message,
283
+ versionLabel:
284
+ versionTranslations['version.label']?.message ?? version.versionLabel,
281
285
  sidebars: translateSidebars(version, versionTranslations),
282
286
  // docs: translateDocs(version.docs, versionTranslations),
283
287
  };
package/src/versions.ts CHANGED
@@ -464,11 +464,11 @@ Please set the docs "sidebarPath" field in your config file to:
464
464
  // "last version" is not a very good concept nor api surface
465
465
  function getDefaultLastVersionName(versionNames: string[]) {
466
466
  if (versionNames.length === 1) {
467
- return versionNames[0];
467
+ return versionNames[0]!;
468
468
  }
469
469
  return versionNames.filter(
470
470
  (versionName) => versionName !== CURRENT_VERSION_NAME,
471
- )[0];
471
+ )[0]!;
472
472
  }
473
473
 
474
474
  function checkVersionsOptions(