@docusaurus/plugin-content-docs 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17

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 (213) hide show
  1. package/lib/categoryGeneratedIndex.d.ts +12 -0
  2. package/lib/categoryGeneratedIndex.js +38 -0
  3. package/lib/cli.d.ts +2 -2
  4. package/lib/cli.js +27 -44
  5. package/lib/client/docsClientUtils.d.ts +3 -25
  6. package/lib/client/docsClientUtils.js +25 -24
  7. package/lib/{theme/hooks/useDocs.d.ts → client/index.d.ts} +1 -2
  8. package/lib/{theme/hooks/useDocs.js → client/index.js} +26 -26
  9. package/lib/docFrontMatter.d.ts +1 -1
  10. package/lib/docFrontMatter.js +9 -3
  11. package/lib/docs.d.ts +39 -3
  12. package/lib/docs.js +157 -53
  13. package/lib/globalData.d.ts +5 -1
  14. package/lib/globalData.js +35 -2
  15. package/lib/index.d.ts +4 -3
  16. package/lib/index.js +110 -144
  17. package/lib/lastUpdate.js +15 -28
  18. package/lib/markdown/index.d.ts +3 -6
  19. package/lib/markdown/index.js +3 -3
  20. package/lib/markdown/linkify.d.ts +1 -1
  21. package/lib/markdown/linkify.js +2 -2
  22. package/lib/numberPrefix.d.ts +1 -1
  23. package/lib/numberPrefix.js +9 -9
  24. package/lib/options.d.ts +3 -3
  25. package/lib/options.js +50 -10
  26. package/lib/props.d.ts +7 -2
  27. package/lib/props.js +66 -11
  28. package/lib/routes.d.ts +28 -0
  29. package/lib/routes.js +110 -0
  30. package/lib/server-export.d.ts +8 -0
  31. package/lib/server-export.js +23 -0
  32. package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +1 -6
  33. package/lib/sidebars/generator.js +193 -0
  34. package/lib/sidebars/index.d.ts +13 -0
  35. package/lib/sidebars/index.js +88 -0
  36. package/lib/sidebars/normalization.d.ts +13 -0
  37. package/lib/sidebars/normalization.js +55 -0
  38. package/lib/sidebars/postProcessor.d.ts +8 -0
  39. package/lib/sidebars/postProcessor.js +70 -0
  40. package/lib/sidebars/processor.d.ts +8 -0
  41. package/lib/sidebars/processor.js +79 -0
  42. package/lib/sidebars/types.d.ts +166 -0
  43. package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js → lib/sidebars/types.js} +2 -10
  44. package/lib/sidebars/utils.d.ts +43 -0
  45. package/lib/sidebars/utils.js +259 -0
  46. package/lib/sidebars/validation.d.ts +9 -0
  47. package/lib/sidebars/validation.js +137 -0
  48. package/lib/slug.d.ts +6 -4
  49. package/lib/slug.js +28 -17
  50. package/{src/__tests__/__fixtures__/site-with-doc-label/docusaurus.config.js → lib/tags.d.ts} +2 -8
  51. package/lib/tags.js +21 -0
  52. package/lib/translations.d.ts +2 -2
  53. package/lib/translations.js +91 -49
  54. package/lib/types.d.ts +40 -126
  55. package/lib/versions.d.ts +29 -4
  56. package/lib/versions.js +92 -87
  57. package/package.json +30 -27
  58. package/src/categoryGeneratedIndex.ts +59 -0
  59. package/src/cli.ts +34 -54
  60. package/src/client/docsClientUtils.ts +32 -57
  61. package/src/{theme/hooks/useDocs.ts → client/index.ts} +11 -10
  62. package/{types.d.ts → src/deps.d.ts} +0 -0
  63. package/src/docFrontMatter.ts +12 -5
  64. package/src/docs.ts +213 -47
  65. package/src/globalData.ts +53 -2
  66. package/src/index.ts +151 -197
  67. package/src/lastUpdate.ts +14 -37
  68. package/src/markdown/index.ts +9 -13
  69. package/src/markdown/linkify.ts +1 -1
  70. package/src/numberPrefix.ts +11 -8
  71. package/src/options.ts +59 -15
  72. package/src/plugin-content-docs.d.ts +249 -54
  73. package/src/props.ts +97 -18
  74. package/src/routes.ts +185 -0
  75. package/src/server-export.ts +24 -0
  76. package/src/sidebars/README.md +9 -0
  77. package/src/sidebars/generator.ts +269 -0
  78. package/src/sidebars/index.ts +113 -0
  79. package/src/sidebars/normalization.ts +85 -0
  80. package/src/sidebars/postProcessor.ts +94 -0
  81. package/src/sidebars/processor.ts +126 -0
  82. package/src/sidebars/types.ts +273 -0
  83. package/src/sidebars/utils.ts +392 -0
  84. package/src/sidebars/validation.ts +173 -0
  85. package/src/slug.ts +39 -21
  86. package/src/tags.ts +19 -0
  87. package/src/translations.ts +121 -62
  88. package/src/types.ts +46 -183
  89. package/src/versions.ts +136 -102
  90. package/lib/.tsbuildinfo +0 -1
  91. package/lib/sidebarItemsGenerator.js +0 -211
  92. package/lib/sidebars.d.ts +0 -43
  93. package/lib/sidebars.js +0 -320
  94. package/src/__tests__/__fixtures__/bad-id-site/docs/invalid-id.md +0 -5
  95. package/src/__tests__/__fixtures__/bad-slug-on-doc-home-site/docs/docWithSlug.md +0 -5
  96. package/src/__tests__/__fixtures__/empty-site/docusaurus.config.js +0 -16
  97. package/src/__tests__/__fixtures__/empty-site/sidebars.json +0 -1
  98. package/src/__tests__/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -34
  99. package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -11
  100. package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -11
  101. package/src/__tests__/__fixtures__/sidebars/sidebars-category.js +0 -44
  102. package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -20
  103. package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed.json +0 -21
  104. package/src/__tests__/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -10
  105. package/src/__tests__/__fixtures__/sidebars/sidebars-first-level-not-category.js +0 -20
  106. package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -11
  107. package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -11
  108. package/src/__tests__/__fixtures__/sidebars/sidebars-link.json +0 -11
  109. package/src/__tests__/__fixtures__/sidebars/sidebars-unknown-type.json +0 -14
  110. package/src/__tests__/__fixtures__/sidebars/sidebars-wrong-field.json +0 -20
  111. package/src/__tests__/__fixtures__/sidebars/sidebars.json +0 -20
  112. package/src/__tests__/__fixtures__/simple-site/docs/foo/bar.md +0 -69
  113. package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +0 -70
  114. package/src/__tests__/__fixtures__/simple-site/docs/headingAsTitle.md +0 -1
  115. package/src/__tests__/__fixtures__/simple-site/docs/hello.md +0 -53
  116. package/src/__tests__/__fixtures__/simple-site/docs/ipsum.md +0 -5
  117. package/src/__tests__/__fixtures__/simple-site/docs/lorem.md +0 -6
  118. package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +0 -5
  119. package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +0 -5
  120. package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +0 -5
  121. package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +0 -5
  122. package/src/__tests__/__fixtures__/simple-site/docs/slugs/absoluteSlug.md +0 -5
  123. package/src/__tests__/__fixtures__/simple-site/docs/slugs/relativeSlug.md +0 -5
  124. package/src/__tests__/__fixtures__/simple-site/docs/slugs/resolvedSlug.md +0 -5
  125. package/src/__tests__/__fixtures__/simple-site/docs/slugs/tryToEscapeSlug.md +0 -5
  126. package/src/__tests__/__fixtures__/simple-site/docusaurus.config.js +0 -14
  127. package/src/__tests__/__fixtures__/simple-site/sidebars.json +0 -23
  128. package/src/__tests__/__fixtures__/simple-site/wrong-sidebars.json +0 -7
  129. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/0-getting-started.md +0 -3
  130. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/1-installation.md +0 -3
  131. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/00_api-overview.md +0 -3
  132. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/0 --- Client API.md +0 -1
  133. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/1 --- Server API.md +0 -1
  134. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/0. Plugin API.md +0 -1
  135. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/1. Theme API.md +0 -1
  136. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/_category_.yml +0 -1
  137. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/03_api-end.md +0 -3
  138. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/_category_.json +0 -3
  139. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/0-guide2.5.md +0 -8
  140. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/02-guide2.md +0 -7
  141. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/_category_.json +0 -3
  142. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/a-guide4.md +0 -7
  143. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/b-guide5.md +0 -7
  144. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/guide3.md +0 -8
  145. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/z-guide1.md +0 -8
  146. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docusaurus.config.js +0 -14
  147. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars.js +0 -23
  148. package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-1.md +0 -7
  149. package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-2.md +0 -8
  150. package/src/__tests__/__fixtures__/site-with-doc-label/sidebars.json +0 -14
  151. package/src/__tests__/__fixtures__/versioned-site/community/team.md +0 -1
  152. package/src/__tests__/__fixtures__/versioned-site/community_sidebars.json +0 -3
  153. package/src/__tests__/__fixtures__/versioned-site/community_versioned_docs/version-1.0.0/team.md +0 -1
  154. package/src/__tests__/__fixtures__/versioned-site/community_versioned_sidebars/version-1.0.0-sidebars.json +0 -3
  155. package/src/__tests__/__fixtures__/versioned-site/community_versions.json +0 -1
  156. package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +0 -4
  157. package/src/__tests__/__fixtures__/versioned-site/docs/hello.md +0 -1
  158. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/absoluteSlug.md +0 -5
  159. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/relativeSlug.md +0 -5
  160. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/resolvedSlug.md +0 -5
  161. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/tryToEscapeSlug.md +0 -5
  162. package/src/__tests__/__fixtures__/versioned-site/docusaurus.config.js +0 -18
  163. package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
  164. package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs-community/current/team.md +0 -5
  165. package/src/__tests__/__fixtures__/versioned-site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
  166. package/src/__tests__/__fixtures__/versioned-site/sidebars.json +0 -10
  167. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/bar.md +0 -4
  168. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/baz.md +0 -1
  169. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md +0 -1
  170. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/foo/bar.md +0 -1
  171. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md +0 -1
  172. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootAbsoluteSlug.md +0 -5
  173. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootRelativeSlug.md +0 -5
  174. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootResolvedSlug.md +0 -5
  175. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootTryToEscapeSlug.md +0 -5
  176. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/absoluteSlug.md +0 -5
  177. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/relativeSlug.md +0 -5
  178. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/resolvedSlug.md +0 -5
  179. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/tryToEscapeSlug.md +0 -5
  180. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.0-sidebars.json +0 -11
  181. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +0 -10
  182. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-withSlugs-sidebars.json +0 -5
  183. package/src/__tests__/__fixtures__/versioned-site/versions.json +0 -5
  184. package/src/__tests__/__snapshots__/cli.test.ts.snap +0 -90
  185. package/src/__tests__/__snapshots__/index.test.ts.snap +0 -1916
  186. package/src/__tests__/__snapshots__/sidebars.test.ts.snap +0 -218
  187. package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -487
  188. package/src/__tests__/cli.test.ts +0 -333
  189. package/src/__tests__/docFrontMatter.test.ts +0 -244
  190. package/src/__tests__/docs.test.ts +0 -878
  191. package/src/__tests__/index.test.ts +0 -1871
  192. package/src/__tests__/lastUpdate.test.ts +0 -69
  193. package/src/__tests__/numberPrefix.test.ts +0 -199
  194. package/src/__tests__/options.test.ts +0 -231
  195. package/src/__tests__/sidebarItemsGenerator.test.ts +0 -336
  196. package/src/__tests__/sidebars.test.ts +0 -639
  197. package/src/__tests__/slug.test.ts +0 -109
  198. package/src/__tests__/translations.test.ts +0 -159
  199. package/src/__tests__/versions.test.ts +0 -741
  200. package/src/client/__tests__/docsClientUtils.test.ts +0 -371
  201. package/src/markdown/__tests__/__fixtures__/docs/doc-localized.md +0 -1
  202. package/src/markdown/__tests__/__fixtures__/docs/doc1.md +0 -13
  203. package/src/markdown/__tests__/__fixtures__/docs/doc2.md +0 -12
  204. package/src/markdown/__tests__/__fixtures__/docs/doc4.md +0 -19
  205. package/src/markdown/__tests__/__fixtures__/docs/doc5.md +0 -6
  206. package/src/markdown/__tests__/__fixtures__/docs/subdir/doc3.md +0 -3
  207. package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/doc2.md +0 -7
  208. package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/subdir/doc1.md +0 -3
  209. package/src/markdown/__tests__/__snapshots__/linkify.test.ts.snap +0 -82
  210. package/src/markdown/__tests__/linkify.test.ts +0 -190
  211. package/src/sidebarItemsGenerator.ts +0 -307
  212. package/src/sidebars.ts +0 -522
  213. package/tsconfig.json +0 -9
