@docusaurus/plugin-content-docs 2.0.0-beta.8bda3b2db → 2.0.0-beta.9

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.
Files changed (117) hide show
  1. package/lib/.tsbuildinfo +1 -1
  2. package/lib/cli.d.ts +2 -2
  3. package/lib/cli.js +20 -24
  4. package/lib/client/docsClientUtils.d.ts +1 -4
  5. package/lib/client/docsClientUtils.js +12 -16
  6. package/lib/docFrontMatter.js +7 -3
  7. package/lib/docs.d.ts +4 -2
  8. package/lib/docs.js +77 -23
  9. package/lib/index.js +88 -94
  10. package/lib/lastUpdate.js +8 -8
  11. package/lib/markdown/index.d.ts +3 -6
  12. package/lib/markdown/index.js +3 -3
  13. package/lib/markdown/linkify.js +2 -2
  14. package/lib/options.d.ts +1 -1
  15. package/lib/options.js +39 -11
  16. package/lib/props.d.ts +7 -2
  17. package/lib/props.js +27 -4
  18. package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +3 -1
  19. package/lib/sidebars/generator.js +174 -0
  20. package/lib/sidebars/index.d.ts +14 -0
  21. package/lib/sidebars/index.js +64 -0
  22. package/lib/sidebars/normalization.d.ts +9 -0
  23. package/lib/sidebars/normalization.js +58 -0
  24. package/lib/sidebars/processor.d.ts +16 -0
  25. package/lib/sidebars/processor.js +70 -0
  26. package/lib/sidebars/types.d.ts +87 -0
  27. package/lib/sidebars/types.js +13 -0
  28. package/lib/sidebars/utils.d.ts +22 -0
  29. package/lib/sidebars/utils.js +101 -0
  30. package/lib/sidebars/validation.d.ts +8 -0
  31. package/lib/sidebars/validation.js +102 -0
  32. package/lib/slug.js +4 -4
  33. package/lib/tags.d.ts +8 -0
  34. package/lib/tags.js +22 -0
  35. package/lib/theme/hooks/useDocs.js +24 -21
  36. package/lib/translations.d.ts +1 -1
  37. package/lib/translations.js +13 -13
  38. package/lib/types.d.ts +35 -58
  39. package/lib/versions.d.ts +1 -1
  40. package/lib/versions.js +75 -22
  41. package/package.json +15 -14
  42. package/src/__tests__/__fixtures__/simple-site/docs/_partials/somePartial.md +3 -0
  43. package/src/__tests__/__fixtures__/simple-site/docs/_partials/subfolder/somePartial.md +3 -0
  44. package/src/__tests__/__fixtures__/simple-site/docs/_somePartial.md +3 -0
  45. package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +5 -0
  46. package/src/__tests__/__fixtures__/simple-site/docs/hello.md +1 -0
  47. package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +2 -0
  48. package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +2 -0
  49. package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +2 -0
  50. package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +2 -0
  51. package/src/__tests__/__fixtures__/simple-site/sidebars.json +15 -1
  52. package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +6 -0
  53. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/somePartial.md +3 -0
  54. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/subfolder/somePartial.md +3 -0
  55. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_somePartial.md +3 -0
  56. package/src/__tests__/__snapshots__/cli.test.ts.snap +33 -0
  57. package/src/__tests__/__snapshots__/docs.test.ts.snap +140 -0
  58. package/src/__tests__/__snapshots__/index.test.ts.snap +478 -60
  59. package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -3
  60. package/src/__tests__/cli.test.ts +14 -10
  61. package/src/__tests__/docFrontMatter.test.ts +163 -48
  62. package/src/__tests__/docs.test.ts +167 -21
  63. package/src/__tests__/index.test.ts +74 -30
  64. package/src/__tests__/lastUpdate.test.ts +3 -2
  65. package/src/__tests__/options.test.ts +46 -3
  66. package/src/__tests__/props.test.ts +62 -0
  67. package/src/__tests__/translations.test.ts +0 -1
  68. package/src/__tests__/versions.test.ts +88 -60
  69. package/src/cli.ts +27 -30
  70. package/src/client/__tests__/docsClientUtils.test.ts +4 -5
  71. package/src/client/docsClientUtils.ts +6 -27
  72. package/src/docFrontMatter.ts +8 -3
  73. package/src/docs.ts +92 -9
  74. package/src/index.ts +114 -121
  75. package/src/lastUpdate.ts +10 -6
  76. package/src/markdown/index.ts +8 -12
  77. package/src/numberPrefix.ts +4 -2
  78. package/src/options.ts +47 -17
  79. package/src/plugin-content-docs.d.ts +121 -34
  80. package/src/props.ts +42 -6
  81. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -0
  82. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -0
  83. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -0
  84. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category.js +0 -0
  85. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -0
  86. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed.json +0 -0
  87. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -0
  88. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-first-level-not-category.js +0 -0
  89. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -0
  90. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -0
  91. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link.json +0 -0
  92. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-unknown-type.json +0 -0
  93. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-wrong-field.json +0 -0
  94. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars.json +0 -0
  95. package/src/{__tests__/__snapshots__/sidebars.test.ts.snap → sidebars/__tests__/__snapshots__/index.test.ts.snap} +21 -6
  96. package/src/{__tests__/sidebarItemsGenerator.test.ts → sidebars/__tests__/generator.test.ts} +29 -7
  97. package/src/sidebars/__tests__/index.test.ts +202 -0
  98. package/src/sidebars/__tests__/processor.test.ts +148 -0
  99. package/src/sidebars/__tests__/utils.test.ts +395 -0
  100. package/src/sidebars/generator.ts +253 -0
  101. package/src/sidebars/index.ts +84 -0
  102. package/src/sidebars/normalization.ts +88 -0
  103. package/src/sidebars/processor.ts +124 -0
  104. package/src/sidebars/types.ts +156 -0
  105. package/src/sidebars/utils.ts +146 -0
  106. package/src/sidebars/validation.ts +124 -0
  107. package/src/tags.ts +21 -0
  108. package/src/theme/hooks/useDocs.ts +5 -1
  109. package/src/translations.ts +26 -36
  110. package/src/types.ts +48 -99
  111. package/src/versions.ts +109 -17
  112. package/lib/sidebarItemsGenerator.js +0 -211
  113. package/lib/sidebars.d.ts +0 -43
  114. package/lib/sidebars.js +0 -319
  115. package/src/__tests__/sidebars.test.ts +0 -639
  116. package/src/sidebarItemsGenerator.ts +0 -307
  117. package/src/sidebars.ts +0 -506
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { Optional } from 'utility-types';
8
+ import type { DocMetadataBase, VersionMetadata, NumberPrefixParser, SidebarOptions } from '../types';
9
+ declare type Expand<T extends Record<string, unknown>> = {
10
+ [P in keyof T]: T[P];
11
+ };
12
+ export declare type SidebarItemBase = {
13
+ className?: string;
14
+ customProps?: Record<string, unknown>;
15
+ };
16
+ export declare type SidebarItemDoc = SidebarItemBase & {
17
+ type: 'doc' | 'ref';
18
+ label?: string;
19
+ id: string;
20
+ };
21
+ export declare type SidebarItemLink = SidebarItemBase & {
22
+ type: 'link';
23
+ href: string;
24
+ label: string;
25
+ };
26
+ export declare type SidebarItemAutogenerated = SidebarItemBase & {
27
+ type: 'autogenerated';
28
+ dirName: string;
29
+ };
30
+ declare type SidebarItemCategoryBase = SidebarItemBase & {
31
+ type: 'category';
32
+ label: string;
33
+ collapsed: boolean;
34
+ collapsible: boolean;
35
+ };
36
+ export declare type SidebarItemCategoryConfig = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
37
+ items: SidebarItemConfig[];
38
+ }>;
39
+ export declare type SidebarCategoriesShorthand = {
40
+ [sidebarCategory: string]: SidebarItemConfig[];
41
+ };
42
+ export declare function isCategoriesShorthand(item: SidebarItemConfig): item is SidebarCategoriesShorthand;
43
+ export declare type SidebarItemConfig = SidebarItemDoc | SidebarItemLink | SidebarItemAutogenerated | SidebarItemCategoryConfig | string | SidebarCategoriesShorthand;
44
+ export declare type SidebarConfig = SidebarCategoriesShorthand | SidebarItemConfig[];
45
+ export declare type SidebarsConfig = {
46
+ [sidebarId: string]: SidebarConfig;
47
+ };
48
+ export declare type NormalizedSidebarItemCategory = Expand<SidebarItemCategoryBase & {
49
+ items: NormalizedSidebarItem[];
50
+ }>;
51
+ export declare type NormalizedSidebarItem = SidebarItemDoc | SidebarItemLink | NormalizedSidebarItemCategory | SidebarItemAutogenerated;
52
+ export declare type NormalizedSidebar = NormalizedSidebarItem[];
53
+ export declare type NormalizedSidebars = {
54
+ [sidebarId: string]: NormalizedSidebar;
55
+ };
56
+ export declare type SidebarItemCategory = Expand<SidebarItemCategoryBase & {
57
+ items: SidebarItem[];
58
+ }>;
59
+ export declare type SidebarItem = SidebarItemDoc | SidebarItemLink | SidebarItemCategory;
60
+ export declare type Sidebar = SidebarItem[];
61
+ export declare type SidebarItemType = SidebarItem['type'];
62
+ export declare type Sidebars = {
63
+ [sidebarId: string]: Sidebar;
64
+ };
65
+ export declare type PropSidebarItemCategory = Expand<SidebarItemCategoryBase & {
66
+ items: PropSidebarItem[];
67
+ }>;
68
+ export declare type PropSidebarItem = SidebarItemLink | PropSidebarItemCategory;
69
+ export declare type PropSidebar = PropSidebarItem[];
70
+ export declare type PropSidebars = {
71
+ [sidebarId: string]: PropSidebar;
72
+ };
73
+ export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
74
+ export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
75
+ export declare type SidebarItemsGeneratorArgs = {
76
+ item: SidebarItemAutogenerated;
77
+ version: SidebarItemsGeneratorVersion;
78
+ docs: SidebarItemsGeneratorDoc[];
79
+ numberPrefixParser: NumberPrefixParser;
80
+ options: SidebarOptions;
81
+ };
82
+ export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<SidebarItem[]>;
83
+ export declare type SidebarItemsGeneratorOptionArgs = {
84
+ defaultSidebarItemsGenerator: SidebarItemsGenerator;
85
+ } & SidebarItemsGeneratorArgs;
86
+ export declare type SidebarItemsGeneratorOption = (generatorArgs: SidebarItemsGeneratorOptionArgs) => Promise<SidebarItem[]>;
87
+ export {};
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.isCategoriesShorthand = void 0;
10
+ function isCategoriesShorthand(item) {
11
+ return typeof item !== 'string' && !item.type;
12
+ }
13
+ exports.isCategoriesShorthand = isCategoriesShorthand;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { Sidebars, Sidebar, SidebarItem, SidebarItemCategory, SidebarItemLink, SidebarItemDoc } from './types';
8
+ export declare function transformSidebarItems(sidebar: Sidebar, updateFn: (item: SidebarItem) => SidebarItem): Sidebar;
9
+ export declare function collectSidebarDocItems(sidebar: Sidebar): SidebarItemDoc[];
10
+ export declare function collectSidebarCategories(sidebar: Sidebar): SidebarItemCategory[];
11
+ export declare function collectSidebarLinks(sidebar: Sidebar): SidebarItemLink[];
12
+ export declare function collectSidebarsDocIds(sidebars: Sidebars): Record<string, string[]>;
13
+ export declare function createSidebarsUtils(sidebars: Sidebars): {
14
+ getFirstDocIdOfFirstSidebar: () => string | undefined;
15
+ getSidebarNameByDocId: (docId: string) => string | undefined;
16
+ getDocNavigation: (docId: string) => {
17
+ sidebarName: string | undefined;
18
+ previousId: string | undefined;
19
+ nextId: string | undefined;
20
+ };
21
+ checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
22
+ };
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createSidebarsUtils = exports.collectSidebarsDocIds = exports.collectSidebarLinks = exports.collectSidebarCategories = exports.collectSidebarDocItems = exports.transformSidebarItems = void 0;
10
+ const lodash_1 = require("lodash");
11
+ const utils_1 = require("@docusaurus/utils");
12
+ function transformSidebarItems(sidebar, updateFn) {
13
+ function transformRecursive(item) {
14
+ if (item.type === 'category') {
15
+ return updateFn({
16
+ ...item,
17
+ items: item.items.map(transformRecursive),
18
+ });
19
+ }
20
+ return updateFn(item);
21
+ }
22
+ return sidebar.map(transformRecursive);
23
+ }
24
+ exports.transformSidebarItems = transformSidebarItems;
25
+ function collectSidebarItemsOfType(type, sidebar) {
26
+ function collectRecursive(item) {
27
+ const currentItemsCollected = item.type === type ? [item] : [];
28
+ const childItemsCollected = item.type === 'category' ? item.items.flatMap(collectRecursive) : [];
29
+ return [...currentItemsCollected, ...childItemsCollected];
30
+ }
31
+ return sidebar.flatMap(collectRecursive);
32
+ }
33
+ function collectSidebarDocItems(sidebar) {
34
+ return collectSidebarItemsOfType('doc', sidebar);
35
+ }
36
+ exports.collectSidebarDocItems = collectSidebarDocItems;
37
+ function collectSidebarCategories(sidebar) {
38
+ return collectSidebarItemsOfType('category', sidebar);
39
+ }
40
+ exports.collectSidebarCategories = collectSidebarCategories;
41
+ function collectSidebarLinks(sidebar) {
42
+ return collectSidebarItemsOfType('link', sidebar);
43
+ }
44
+ exports.collectSidebarLinks = collectSidebarLinks;
45
+ function collectSidebarsDocIds(sidebars) {
46
+ return (0, lodash_1.mapValues)(sidebars, (sidebar) => {
47
+ return collectSidebarDocItems(sidebar).map((docItem) => docItem.id);
48
+ });
49
+ }
50
+ exports.collectSidebarsDocIds = collectSidebarsDocIds;
51
+ function createSidebarsUtils(sidebars) {
52
+ const sidebarNameToDocIds = collectSidebarsDocIds(sidebars);
53
+ // Reverse mapping
54
+ const docIdToSidebarName = Object.fromEntries(Object.entries(sidebarNameToDocIds).flatMap(([sidebarName, docIds]) => docIds.map((docId) => [docId, sidebarName])));
55
+ function getFirstDocIdOfFirstSidebar() {
56
+ var _a;
57
+ return (_a = Object.values(sidebarNameToDocIds)[0]) === null || _a === void 0 ? void 0 : _a[0];
58
+ }
59
+ function getSidebarNameByDocId(docId) {
60
+ return docIdToSidebarName[docId];
61
+ }
62
+ function getDocNavigation(docId) {
63
+ const sidebarName = getSidebarNameByDocId(docId);
64
+ if (sidebarName) {
65
+ const docIds = sidebarNameToDocIds[sidebarName];
66
+ const currentIndex = docIds.indexOf(docId);
67
+ const { previous, next } = (0, utils_1.getElementsAround)(docIds, currentIndex);
68
+ return {
69
+ sidebarName,
70
+ previousId: previous,
71
+ nextId: next,
72
+ };
73
+ }
74
+ else {
75
+ return {
76
+ sidebarName: undefined,
77
+ previousId: undefined,
78
+ nextId: undefined,
79
+ };
80
+ }
81
+ }
82
+ function checkSidebarsDocIds(validDocIds, sidebarFilePath) {
83
+ const allSidebarDocIds = Object.values(sidebarNameToDocIds).flat();
84
+ const invalidSidebarDocIds = (0, lodash_1.difference)(allSidebarDocIds, validDocIds);
85
+ if (invalidSidebarDocIds.length > 0) {
86
+ throw new Error(`Invalid sidebar file at "${(0, utils_1.toMessageRelativeFilePath)(sidebarFilePath)}".
87
+ These sidebar document ids do not exist:
88
+ - ${invalidSidebarDocIds.sort().join('\n- ')}
89
+
90
+ Available document ids are:
91
+ - ${validDocIds.sort().join('\n- ')}`);
92
+ }
93
+ }
94
+ return {
95
+ getFirstDocIdOfFirstSidebar,
96
+ getSidebarNameByDocId,
97
+ getDocNavigation,
98
+ checkSidebarsDocIds,
99
+ };
100
+ }
101
+ exports.createSidebarsUtils = createSidebarsUtils;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { SidebarsConfig } from './types';
8
+ export declare function validateSidebars(sidebars: unknown): asserts sidebars is SidebarsConfig;
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.validateSidebars = void 0;
10
+ const utils_validation_1 = require("@docusaurus/utils-validation");
11
+ const types_1 = require("./types");
12
+ const sidebarItemBaseSchema = utils_validation_1.Joi.object({
13
+ className: utils_validation_1.Joi.string(),
14
+ customProps: utils_validation_1.Joi.object().unknown(),
15
+ });
16
+ const sidebarItemAutogeneratedSchema = sidebarItemBaseSchema.append({
17
+ type: 'autogenerated',
18
+ dirName: utils_validation_1.Joi.string()
19
+ .required()
20
+ .pattern(/^[^/](.*[^/])?$/)
21
+ .message('"dirName" must be a dir path relative to the docs folder root, and should not start or end with slash'),
22
+ });
23
+ const sidebarItemDocSchema = sidebarItemBaseSchema.append({
24
+ type: utils_validation_1.Joi.string().valid('doc', 'ref').required(),
25
+ id: utils_validation_1.Joi.string().required(),
26
+ label: utils_validation_1.Joi.string(),
27
+ });
28
+ const sidebarItemLinkSchema = sidebarItemBaseSchema.append({
29
+ type: 'link',
30
+ href: utils_validation_1.URISchema.required(),
31
+ label: utils_validation_1.Joi.string()
32
+ .required()
33
+ .messages({ 'any.unknown': '"label" must be a string' }),
34
+ });
35
+ const sidebarItemCategorySchema = sidebarItemBaseSchema.append({
36
+ type: 'category',
37
+ label: utils_validation_1.Joi.string()
38
+ .required()
39
+ .messages({ 'any.unknown': '"label" must be a string' }),
40
+ // TODO: Joi doesn't allow mutual recursion. See https://github.com/sideway/joi/issues/2611
41
+ items: utils_validation_1.Joi.array()
42
+ .required()
43
+ .messages({ 'any.unknown': '"items" must be an array' }),
44
+ collapsed: utils_validation_1.Joi.boolean().messages({
45
+ 'any.unknown': '"collapsed" must be a boolean',
46
+ }),
47
+ collapsible: utils_validation_1.Joi.boolean().messages({
48
+ 'any.unknown': '"collapsible" must be a boolean',
49
+ }),
50
+ });
51
+ const sidebarItemSchema = utils_validation_1.Joi.object()
52
+ .when('.type', {
53
+ switch: [
54
+ { is: 'link', then: sidebarItemLinkSchema },
55
+ {
56
+ is: utils_validation_1.Joi.string().valid('doc', 'ref').required(),
57
+ then: sidebarItemDocSchema,
58
+ },
59
+ { is: 'autogenerated', then: sidebarItemAutogeneratedSchema },
60
+ { is: 'category', then: sidebarItemCategorySchema },
61
+ {
62
+ is: 'subcategory',
63
+ then: utils_validation_1.Joi.forbidden().messages({
64
+ 'any.unknown': 'Docusaurus v2: "subcategory" has been renamed as "category".',
65
+ }),
66
+ },
67
+ {
68
+ is: utils_validation_1.Joi.string().required(),
69
+ then: utils_validation_1.Joi.forbidden().messages({
70
+ 'any.unknown': 'Unknown sidebar item type "{.type}".',
71
+ }),
72
+ },
73
+ ],
74
+ })
75
+ .id('sidebarItemSchema');
76
+ function validateSidebarItem(item) {
77
+ if (typeof item === 'string') {
78
+ return;
79
+ }
80
+ // TODO: remove once with proper Joi support
81
+ // Because we can't use Joi to validate nested items (see above), we do it manually
82
+ if ((0, types_1.isCategoriesShorthand)(item)) {
83
+ Object.values(item).forEach((category) => category.forEach(validateSidebarItem));
84
+ }
85
+ else {
86
+ utils_validation_1.Joi.assert(item, sidebarItemSchema);
87
+ if (item.type === 'category') {
88
+ item.items.forEach(validateSidebarItem);
89
+ }
90
+ }
91
+ }
92
+ function validateSidebars(sidebars) {
93
+ Object.values(sidebars).forEach((sidebar) => {
94
+ if (Array.isArray(sidebar)) {
95
+ sidebar.forEach(validateSidebarItem);
96
+ }
97
+ else {
98
+ validateSidebarItem(sidebar);
99
+ }
100
+ });
101
+ }
102
+ exports.validateSidebars = validateSidebars;
package/lib/slug.js CHANGED
@@ -16,14 +16,14 @@ function getSlug({ baseID, frontmatterSlug, dirName, stripDirNumberPrefixes = tr
16
16
  }
17
17
  else {
18
18
  const dirNameStripped = stripDirNumberPrefixes
19
- ? numberPrefix_1.stripPathNumberPrefixes(dirName, numberPrefixParser)
19
+ ? (0, numberPrefix_1.stripPathNumberPrefixes)(dirName, numberPrefixParser)
20
20
  : dirName;
21
21
  const resolveDirname = dirName === '.'
22
22
  ? '/'
23
- : utils_1.addLeadingSlash(utils_1.addTrailingSlash(dirNameStripped));
24
- slug = utils_1.resolvePathname(baseSlug, resolveDirname);
23
+ : (0, utils_1.addLeadingSlash)((0, utils_1.addTrailingSlash)(dirNameStripped));
24
+ slug = (0, utils_1.resolvePathname)(baseSlug, resolveDirname);
25
25
  }
26
- if (!utils_1.isValidPathname(slug)) {
26
+ if (!(0, utils_1.isValidPathname)(slug)) {
27
27
  throw new Error(`We couldn't compute a valid slug for document with id "${baseID}" in "${dirName}" directory.
28
28
  The slug we computed looks invalid: ${slug}.
29
29
  Maybe your slug frontmatter is incorrect or you use weird chars in the file path?
package/lib/tags.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { VersionTags, DocMetadata } from './types';
8
+ export declare function getVersionTags(docs: DocMetadata[]): VersionTags;
package/lib/tags.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.getVersionTags = void 0;
10
+ const utils_1 = require("@docusaurus/utils");
11
+ const lodash_1 = require("lodash");
12
+ function getVersionTags(docs) {
13
+ const groups = (0, utils_1.groupTaggedItems)(docs, (doc) => doc.tags);
14
+ return (0, lodash_1.mapValues)(groups, (group) => {
15
+ return {
16
+ name: group.tag.label,
17
+ docIds: group.items.map((item) => item.id),
18
+ permalink: group.tag.permalink,
19
+ };
20
+ });
21
+ }
22
+ exports.getVersionTags = getVersionTags;
@@ -9,27 +9,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.useDocVersionSuggestions = exports.useActiveDocContext = exports.useActiveVersion = exports.useLatestVersion = exports.useVersions = exports.useActivePluginAndVersion = exports.useActivePlugin = exports.useDocsData = exports.useAllDocsData = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const router_1 = require("@docusaurus/router");
12
- const useGlobalData_1 = tslib_1.__importStar(require("@docusaurus/useGlobalData"));
12
+ const useGlobalData_1 = (0, tslib_1.__importStar)(require("@docusaurus/useGlobalData"));
13
13
  const docsClientUtils_1 = require("../../client/docsClientUtils");
14
+ // Important to use a constant object to avoid React useEffect executions etc...,
15
+ // see https://github.com/facebook/docusaurus/issues/5089
16
+ const StableEmptyObject = {};
14
17
  // Not using useAllPluginInstancesData() because in blog-only mode, docs hooks are still used by the theme
15
18
  // We need a fail-safe fallback when the docs plugin is not in use
16
19
  const useAllDocsData = () => { var _a;
17
20
  // useAllPluginInstancesData('docusaurus-plugin-content-docs');
18
- return (_a = useGlobalData_1.default()['docusaurus-plugin-content-docs']) !== null && _a !== void 0 ? _a : {}; };
21
+ return (_a = (0, useGlobalData_1.default)()['docusaurus-plugin-content-docs']) !== null && _a !== void 0 ? _a : StableEmptyObject; };
19
22
  exports.useAllDocsData = useAllDocsData;
20
- const useDocsData = (pluginId) => useGlobalData_1.usePluginData('docusaurus-plugin-content-docs', pluginId);
23
+ const useDocsData = (pluginId) => (0, useGlobalData_1.usePluginData)('docusaurus-plugin-content-docs', pluginId);
21
24
  exports.useDocsData = useDocsData;
22
25
  const useActivePlugin = (options = {}) => {
23
- const data = exports.useAllDocsData();
24
- const { pathname } = router_1.useLocation();
25
- return docsClientUtils_1.getActivePlugin(data, pathname, options);
26
+ const data = (0, exports.useAllDocsData)();
27
+ const { pathname } = (0, router_1.useLocation)();
28
+ return (0, docsClientUtils_1.getActivePlugin)(data, pathname, options);
26
29
  };
27
30
  exports.useActivePlugin = useActivePlugin;
28
31
  const useActivePluginAndVersion = (options = {}) => {
29
- const activePlugin = exports.useActivePlugin(options);
30
- const { pathname } = router_1.useLocation();
32
+ const activePlugin = (0, exports.useActivePlugin)(options);
33
+ const { pathname } = (0, router_1.useLocation)();
31
34
  if (activePlugin) {
32
- const activeVersion = docsClientUtils_1.getActiveVersion(activePlugin.pluginData, pathname);
35
+ const activeVersion = (0, docsClientUtils_1.getActiveVersion)(activePlugin.pluginData, pathname);
33
36
  return {
34
37
  activePlugin,
35
38
  activeVersion,
@@ -40,33 +43,33 @@ const useActivePluginAndVersion = (options = {}) => {
40
43
  exports.useActivePluginAndVersion = useActivePluginAndVersion;
41
44
  // versions are returned ordered (most recent first)
42
45
  const useVersions = (pluginId) => {
43
- const data = exports.useDocsData(pluginId);
46
+ const data = (0, exports.useDocsData)(pluginId);
44
47
  return data.versions;
45
48
  };
46
49
  exports.useVersions = useVersions;
47
50
  const useLatestVersion = (pluginId) => {
48
- const data = exports.useDocsData(pluginId);
49
- return docsClientUtils_1.getLatestVersion(data);
51
+ const data = (0, exports.useDocsData)(pluginId);
52
+ return (0, docsClientUtils_1.getLatestVersion)(data);
50
53
  };
51
54
  exports.useLatestVersion = useLatestVersion;
52
55
  // Note: return undefined on doc-unrelated pages,
53
56
  // because there's no version currently considered as active
54
57
  const useActiveVersion = (pluginId) => {
55
- const data = exports.useDocsData(pluginId);
56
- const { pathname } = router_1.useLocation();
57
- return docsClientUtils_1.getActiveVersion(data, pathname);
58
+ const data = (0, exports.useDocsData)(pluginId);
59
+ const { pathname } = (0, router_1.useLocation)();
60
+ return (0, docsClientUtils_1.getActiveVersion)(data, pathname);
58
61
  };
59
62
  exports.useActiveVersion = useActiveVersion;
60
63
  const useActiveDocContext = (pluginId) => {
61
- const data = exports.useDocsData(pluginId);
62
- const { pathname } = router_1.useLocation();
63
- return docsClientUtils_1.getActiveDocContext(data, pathname);
64
+ const data = (0, exports.useDocsData)(pluginId);
65
+ const { pathname } = (0, router_1.useLocation)();
66
+ return (0, docsClientUtils_1.getActiveDocContext)(data, pathname);
64
67
  };
65
68
  exports.useActiveDocContext = useActiveDocContext;
66
69
  // Useful to say "hey, you are not on the latest docs version, please switch"
67
70
  const useDocVersionSuggestions = (pluginId) => {
68
- const data = exports.useDocsData(pluginId);
69
- const { pathname } = router_1.useLocation();
70
- return docsClientUtils_1.getDocVersionSuggestions(data, pathname);
71
+ const data = (0, exports.useDocsData)(pluginId);
72
+ const { pathname } = (0, router_1.useLocation)();
73
+ return (0, docsClientUtils_1.getDocVersionSuggestions)(data, pathname);
71
74
  };
72
75
  exports.useDocVersionSuggestions = useDocVersionSuggestions;
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { LoadedContent } from './types';
7
+ import type { LoadedContent } from './types';
8
8
  import { TranslationFile, TranslationFiles } from '@docusaurus/types';
9
9
  export declare function getLoadedContentTranslationFiles(loadedContent: LoadedContent): TranslationFiles;
10
10
  export declare function translateLoadedContent(loadedContent: LoadedContent, translationFiles: TranslationFile[]): LoadedContent;
@@ -8,8 +8,8 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.translateLoadedContent = exports.getLoadedContentTranslationFiles = void 0;
10
10
  const lodash_1 = require("lodash");
11
- const sidebars_1 = require("./sidebars");
12
- const utils_1 = require("@docusaurus/utils");
11
+ const utils_1 = require("./sidebars/utils");
12
+ const utils_2 = require("@docusaurus/utils");
13
13
  const constants_1 = require("./constants");
14
14
  function getVersionFileName(versionName) {
15
15
  if (versionName === constants_1.CURRENT_VERSION_NAME) {
@@ -74,26 +74,26 @@ function translateDocs(
74
74
  }
75
75
  */
76
76
  function getSidebarTranslationFileContent(sidebar, sidebarName) {
77
- const categories = sidebars_1.collectSidebarCategories(sidebar);
78
- const categoryContent = lodash_1.chain(categories)
77
+ const categories = (0, utils_1.collectSidebarCategories)(sidebar);
78
+ const categoryContent = (0, lodash_1.chain)(categories)
79
79
  .keyBy((category) => `sidebar.${sidebarName}.category.${category.label}`)
80
80
  .mapValues((category) => ({
81
81
  message: category.label,
82
82
  description: `The label for category ${category.label} in sidebar ${sidebarName}`,
83
83
  }))
84
84
  .value();
85
- const links = sidebars_1.collectSidebarLinks(sidebar);
86
- const linksContent = lodash_1.chain(links)
85
+ const links = (0, utils_1.collectSidebarLinks)(sidebar);
86
+ const linksContent = (0, lodash_1.chain)(links)
87
87
  .keyBy((link) => `sidebar.${sidebarName}.link.${link.label}`)
88
88
  .mapValues((link) => ({
89
89
  message: link.label,
90
90
  description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
91
91
  }))
92
92
  .value();
93
- return utils_1.mergeTranslations([categoryContent, linksContent]);
93
+ return (0, utils_2.mergeTranslations)([categoryContent, linksContent]);
94
94
  }
95
95
  function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
96
- return sidebars_1.transformSidebarItems(sidebar, (item) => {
96
+ return (0, utils_1.transformSidebarItems)(sidebar, (item) => {
97
97
  var _a, _b, _c, _d;
98
98
  if (item.type === 'category') {
99
99
  return {
@@ -111,7 +111,7 @@ function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
111
111
  });
112
112
  }
113
113
  function getSidebarsTranslations(version) {
114
- return utils_1.mergeTranslations(Object.entries(version.sidebars).map(([sidebarName, sidebar]) => {
114
+ return (0, utils_2.mergeTranslations)(Object.entries(version.sidebars).map(([sidebarName, sidebar]) => {
115
115
  const normalizedSidebarName = getNormalizedSidebarName({
116
116
  sidebarName,
117
117
  versionName: version.versionName,
@@ -120,7 +120,7 @@ function getSidebarsTranslations(version) {
120
120
  }));
121
121
  }
122
122
  function translateSidebars(version, sidebarsTranslations) {
123
- return lodash_1.mapValues(version.sidebars, (sidebar, sidebarName) => {
123
+ return (0, lodash_1.mapValues)(version.sidebars, (sidebar, sidebarName) => {
124
124
  return translateSidebar({
125
125
  sidebar,
126
126
  sidebarName: getNormalizedSidebarName({
@@ -143,7 +143,7 @@ function getVersionTranslationFiles(version) {
143
143
  return [
144
144
  {
145
145
  path: getVersionFileName(version.versionName),
146
- content: utils_1.mergeTranslations([
146
+ content: (0, utils_2.mergeTranslations)([
147
147
  versionTranslations,
148
148
  sidebarsTranslations,
149
149
  // docsTranslations,
@@ -162,7 +162,7 @@ function translateVersion(version, translationFiles) {
162
162
  };
163
163
  }
164
164
  function getVersionsTranslationFiles(versions) {
165
- return lodash_1.flatten(versions.map(getVersionTranslationFiles));
165
+ return versions.flatMap(getVersionTranslationFiles);
166
166
  }
167
167
  function translateVersions(versions, translationFiles) {
168
168
  return versions.map((version) => translateVersion(version, translationFiles));
@@ -172,7 +172,7 @@ function getLoadedContentTranslationFiles(loadedContent) {
172
172
  }
173
173
  exports.getLoadedContentTranslationFiles = getLoadedContentTranslationFiles;
174
174
  function translateLoadedContent(loadedContent, translationFiles) {
175
- const translationFilesMap = lodash_1.keyBy(translationFiles, (f) => f.path);
175
+ const translationFilesMap = (0, lodash_1.keyBy)(translationFiles, (f) => f.path);
176
176
  return {
177
177
  loadedVersions: translateVersions(loadedContent.loadedVersions, translationFilesMap),
178
178
  };