@docusaurus/plugin-content-docs 0.0.0-4679 → 0.0.0-4683

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.
@@ -11,9 +11,6 @@ const utils_1 = require("./sidebars/utils");
11
11
  const docs_1 = require("./docs");
12
12
  function getCategoryGeneratedIndexMetadata({ category, sidebarsUtils, docsById, }) {
13
13
  const { sidebarName, previous, next } = sidebarsUtils.getCategoryGeneratedIndexNavigation(category.link.permalink);
14
- if (!sidebarName) {
15
- throw new Error('unexpected');
16
- }
17
14
  return {
18
15
  title: category.link.title ?? category.label,
19
16
  description: category.link.description,
@@ -27,7 +27,9 @@ const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, isCategoryInde
27
27
  const getDoc = (docId) => {
28
28
  const doc = findDoc(docId);
29
29
  if (!doc) {
30
- throw new Error(`Can't find any doc with id=${docId}.\nAvailable doc ids:\n- ${Object.keys(docsById).join('\n- ')}`);
30
+ throw new Error(`Can't find any doc with ID ${docId}.
31
+ Available doc IDs:
32
+ - ${Object.keys(docsById).join('\n- ')}`);
31
33
  }
32
34
  return doc;
33
35
  };
@@ -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
  }
@@ -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;
@@ -158,10 +158,7 @@ function createSidebarsUtils(sidebars) {
158
158
  item.link?.type === 'generated-index' &&
159
159
  item.link.permalink === categoryGeneratedIndexPermalink);
160
160
  }
161
- const sidebarName = Object.entries(sidebarNameToNavigationItems).find(([, navigationItems]) => navigationItems.find(isCurrentCategoryGeneratedIndexItem))?.[0];
162
- if (!sidebarName) {
163
- return emptySidebarNavigation();
164
- }
161
+ const sidebarName = Object.entries(sidebarNameToNavigationItems).find(([, navigationItems]) => navigationItems.find(isCurrentCategoryGeneratedIndexItem))[0];
165
162
  const navigationItems = sidebarNameToNavigationItems[sidebarName];
166
163
  const currentItemIndex = navigationItems.findIndex(isCurrentCategoryGeneratedIndexItem);
167
164
  const { previous, next } = (0, utils_1.getElementsAround)(navigationItems, currentItemIndex);
@@ -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-4679",
3
+ "version": "0.0.0-4683",
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-4679",
27
- "@docusaurus/logger": "0.0.0-4679",
28
- "@docusaurus/mdx-loader": "0.0.0-4679",
29
- "@docusaurus/utils": "0.0.0-4679",
30
- "@docusaurus/utils-validation": "0.0.0-4679",
26
+ "@docusaurus/core": "0.0.0-4683",
27
+ "@docusaurus/logger": "0.0.0-4683",
28
+ "@docusaurus/mdx-loader": "0.0.0-4683",
29
+ "@docusaurus/utils": "0.0.0-4683",
30
+ "@docusaurus/utils-validation": "0.0.0-4683",
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-4679",
43
- "@docusaurus/types": "0.0.0-4679",
42
+ "@docusaurus/module-type-aliases": "0.0.0-4683",
43
+ "@docusaurus/types": "0.0.0-4683",
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": "446224a0b9b4f91bb8676d85518b5d7af0221044"
59
+ "gitHead": "57af658e8e5cf53b765ba7267a2b1c062e0bf6a1"
60
60
  }
@@ -21,10 +21,6 @@ function getCategoryGeneratedIndexMetadata({
21
21
  }): CategoryGeneratedIndexMetadata {
22
22
  const {sidebarName, previous, next} =
23
23
  sidebarsUtils.getCategoryGeneratedIndexNavigation(category.link.permalink);
24
- if (!sidebarName) {
25
- throw new Error('unexpected');
26
- }
27
-
28
24
  return {
29
25
  title: category.link.title ?? category.label,
30
26
  description: category.link.description,
@@ -32,7 +28,7 @@ function getCategoryGeneratedIndexMetadata({
32
28
  keywords: category.link.keywords,
33
29
  slug: category.link.slug,
34
30
  permalink: category.link.permalink,
35
- sidebar: sidebarName,
31
+ sidebar: sidebarName!,
36
32
  previous: toNavigationLink(previous, docsById),
37
33
  next: toNavigationLink(next, docsById),
38
34
  };
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;
@@ -60,9 +60,9 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
60
60
  const doc = findDoc(docId);
61
61
  if (!doc) {
62
62
  throw new Error(
63
- `Can't find any doc with id=${docId}.\nAvailable doc ids:\n- ${Object.keys(
64
- docsById,
65
- ).join('\n- ')}`,
63
+ `Can't find any doc with ID ${docId}.
64
+ Available doc IDs:
65
+ - ${Object.keys(docsById).join('\n- ')}`,
66
66
  );
67
67
  }
68
68
  return doc;
@@ -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
  ', ',
@@ -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;
@@ -258,12 +258,8 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
258
258
  const sidebarName = Object.entries(sidebarNameToNavigationItems).find(
259
259
  ([, navigationItems]) =>
260
260
  navigationItems.find(isCurrentCategoryGeneratedIndexItem),
261
- )?.[0];
262
-
263
- if (!sidebarName) {
264
- return emptySidebarNavigation();
265
- }
266
- const navigationItems = sidebarNameToNavigationItems[sidebarName];
261
+ )![0];
262
+ const navigationItems = sidebarNameToNavigationItems[sidebarName]!;
267
263
  const currentItemIndex = navigationItems.findIndex(
268
264
  isCurrentCategoryGeneratedIndexItem,
269
265
  );
@@ -341,7 +337,7 @@ Available document ids are:
341
337
  getCategoryGeneratedIndexList,
342
338
  getCategoryGeneratedIndexNavigation,
343
339
  checkSidebarsDocIds,
344
- getFirstLink: (id) => getFirstLink(sidebars[id]),
340
+ getFirstLink: (id) => getFirstLink(sidebars[id]!),
345
341
  };
346
342
  }
347
343
 
@@ -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(