@@ -0,0 +1,88 @@
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.loadSidebars = exports.loadSidebarsFileUnsafe = exports.resolveSidebarPathOption = exports.DisabledSidebars = exports.DefaultSidebars = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
+ const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
13
+ const validation_1 = require("./validation");
14
+ const normalization_1 = require("./normalization");
15
+ const processor_1 = require("./processor");
16
+ const postProcessor_1 = require("./postProcessor");
17
+ const path_1 = tslib_1.__importDefault(require("path"));
18
+ const utils_1 = require("@docusaurus/utils");
19
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
20
+ const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
21
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
22
+ const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
23
+ exports.DefaultSidebars = {
24
+ defaultSidebar: [
25
+ {
26
+ type: 'autogenerated',
27
+ dirName: '.',
28
+ },
29
+ ],
30
+ };
31
+ exports.DisabledSidebars = {};
32
+ // If a path is provided, make it absolute
33
+ // use this before loadSidebars()
34
+ function resolveSidebarPathOption(siteDir, sidebarPathOption) {
35
+ return sidebarPathOption
36
+ ? path_1.default.resolve(siteDir, sidebarPathOption)
37
+ : sidebarPathOption;
38
+ }
39
+ exports.resolveSidebarPathOption = resolveSidebarPathOption;
40
+ async function readCategoriesMetadata(contentPath) {
41
+ const categoryFiles = await (0, utils_1.Globby)('**/_category_.{json,yml,yaml}', {
42
+ cwd: contentPath,
43
+ });
44
+ const categoryToFile = lodash_1.default.groupBy(categoryFiles, path_1.default.dirname);
45
+ return (0, combine_promises_1.default)(lodash_1.default.mapValues(categoryToFile, async (files, folder) => {
46
+ const [filePath] = files;
47
+ if (files.length > 1) {
48
+ logger_1.default.warn `There are more than one category metadata files for path=${folder}: ${files.join(', ')}. The behavior is undetermined.`;
49
+ }
50
+ const content = await fs_extra_1.default.readFile(path_1.default.join(contentPath, filePath), 'utf-8');
51
+ try {
52
+ return (0, validation_1.validateCategoryMetadataFile)(js_yaml_1.default.load(content));
53
+ }
54
+ catch (err) {
55
+ logger_1.default.error `The docs sidebar category metadata file path=${filePath} looks invalid!`;
56
+ throw err;
57
+ }
58
+ }));
59
+ }
60
+ async function loadSidebarsFileUnsafe(sidebarFilePath) {
61
+ // false => no sidebars
62
+ if (sidebarFilePath === false) {
63
+ return exports.DisabledSidebars;
64
+ }
65
+ // undefined => defaults to autogenerated sidebars
66
+ if (typeof sidebarFilePath === 'undefined') {
67
+ return exports.DefaultSidebars;
68
+ }
69
+ // Non-existent sidebars file: no sidebars
70
+ // Note: this edge case can happen on versioned docs, not current version
71
+ // We avoid creating empty versioned sidebars file with the CLI
72
+ if (!(await fs_extra_1.default.pathExists(sidebarFilePath))) {
73
+ return exports.DisabledSidebars;
74
+ }
75
+ // We don't want sidebars to be cached because of hot reloading.
76
+ return (0, import_fresh_1.default)(sidebarFilePath);
77
+ }
78
+ exports.loadSidebarsFileUnsafe = loadSidebarsFileUnsafe;
79
+ // Note: sidebarFilePath must be absolute, use resolveSidebarPathOption
80
+ async function loadSidebars(sidebarFilePath, options) {
81
+ const sidebarsConfig = await loadSidebarsFileUnsafe(sidebarFilePath);
82
+ const normalizedSidebars = (0, normalization_1.normalizeSidebars)(sidebarsConfig);
83
+ (0, validation_1.validateSidebars)(normalizedSidebars);
84
+ const categoriesMetadata = await readCategoriesMetadata(options.version.contentPath);
85
+ const processedSidebars = await (0, processor_1.processSidebars)(normalizedSidebars, categoriesMetadata, options);
86
+ return (0, postProcessor_1.postProcessSidebars)(processedSidebars, options);
87
+ }
88
+ exports.loadSidebars = loadSidebars;
@@ -0,0 +1,13 @@
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 { NormalizedSidebarItem, NormalizedSidebars, SidebarItemConfig, SidebarsConfig } from './types';
8
+ /**
9
+ * Normalizes recursively item and all its children. Ensures that at the end
10
+ * each item will be an object with the corresponding type.
11
+ */
12
+ export declare function normalizeItem(item: SidebarItemConfig): NormalizedSidebarItem[];
13
+ export declare function normalizeSidebars(sidebars: SidebarsConfig): NormalizedSidebars;
@@ -0,0 +1,55 @@
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.normalizeSidebars = exports.normalizeItem = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const utils_1 = require("./utils");
12
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ function normalizeCategoriesShorthand(sidebar) {
15
+ return Object.entries(sidebar).map(([label, items]) => ({
16
+ type: 'category',
17
+ label,
18
+ items,
19
+ }));
20
+ }
21
+ /**
22
+ * Normalizes recursively item and all its children. Ensures that at the end
23
+ * each item will be an object with the corresponding type.
24
+ */
25
+ function normalizeItem(item) {
26
+ if (typeof item === 'string') {
27
+ return [{ type: 'doc', id: item }];
28
+ }
29
+ if ((0, utils_1.isCategoriesShorthand)(item)) {
30
+ // This will never throw anyways
31
+ return normalizeSidebar(item, 'sidebar items slice');
32
+ }
33
+ if (item.type === 'category') {
34
+ const normalizedCategory = {
35
+ ...item,
36
+ items: normalizeSidebar(item.items, logger_1.default.interpolate `code=${'items'} of the category name=${item.label}`),
37
+ };
38
+ return [normalizedCategory];
39
+ }
40
+ return [item];
41
+ }
42
+ exports.normalizeItem = normalizeItem;
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
+ }
47
+ const normalizedSidebar = Array.isArray(sidebar)
48
+ ? sidebar
49
+ : normalizeCategoriesShorthand(sidebar);
50
+ return normalizedSidebar.flatMap((subItem) => normalizeItem(subItem));
51
+ }
52
+ function normalizeSidebars(sidebars) {
53
+ return lodash_1.default.mapValues(sidebars, (sidebar, id) => normalizeSidebar(sidebar, logger_1.default.interpolate `sidebar name=${id}`));
54
+ }
55
+ exports.normalizeSidebars = normalizeSidebars;
@@ -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 type { Sidebars, SidebarProcessorParams, ProcessedSidebars } from './types';
8
+ export declare function postProcessSidebars(sidebars: ProcessedSidebars, params: SidebarProcessorParams): Sidebars;
@@ -0,0 +1,70 @@
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.postProcessSidebars = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const utils_1 = require("@docusaurus/utils");
12
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
+ function normalizeCategoryLink(category, params) {
14
+ if (category.link?.type === 'generated-index') {
15
+ // default slug logic can be improved
16
+ const getDefaultSlug = () => `/category/${params.categoryLabelSlugger.slug(category.label)}`;
17
+ const slug = category.link.slug ?? getDefaultSlug();
18
+ const permalink = (0, utils_1.normalizeUrl)([params.version.versionPath, slug]);
19
+ return {
20
+ ...category.link,
21
+ slug,
22
+ permalink,
23
+ };
24
+ }
25
+ return category.link;
26
+ }
27
+ function postProcessSidebarItem(item, params) {
28
+ if (item.type === 'category') {
29
+ const category = {
30
+ ...item,
31
+ collapsed: item.collapsed ?? params.sidebarOptions.sidebarCollapsed,
32
+ collapsible: item.collapsible ?? params.sidebarOptions.sidebarCollapsible,
33
+ link: normalizeCategoryLink(item, params),
34
+ items: item.items.map((subItem) => postProcessSidebarItem(subItem, params)),
35
+ };
36
+ // If the current category doesn't have subitems, we render a normal link
37
+ // instead.
38
+ if (category.items.length === 0) {
39
+ if (!category.link) {
40
+ throw new Error(`Sidebar category ${item.label} has neither any subitem nor a link. This makes this item not able to link to anything.`);
41
+ }
42
+ switch (category.link.type) {
43
+ case 'doc':
44
+ return {
45
+ type: 'doc',
46
+ label: category.label,
47
+ id: category.link.id,
48
+ };
49
+ case 'generated-index':
50
+ return {
51
+ type: 'link',
52
+ label: category.label,
53
+ href: category.link.permalink,
54
+ };
55
+ default:
56
+ throw new Error('Unexpected sidebar category link type');
57
+ }
58
+ }
59
+ // A non-collapsible category can't be collapsed!
60
+ if (category.collapsible === false) {
61
+ category.collapsed = false;
62
+ }
63
+ return category;
64
+ }
65
+ return item;
66
+ }
67
+ function postProcessSidebars(sidebars, params) {
68
+ return lodash_1.default.mapValues(sidebars, (sidebar) => sidebar.map((item) => postProcessSidebarItem(item, params)));
69
+ }
70
+ exports.postProcessSidebars = postProcessSidebars;
@@ -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 type { NormalizedSidebars, ProcessedSidebars, SidebarProcessorParams, CategoryMetadataFile } from './types';
8
+ export declare function processSidebars(unprocessedSidebars: NormalizedSidebars, categoriesMetadata: Record<string, CategoryMetadataFile>, params: SidebarProcessorParams): Promise<ProcessedSidebars>;
@@ -0,0 +1,79 @@
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.processSidebars = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const generator_1 = require("./generator");
12
+ const validation_1 = require("./validation");
13
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
14
+ const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
15
+ const docs_1 = require("../docs");
16
+ function toSidebarItemsGeneratorDoc(doc) {
17
+ return lodash_1.default.pick(doc, [
18
+ 'id',
19
+ 'unversionedId',
20
+ 'frontMatter',
21
+ 'source',
22
+ 'sourceDirName',
23
+ 'sidebarPosition',
24
+ ]);
25
+ }
26
+ function toSidebarItemsGeneratorVersion(version) {
27
+ return lodash_1.default.pick(version, ['versionName', 'contentPath']);
28
+ }
29
+ // Handle the generation of autogenerated sidebar items and other
30
+ // post-processing checks
31
+ async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
32
+ const { sidebarItemsGenerator, numberPrefixParser, docs, version, sidebarOptions, } = params;
33
+ // Just a minor lazy transformation optimization
34
+ const getSidebarItemsGeneratorDocsAndVersion = lodash_1.default.memoize(() => ({
35
+ docs: docs.map(toSidebarItemsGeneratorDoc),
36
+ version: toSidebarItemsGeneratorVersion(version),
37
+ }));
38
+ async function processAutoGeneratedItem(item) {
39
+ const generatedItems = await sidebarItemsGenerator({
40
+ item,
41
+ numberPrefixParser,
42
+ defaultSidebarItemsGenerator: generator_1.DefaultSidebarItemsGenerator,
43
+ isCategoryIndex: docs_1.isCategoryIndex,
44
+ ...getSidebarItemsGeneratorDocsAndVersion(),
45
+ options: sidebarOptions,
46
+ categoriesMetadata,
47
+ });
48
+ // Process again... weird but sidebar item generated might generate some
49
+ // auto-generated items?
50
+ // TODO repeatedly process & unwrap autogenerated items until there are no
51
+ // more autogenerated items, or when loop count (e.g. 10) is reached
52
+ return processItems(generatedItems);
53
+ }
54
+ async function processItem(item) {
55
+ if (item.type === 'category') {
56
+ return [
57
+ {
58
+ ...item,
59
+ items: (await Promise.all(item.items.map(processItem))).flat(),
60
+ },
61
+ ];
62
+ }
63
+ if (item.type === 'autogenerated') {
64
+ return processAutoGeneratedItem(item);
65
+ }
66
+ return [item];
67
+ }
68
+ async function processItems(items) {
69
+ return (await Promise.all(items.map(processItem))).flat();
70
+ }
71
+ const processedSidebar = await processItems(unprocessedSidebar);
72
+ return processedSidebar;
73
+ }
74
+ async function processSidebars(unprocessedSidebars, categoriesMetadata, params) {
75
+ const processedSidebars = await (0, combine_promises_1.default)(lodash_1.default.mapValues(unprocessedSidebars, (unprocessedSidebar) => processSidebar(unprocessedSidebar, categoriesMetadata, params)));
76
+ (0, validation_1.validateSidebars)(processedSidebars);
77
+ return processedSidebars;
78
+ }
79
+ exports.processSidebars = processSidebars;
@@ -0,0 +1,166 @@
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 { Optional, Required } from 'utility-types';
8
+ import type { DocMetadataBase, VersionMetadata } from '../types';
9
+ import type { NumberPrefixParser, SidebarOptions, CategoryIndexMatcher } from '@docusaurus/plugin-content-docs';
10
+ import type { Slugger } from '@docusaurus/utils';
11
+ declare type Expand<T extends Record<string, unknown>> = {
12
+ [P in keyof T]: T[P];
13
+ };
14
+ export declare type SidebarItemBase = {
15
+ className?: string;
16
+ customProps?: Record<string, unknown>;
17
+ };
18
+ export declare type SidebarItemDoc = SidebarItemBase & {
19
+ type: 'doc' | 'ref';
20
+ label?: string;
21
+ id: string;
22
+ };
23
+ export declare type SidebarItemHtml = SidebarItemBase & {
24
+ type: 'html';
25
+ value: string;
26
+ defaultStyle?: boolean;
27
+ };
28
+ export declare type SidebarItemLink = SidebarItemBase & {
29
+ type: 'link';
30
+ href: string;
31
+ label: string;
32
+ };
33
+ export declare type SidebarItemAutogenerated = SidebarItemBase & {
34
+ type: 'autogenerated';
35
+ dirName: string;
36
+ };
37
+ declare type SidebarItemCategoryBase = SidebarItemBase & {
38
+ type: 'category';
39
+ label: string;
40
+ collapsed: boolean;
41
+ collapsible: boolean;
42
+ };
43
+ export declare type SidebarItemCategoryLinkDoc = {
44
+ type: 'doc';
45
+ id: string;
46
+ };
47
+ export declare type SidebarItemCategoryLinkGeneratedIndexConfig = {
48
+ type: 'generated-index';
49
+ slug?: string;
50
+ title?: string;
51
+ description?: string;
52
+ image?: string;
53
+ keywords?: string | readonly string[];
54
+ };
55
+ export declare type SidebarItemCategoryLinkGeneratedIndex = {
56
+ type: 'generated-index';
57
+ slug: string;
58
+ permalink: string;
59
+ title?: string;
60
+ description?: string;
61
+ image?: string;
62
+ keywords?: string | readonly string[];
63
+ };
64
+ export declare type SidebarItemCategoryLinkConfig = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndexConfig;
65
+ export declare type SidebarItemCategoryLink = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndex;
66
+ export declare type SidebarItemCategoryConfig = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
67
+ items: SidebarCategoriesShorthand | SidebarItemConfig[];
68
+ link?: SidebarItemCategoryLinkConfig;
69
+ }>;
70
+ export declare type SidebarCategoriesShorthand = {
71
+ [sidebarCategory: string]: SidebarCategoriesShorthand | SidebarItemConfig[];
72
+ };
73
+ export declare type SidebarItemConfig = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | SidebarItemAutogenerated | SidebarItemCategoryConfig | string | SidebarCategoriesShorthand;
74
+ export declare type SidebarConfig = SidebarCategoriesShorthand | SidebarItemConfig[];
75
+ export declare type SidebarsConfig = {
76
+ [sidebarId: string]: SidebarConfig;
77
+ };
78
+ export declare type NormalizedSidebarItemCategory = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
79
+ items: NormalizedSidebarItem[];
80
+ link?: SidebarItemCategoryLinkConfig;
81
+ }>;
82
+ export declare type NormalizedSidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | NormalizedSidebarItemCategory | SidebarItemAutogenerated;
83
+ export declare type NormalizedSidebar = NormalizedSidebarItem[];
84
+ export declare type NormalizedSidebars = {
85
+ [sidebarId: string]: NormalizedSidebar;
86
+ };
87
+ export declare type ProcessedSidebarItemCategory = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
88
+ items: ProcessedSidebarItem[];
89
+ link?: SidebarItemCategoryLinkConfig;
90
+ }>;
91
+ export declare type ProcessedSidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | ProcessedSidebarItemCategory;
92
+ export declare type ProcessedSidebar = ProcessedSidebarItem[];
93
+ export declare type ProcessedSidebars = {
94
+ [sidebarId: string]: ProcessedSidebar;
95
+ };
96
+ export declare type SidebarItemCategory = Expand<SidebarItemCategoryBase & {
97
+ items: SidebarItem[];
98
+ link?: SidebarItemCategoryLink;
99
+ }>;
100
+ export declare type SidebarItemCategoryWithLink = Required<SidebarItemCategory, 'link'>;
101
+ export declare type SidebarItemCategoryWithGeneratedIndex = SidebarItemCategoryWithLink & {
102
+ link: SidebarItemCategoryLinkGeneratedIndex;
103
+ };
104
+ export declare type SidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | SidebarItemCategory;
105
+ export declare type SidebarNavigationItem = SidebarItemDoc | SidebarItemCategoryWithLink;
106
+ export declare type Sidebar = SidebarItem[];
107
+ export declare type SidebarItemType = SidebarItem['type'];
108
+ export declare type Sidebars = {
109
+ [sidebarId: string]: Sidebar;
110
+ };
111
+ export declare type PropSidebarItemCategory = Expand<SidebarItemCategoryBase & {
112
+ items: PropSidebarItem[];
113
+ href?: string;
114
+ }>;
115
+ export declare type PropSidebarItemLink = SidebarItemLink & {
116
+ docId?: string;
117
+ };
118
+ export declare type PropSidebarItemHtml = SidebarItemHtml;
119
+ export declare type PropSidebarItem = PropSidebarItemLink | PropSidebarItemCategory | PropSidebarItemHtml;
120
+ export declare type PropSidebar = PropSidebarItem[];
121
+ export declare type PropSidebars = {
122
+ [sidebarId: string]: PropSidebar;
123
+ };
124
+ export declare type PropSidebarBreadcrumbsItem = PropSidebarItemLink | PropSidebarItemCategory;
125
+ export declare type PropVersionDoc = {
126
+ id: string;
127
+ title: string;
128
+ description?: string;
129
+ sidebar?: string;
130
+ };
131
+ export declare type PropVersionDocs = {
132
+ [docId: string]: PropVersionDoc;
133
+ };
134
+ export declare type CategoryMetadataFile = {
135
+ label?: string;
136
+ position?: number;
137
+ collapsed?: boolean;
138
+ collapsible?: boolean;
139
+ className?: string;
140
+ link?: SidebarItemCategoryLinkConfig | null;
141
+ };
142
+ export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'unversionedId' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
143
+ export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
144
+ export declare type SidebarItemsGeneratorArgs = {
145
+ item: SidebarItemAutogenerated;
146
+ version: SidebarItemsGeneratorVersion;
147
+ docs: SidebarItemsGeneratorDoc[];
148
+ numberPrefixParser: NumberPrefixParser;
149
+ isCategoryIndex: CategoryIndexMatcher;
150
+ categoriesMetadata: Record<string, CategoryMetadataFile>;
151
+ options: SidebarOptions;
152
+ };
153
+ export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<NormalizedSidebar>;
154
+ export declare type SidebarItemsGeneratorOptionArgs = {
155
+ defaultSidebarItemsGenerator: SidebarItemsGenerator;
156
+ } & SidebarItemsGeneratorArgs;
157
+ export declare type SidebarItemsGeneratorOption = (generatorArgs: SidebarItemsGeneratorOptionArgs) => Promise<NormalizedSidebarItem[]>;
158
+ export declare type SidebarProcessorParams = {
159
+ sidebarItemsGenerator: SidebarItemsGeneratorOption;
160
+ numberPrefixParser: NumberPrefixParser;
161
+ docs: DocMetadataBase[];
162
+ version: VersionMetadata;
163
+ categoryLabelSlugger: Slugger;
164
+ sidebarOptions: SidebarOptions;
165
+ };
166
+ export {};
@@ -1,16 +1,8 @@
1
+ "use strict";
1
2
  /**
2
3
  * Copyright (c) Facebook, Inc. and its affiliates.
3
4
  *
4
5
  * This source code is licensed under the MIT license found in the
5
6
  * LICENSE file in the root directory of this source tree.
6
7
  */
