@docusaurus/plugin-content-docs 0.0.0-4619 → 0.0.0-4622

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.
@@ -10,6 +10,7 @@ exports.normalizeSidebars = exports.normalizeItem = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const utils_1 = require("./utils");
12
12
  const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
13
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
13
14
  function normalizeCategoriesShorthand(sidebar) {
14
15
  return Object.entries(sidebar).map(([label, items]) => ({
15
16
  type: 'category',
@@ -23,38 +24,32 @@ function normalizeCategoriesShorthand(sidebar) {
23
24
  */
24
25
  function normalizeItem(item) {
25
26
  if (typeof item === 'string') {
26
- return [
27
- {
28
- type: 'doc',
29
- id: item,
30
- },
31
- ];
27
+ return [{ type: 'doc', id: item }];
32
28
  }
33
29
  if ((0, utils_1.isCategoriesShorthand)(item)) {
34
- return normalizeCategoriesShorthand(item).flatMap((subItem) => normalizeItem(subItem));
30
+ // This will never throw anyways
31
+ return normalizeSidebar(item, 'sidebar items slice');
35
32
  }
36
33
  if (item.type === 'category') {
37
- if (typeof item.items !== 'undefined' && typeof item.items !== 'object') {
38
- throw new Error(`Invalid category ${JSON.stringify(item)}: items must be an array of sidebar items or a category shorthand`);
39
- }
40
34
  const normalizedCategory = {
41
35
  ...item,
42
- items: Array.isArray(item.items)
43
- ? item.items.flatMap((subItem) => normalizeItem(subItem))
44
- : normalizeCategoriesShorthand(item.items).flatMap((subItem) => normalizeItem(subItem)),
36
+ items: normalizeSidebar(item.items, logger_1.default.interpolate `code=${'items'} of the category name=${item.label}`),
45
37
  };
46
38
  return [normalizedCategory];
47
39
  }
48
40
  return [item];
49
41
  }
50
42
  exports.normalizeItem = normalizeItem;
51
- function normalizeSidebar(sidebar) {
43
+ function normalizeSidebar(sidebar, place) {
44
+ if (!Array.isArray(sidebar) && !(0, utils_1.isCategoriesShorthand)(sidebar)) {
45
+ throw new Error(logger_1.default.interpolate `Invalid sidebar items collection code=${JSON.stringify(sidebar)} in ${place}: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a code=${'type'} property). See path=${'https://docusaurus.io/docs/sidebar/items'} for all valid syntaxes.`);
46
+ }
52
47
  const normalizedSidebar = Array.isArray(sidebar)
53
48
  ? sidebar
54
49
  : normalizeCategoriesShorthand(sidebar);
55
50
  return normalizedSidebar.flatMap((subItem) => normalizeItem(subItem));
56
51
  }
57
52
  function normalizeSidebars(sidebars) {
58
- return lodash_1.default.mapValues(sidebars, normalizeSidebar);
53
+ return lodash_1.default.mapValues(sidebars, (sidebar, id) => normalizeSidebar(sidebar, logger_1.default.interpolate `sidebar name=${id}`));
59
54
  }
60
55
  exports.normalizeSidebars = normalizeSidebars;
@@ -11,7 +11,7 @@ const tslib_1 = require("tslib");
11
11
  const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
12
12
  const utils_1 = require("@docusaurus/utils");
13
13
  function isCategoriesShorthand(item) {
14
- return typeof item !== 'string' && !item.type;
14
+ return typeof item === 'object' && !item.type;
15
15
  }
16
16
  exports.isCategoriesShorthand = isCategoriesShorthand;
17
17
  function transformSidebarItems(sidebar, updateFn) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-4619",
3
+ "version": "0.0.0-4622",
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-4619",
27
- "@docusaurus/logger": "0.0.0-4619",
28
- "@docusaurus/mdx-loader": "0.0.0-4619",
29
- "@docusaurus/utils": "0.0.0-4619",
30
- "@docusaurus/utils-validation": "0.0.0-4619",
26
+ "@docusaurus/core": "0.0.0-4622",
27
+ "@docusaurus/logger": "0.0.0-4622",
28
+ "@docusaurus/mdx-loader": "0.0.0-4622",
29
+ "@docusaurus/utils": "0.0.0-4622",
30
+ "@docusaurus/utils-validation": "0.0.0-4622",
31
31
  "combine-promises": "^1.1.0",
32
32
  "fs-extra": "^10.0.0",
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-4619",
43
- "@docusaurus/types": "0.0.0-4619",
42
+ "@docusaurus/module-type-aliases": "0.0.0-4622",
43
+ "@docusaurus/types": "0.0.0-4622",
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": "ec771a43284544899f7dd4ef59a8b794c51f2399"
59
+ "gitHead": "88fa597b10a32d3f2e3cff963af8337e66f89a13"
60
60
  }
@@ -8,6 +8,10 @@
8
8
  declare module '@docusaurus/plugin-content-docs' {
9
9
  import type {RemarkAndRehypePluginOptions} from '@docusaurus/mdx-loader';
10
10
 
11
+ export interface Assets {
12
+ image?: string;
13
+ }
14
+
11
15
  export type NumberPrefixParser = (filename: string) => {
12
16
  filename: string;
13
17
  numberPrefix?: number;
@@ -159,6 +163,7 @@ declare module '@theme/DocItem' {
159
163
  import type {
160
164
  PropNavigationLink,
161
165
  PropVersionMetadata,
166
+ Assets,
162
167
  } from '@docusaurus/plugin-content-docs';
163
168
 
164
169
  export type DocumentRoute = {
@@ -204,6 +209,7 @@ declare module '@theme/DocItem' {
204
209
  readonly metadata: Metadata;
205
210
  readonly toc: readonly TOCItem[];
206
211
  readonly contentTitle: string | undefined;
212
+ readonly assets: Assets;
207
213
  (): JSX.Element;
208
214
  };
209
215
  }
@@ -18,6 +18,7 @@ import type {
18
18
  } from './types';
19
19
  import {isCategoriesShorthand} from './utils';
20
20
  import _ from 'lodash';
21
+ import logger from '@docusaurus/logger';
21
22
 
22
23
  function normalizeCategoriesShorthand(
23
24
  sidebar: SidebarCategoriesShorthand,
@@ -37,40 +38,37 @@ export function normalizeItem(
37
38
  item: SidebarItemConfig,
38
39
  ): NormalizedSidebarItem[] {
39
40
  if (typeof item === 'string') {
40
- return [
41
- {
42
- type: 'doc',
43
- id: item,
44
- },
45
- ];
41
+ return [{type: 'doc', id: item}];
46
42
  }
47
43
  if (isCategoriesShorthand(item)) {
48
- return normalizeCategoriesShorthand(item).flatMap((subItem) =>
49
- normalizeItem(subItem),
50
- );
44
+ // This will never throw anyways
45
+ return normalizeSidebar(item, 'sidebar items slice');
51
46
  }
52
47
  if (item.type === 'category') {
53
- if (typeof item.items !== 'undefined' && typeof item.items !== 'object') {
54
- throw new Error(
55
- `Invalid category ${JSON.stringify(
56
- item,
57
- )}: items must be an array of sidebar items or a category shorthand`,
58
- );
59
- }
60
48
  const normalizedCategory: NormalizedSidebarItemCategory = {
61
49
  ...item,
62
- items: Array.isArray(item.items)
63
- ? item.items.flatMap((subItem) => normalizeItem(subItem))
64
- : normalizeCategoriesShorthand(item.items).flatMap((subItem) =>
65
- normalizeItem(subItem),
66
- ),
50
+ items: normalizeSidebar(
51
+ item.items,
52
+ logger.interpolate`code=${'items'} of the category name=${item.label}`,
53
+ ),
67
54
  };
68
55
  return [normalizedCategory];
69
56
  }
70
57
  return [item];
71
58
  }
72
59
 
73
- function normalizeSidebar(sidebar: SidebarConfig): NormalizedSidebar {
60
+ function normalizeSidebar(
61
+ sidebar: SidebarConfig,
62
+ place: string,
63
+ ): NormalizedSidebar {
64
+ if (!Array.isArray(sidebar) && !isCategoriesShorthand(sidebar)) {
65
+ throw new Error(
66
+ logger.interpolate`Invalid sidebar items collection code=${JSON.stringify(
67
+ sidebar,
68
+ )} in ${place}: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a code=${'type'} property). See path=${'https://docusaurus.io/docs/sidebar/items'} for all valid syntaxes.`,
69
+ );
70
+ }
71
+
74
72
  const normalizedSidebar = Array.isArray(sidebar)
75
73
  ? sidebar
76
74
  : normalizeCategoriesShorthand(sidebar);
@@ -81,5 +79,7 @@ function normalizeSidebar(sidebar: SidebarConfig): NormalizedSidebar {
81
79
  export function normalizeSidebars(
82
80
  sidebars: SidebarsConfig,
83
81
  ): NormalizedSidebars {
84
- return _.mapValues(sidebars, normalizeSidebar);
82
+ return _.mapValues(sidebars, (sidebar, id) =>
83
+ normalizeSidebar(sidebar, logger.interpolate`sidebar name=${id}`),
84
+ );
85
85
  }
@@ -26,7 +26,7 @@ import type {DocMetadataBase, DocNavLink} from '../types';
26
26
  export function isCategoriesShorthand(
27
27
  item: SidebarItemConfig,
28
28
  ): item is SidebarCategoriesShorthand {
29
- return typeof item !== 'string' && !item.type;
29
+ return typeof item === 'object' && !item.type;
30
30
  }
31
31
 
32
32
  export function transformSidebarItems(