7
-
8
- module.exports = {
9
- someSidebar: [
10
- {type: 'doc', id: 'API/api-end'},
11
- {
12
- type: 'autogenerated',
13
- dirName: '3-API',
14
- },
15
- ],
16
- };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,43 @@
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, SidebarCategoriesShorthand, SidebarItemConfig, SidebarItemCategoryWithGeneratedIndex, SidebarNavigationItem } from './types';
8
+ import type { DocMetadataBase, DocNavLink } from '../types';
9
+ export declare function isCategoriesShorthand(item: SidebarItemConfig): item is SidebarCategoriesShorthand;
10
+ export declare function transformSidebarItems(sidebar: Sidebar, updateFn: (item: SidebarItem) => SidebarItem): Sidebar;
11
+ export declare function collectSidebarDocItems(sidebar: Sidebar): SidebarItemDoc[];
12
+ export declare function collectSidebarCategories(sidebar: Sidebar): SidebarItemCategory[];
13
+ export declare function collectSidebarLinks(sidebar: Sidebar): SidebarItemLink[];
14
+ export declare function collectSidebarDocIds(sidebar: Sidebar): string[];
15
+ export declare function collectSidebarNavigation(sidebar: Sidebar): SidebarNavigationItem[];
16
+ export declare function collectSidebarsDocIds(sidebars: Sidebars): Record<string, string[]>;
17
+ export declare function collectSidebarsNavigations(sidebars: Sidebars): Record<string, SidebarNavigationItem[]>;
18
+ export declare type SidebarNavigation = {
19
+ sidebarName: string | undefined;
20
+ previous: SidebarNavigationItem | undefined;
21
+ next: SidebarNavigationItem | undefined;
22
+ };
23
+ export declare type SidebarsUtils = {
24
+ sidebars: Sidebars;
25
+ getFirstDocIdOfFirstSidebar: () => string | undefined;
26
+ getSidebarNameByDocId: (docId: string) => string | undefined;
27
+ getDocNavigation: (unversionedId: string, versionedId: string, displayedSidebar: string | null | undefined) => SidebarNavigation;
28
+ getCategoryGeneratedIndexList: () => SidebarItemCategoryWithGeneratedIndex[];
29
+ getCategoryGeneratedIndexNavigation: (categoryGeneratedIndexPermalink: string) => SidebarNavigation;
30
+ getFirstLink: (sidebarId: string) => {
31
+ type: 'doc';
32
+ id: string;
33
+ label: string;
34
+ } | {
35
+ type: 'generated-index';
36
+ slug: string;
37
+ label: string;
38
+ } | undefined;
39
+ checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
40
+ };
41
+ export declare function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils;
42
+ export declare function toDocNavigationLink(doc: DocMetadataBase): DocNavLink;
43
+ export declare function toNavigationLink(navigationItem: SidebarNavigationItem | undefined, docsById: Record<string, DocMetadataBase>): DocNavLink | undefined;