@docusaurus/plugin-content-docs 2.0.0-beta.2 → 2.0.0-beta.20

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 (229) hide show
  1. package/lib/categoryGeneratedIndex.d.ts +12 -0
  2. package/lib/categoryGeneratedIndex.js +37 -0
  3. package/lib/cli.d.ts +3 -2
  4. package/lib/cli.js +60 -69
  5. package/lib/client/docsClientUtils.d.ts +9 -28
  6. package/lib/client/docsClientUtils.js +33 -34
  7. package/lib/client/index.d.ts +22 -0
  8. package/lib/client/index.js +72 -0
  9. package/lib/constants.d.ts +4 -0
  10. package/lib/constants.js +4 -1
  11. package/lib/docs.d.ts +32 -3
  12. package/lib/docs.js +164 -63
  13. package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docusaurus.config.js → lib/frontMatter.d.ts} +4 -8
  14. package/lib/{docFrontMatter.js → frontMatter.js} +13 -4
  15. package/lib/globalData.d.ts +3 -3
  16. package/lib/globalData.js +35 -6
  17. package/lib/index.d.ts +3 -3
  18. package/lib/index.js +122 -148
  19. package/lib/lastUpdate.d.ts +4 -6
  20. package/lib/lastUpdate.js +22 -26
  21. package/lib/markdown/index.d.ts +3 -6
  22. package/lib/markdown/index.js +3 -3
  23. package/lib/markdown/linkify.d.ts +1 -1
  24. package/lib/markdown/linkify.js +6 -3
  25. package/lib/numberPrefix.d.ts +1 -1
  26. package/lib/numberPrefix.js +16 -21
  27. package/lib/options.d.ts +3 -5
  28. package/lib/options.js +54 -13
  29. package/lib/props.d.ts +7 -2
  30. package/lib/props.js +69 -13
  31. package/lib/routes.d.ts +29 -0
  32. package/lib/routes.js +96 -0
  33. package/lib/server-export.d.ts +9 -0
  34. package/lib/server-export.js +22 -0
  35. package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +1 -6
  36. package/lib/sidebars/generator.js +209 -0
  37. package/lib/sidebars/index.d.ts +13 -0
  38. package/lib/sidebars/index.js +92 -0
  39. package/lib/sidebars/normalization.d.ts +13 -0
  40. package/lib/sidebars/normalization.js +55 -0
  41. package/lib/sidebars/postProcessor.d.ts +8 -0
  42. package/lib/sidebars/postProcessor.js +65 -0
  43. package/lib/sidebars/processor.d.ts +10 -0
  44. package/lib/sidebars/processor.js +90 -0
  45. package/lib/sidebars/types.d.ts +178 -0
  46. package/lib/{docFrontMatter.d.ts → sidebars/types.js} +2 -2
  47. package/lib/sidebars/utils.d.ts +54 -0
  48. package/lib/sidebars/utils.js +255 -0
  49. package/lib/sidebars/validation.d.ts +11 -0
  50. package/lib/sidebars/validation.js +138 -0
  51. package/lib/slug.d.ts +5 -4
  52. package/lib/slug.js +28 -18
  53. package/{src/__tests__/__fixtures__/sidebars/sidebars-first-level-not-category.js → lib/tags.d.ts} +3 -14
  54. package/lib/tags.js +21 -0
  55. package/lib/translations.d.ts +3 -3
  56. package/lib/translations.js +84 -94
  57. package/lib/types.d.ts +13 -184
  58. package/lib/versions/files.d.ts +44 -0
  59. package/lib/versions/files.js +142 -0
  60. package/lib/versions/index.d.ts +36 -0
  61. package/lib/versions/index.js +155 -0
  62. package/lib/versions/validation.d.ts +17 -0
  63. package/lib/versions/validation.js +71 -0
  64. package/package.json +32 -27
  65. package/src/categoryGeneratedIndex.ts +60 -0
  66. package/src/cli.ts +84 -109
  67. package/src/client/docsClientUtils.ts +43 -70
  68. package/src/client/index.ts +103 -0
  69. package/src/constants.ts +4 -2
  70. package/{types.d.ts → src/deps.d.ts} +1 -1
  71. package/src/docs.ts +228 -65
  72. package/src/{docFrontMatter.ts → frontMatter.ts} +21 -11
  73. package/src/globalData.ts +57 -7
  74. package/src/index.ts +169 -210
  75. package/src/lastUpdate.ts +26 -37
  76. package/src/markdown/index.ts +10 -16
  77. package/src/markdown/linkify.ts +7 -4
  78. package/src/numberPrefix.ts +19 -26
  79. package/src/options.ts +60 -18
  80. package/src/plugin-content-docs.d.ts +625 -89
  81. package/src/props.ts +102 -20
  82. package/src/routes.ts +159 -0
  83. package/src/server-export.ts +22 -0
  84. package/src/sidebars/README.md +9 -0
  85. package/src/sidebars/generator.ts +292 -0
  86. package/src/sidebars/index.ts +118 -0
  87. package/src/sidebars/normalization.ts +85 -0
  88. package/src/sidebars/postProcessor.ts +89 -0
  89. package/src/sidebars/processor.ts +139 -0
  90. package/src/sidebars/types.ts +275 -0
  91. package/src/sidebars/utils.ts +391 -0
  92. package/src/sidebars/validation.ts +174 -0
  93. package/src/slug.ts +41 -22
  94. package/src/tags.ts +20 -0
  95. package/src/translations.ts +124 -117
  96. package/src/types.ts +18 -247
  97. package/src/versions/files.ts +220 -0
  98. package/src/versions/index.ts +247 -0
  99. package/src/versions/validation.ts +113 -0
  100. package/lib/.tsbuildinfo +0 -1
  101. package/lib/sidebarItemsGenerator.js +0 -211
  102. package/lib/sidebars.d.ts +0 -43
  103. package/lib/sidebars.js +0 -320
  104. package/lib/theme/hooks/useDocs.d.ts +0 -20
  105. package/lib/theme/hooks/useDocs.js +0 -72
  106. package/lib/versions.d.ts +0 -16
  107. package/lib/versions.js +0 -319
  108. package/src/__tests__/__fixtures__/bad-id-site/docs/invalid-id.md +0 -5
  109. package/src/__tests__/__fixtures__/bad-slug-on-doc-home-site/docs/docWithSlug.md +0 -5
  110. package/src/__tests__/__fixtures__/empty-site/docusaurus.config.js +0 -16
  111. package/src/__tests__/__fixtures__/empty-site/sidebars.json +0 -1
  112. package/src/__tests__/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -34
  113. package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -11
  114. package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -11
  115. package/src/__tests__/__fixtures__/sidebars/sidebars-category.js +0 -44
  116. package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -20
  117. package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed.json +0 -21
  118. package/src/__tests__/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -10
  119. package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -11
  120. package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -11
  121. package/src/__tests__/__fixtures__/sidebars/sidebars-link.json +0 -11
  122. package/src/__tests__/__fixtures__/sidebars/sidebars-unknown-type.json +0 -14
  123. package/src/__tests__/__fixtures__/sidebars/sidebars-wrong-field.json +0 -20
  124. package/src/__tests__/__fixtures__/sidebars/sidebars.json +0 -20
  125. package/src/__tests__/__fixtures__/simple-site/docs/foo/bar.md +0 -69
  126. package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +0 -70
  127. package/src/__tests__/__fixtures__/simple-site/docs/headingAsTitle.md +0 -1
  128. package/src/__tests__/__fixtures__/simple-site/docs/hello.md +0 -53
  129. package/src/__tests__/__fixtures__/simple-site/docs/ipsum.md +0 -5
  130. package/src/__tests__/__fixtures__/simple-site/docs/lorem.md +0 -6
  131. package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +0 -5
  132. package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +0 -5
  133. package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +0 -5
  134. package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +0 -5
  135. package/src/__tests__/__fixtures__/simple-site/docs/slugs/absoluteSlug.md +0 -5
  136. package/src/__tests__/__fixtures__/simple-site/docs/slugs/relativeSlug.md +0 -5
  137. package/src/__tests__/__fixtures__/simple-site/docs/slugs/resolvedSlug.md +0 -5
  138. package/src/__tests__/__fixtures__/simple-site/docs/slugs/tryToEscapeSlug.md +0 -5
  139. package/src/__tests__/__fixtures__/simple-site/docusaurus.config.js +0 -14
  140. package/src/__tests__/__fixtures__/simple-site/sidebars.json +0 -23
  141. package/src/__tests__/__fixtures__/simple-site/wrong-sidebars.json +0 -7
  142. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/0-getting-started.md +0 -3
  143. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/1-installation.md +0 -3
  144. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/00_api-overview.md +0 -3
  145. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/0 --- Client API.md +0 -1
  146. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/1 --- Server API.md +0 -1
  147. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/0. Plugin API.md +0 -1
  148. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/1. Theme API.md +0 -1
  149. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/_category_.yml +0 -1
  150. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/03_api-end.md +0 -3
  151. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/_category_.json +0 -3
  152. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/0-guide2.5.md +0 -8
  153. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/02-guide2.md +0 -7
  154. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/_category_.json +0 -3
  155. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/a-guide4.md +0 -7
  156. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/b-guide5.md +0 -7
  157. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/guide3.md +0 -8
  158. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/z-guide1.md +0 -8
  159. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars.js +0 -23
  160. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js +0 -16
  161. package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-1.md +0 -7
  162. package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-2.md +0 -8
  163. package/src/__tests__/__fixtures__/site-with-doc-label/docusaurus.config.js +0 -14
  164. package/src/__tests__/__fixtures__/site-with-doc-label/sidebars.json +0 -14
  165. package/src/__tests__/__fixtures__/versioned-site/community/team.md +0 -1
  166. package/src/__tests__/__fixtures__/versioned-site/community_sidebars.json +0 -3
  167. package/src/__tests__/__fixtures__/versioned-site/community_versioned_docs/version-1.0.0/team.md +0 -1
  168. package/src/__tests__/__fixtures__/versioned-site/community_versioned_sidebars/version-1.0.0-sidebars.json +0 -3
  169. package/src/__tests__/__fixtures__/versioned-site/community_versions.json +0 -1
  170. package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +0 -4
  171. package/src/__tests__/__fixtures__/versioned-site/docs/hello.md +0 -1
  172. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/absoluteSlug.md +0 -5
  173. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/relativeSlug.md +0 -5
  174. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/resolvedSlug.md +0 -5
  175. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/tryToEscapeSlug.md +0 -5
  176. package/src/__tests__/__fixtures__/versioned-site/docusaurus.config.js +0 -18
  177. package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
  178. package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs-community/current/team.md +0 -5
  179. package/src/__tests__/__fixtures__/versioned-site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
  180. package/src/__tests__/__fixtures__/versioned-site/sidebars.json +0 -10
  181. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/bar.md +0 -4
  182. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/baz.md +0 -1
  183. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md +0 -1
  184. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/foo/bar.md +0 -1
  185. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md +0 -1
  186. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootAbsoluteSlug.md +0 -5
  187. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootRelativeSlug.md +0 -5
  188. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootResolvedSlug.md +0 -5
  189. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootTryToEscapeSlug.md +0 -5
  190. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/absoluteSlug.md +0 -5
  191. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/relativeSlug.md +0 -5
  192. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/resolvedSlug.md +0 -5
  193. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/tryToEscapeSlug.md +0 -5
  194. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.0-sidebars.json +0 -11
  195. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +0 -10
  196. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-withSlugs-sidebars.json +0 -5
  197. package/src/__tests__/__fixtures__/versioned-site/versions.json +0 -5
  198. package/src/__tests__/__snapshots__/cli.test.ts.snap +0 -90
  199. package/src/__tests__/__snapshots__/index.test.ts.snap +0 -1916
  200. package/src/__tests__/__snapshots__/sidebars.test.ts.snap +0 -218
  201. package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -487
  202. package/src/__tests__/cli.test.ts +0 -333
  203. package/src/__tests__/docFrontMatter.test.ts +0 -244
  204. package/src/__tests__/docs.test.ts +0 -878
  205. package/src/__tests__/index.test.ts +0 -1871
  206. package/src/__tests__/lastUpdate.test.ts +0 -69
  207. package/src/__tests__/numberPrefix.test.ts +0 -199
  208. package/src/__tests__/options.test.ts +0 -231
  209. package/src/__tests__/sidebarItemsGenerator.test.ts +0 -336
  210. package/src/__tests__/sidebars.test.ts +0 -639
  211. package/src/__tests__/slug.test.ts +0 -109
  212. package/src/__tests__/translations.test.ts +0 -159
  213. package/src/__tests__/versions.test.ts +0 -741
  214. package/src/client/__tests__/docsClientUtils.test.ts +0 -371
  215. package/src/markdown/__tests__/__fixtures__/docs/doc-localized.md +0 -1
  216. package/src/markdown/__tests__/__fixtures__/docs/doc1.md +0 -13
  217. package/src/markdown/__tests__/__fixtures__/docs/doc2.md +0 -12
  218. package/src/markdown/__tests__/__fixtures__/docs/doc4.md +0 -19
  219. package/src/markdown/__tests__/__fixtures__/docs/doc5.md +0 -6
  220. package/src/markdown/__tests__/__fixtures__/docs/subdir/doc3.md +0 -3
  221. package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/doc2.md +0 -7
  222. package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/subdir/doc1.md +0 -3
  223. package/src/markdown/__tests__/__snapshots__/linkify.test.ts.snap +0 -82
  224. package/src/markdown/__tests__/linkify.test.ts +0 -190
  225. package/src/sidebarItemsGenerator.ts +0 -307
  226. package/src/sidebars.ts +0 -522
  227. package/src/theme/hooks/useDocs.ts +0 -99
  228. package/src/versions.ts +0 -572
  229. package/tsconfig.json +0 -9
@@ -0,0 +1,92 @@
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
+ function resolveSidebarPathOption(siteDir, sidebarPathOption) {
34
+ return sidebarPathOption
35
+ ? path_1.default.resolve(siteDir, sidebarPathOption)
36
+ : sidebarPathOption;
37
+ }
38
+ exports.resolveSidebarPathOption = resolveSidebarPathOption;
39
+ async function readCategoriesMetadata(contentPath) {
40
+ const categoryFiles = await (0, utils_1.Globby)('**/_category_.{json,yml,yaml}', {
41
+ cwd: contentPath,
42
+ });
43
+ const categoryToFile = lodash_1.default.groupBy(categoryFiles, path_1.default.dirname);
44
+ return (0, combine_promises_1.default)(lodash_1.default.mapValues(categoryToFile, async (files, folder) => {
45
+ const filePath = files[0];
46
+ if (files.length > 1) {
47
+ logger_1.default.warn `There are more than one category metadata files for path=${folder}: ${files.join(', ')}. The behavior is undetermined.`;
48
+ }
49
+ const content = await fs_extra_1.default.readFile(path_1.default.join(contentPath, filePath), 'utf-8');
50
+ try {
51
+ return (0, validation_1.validateCategoryMetadataFile)(js_yaml_1.default.load(content));
52
+ }
53
+ catch (err) {
54
+ logger_1.default.error `The docs sidebar category metadata file path=${filePath} looks invalid!`;
55
+ throw err;
56
+ }
57
+ }));
58
+ }
59
+ async function loadSidebarsFileUnsafe(sidebarFilePath) {
60
+ // false => no sidebars
61
+ if (sidebarFilePath === false) {
62
+ return exports.DisabledSidebars;
63
+ }
64
+ // undefined => defaults to autogenerated sidebars
65
+ if (typeof sidebarFilePath === 'undefined') {
66
+ return exports.DefaultSidebars;
67
+ }
68
+ // Non-existent sidebars file: no sidebars
69
+ // Note: this edge case can happen on versioned docs, not current version
70
+ // We avoid creating empty versioned sidebars file with the CLI
71
+ if (!(await fs_extra_1.default.pathExists(sidebarFilePath))) {
72
+ return exports.DisabledSidebars;
73
+ }
74
+ // We don't want sidebars to be cached because of hot reloading.
75
+ return (0, import_fresh_1.default)(sidebarFilePath);
76
+ }
77
+ exports.loadSidebarsFileUnsafe = loadSidebarsFileUnsafe;
78
+ async function loadSidebars(sidebarFilePath, options) {
79
+ try {
80
+ const sidebarsConfig = await loadSidebarsFileUnsafe(sidebarFilePath);
81
+ const normalizedSidebars = (0, normalization_1.normalizeSidebars)(sidebarsConfig);
82
+ (0, validation_1.validateSidebars)(normalizedSidebars);
83
+ const categoriesMetadata = await readCategoriesMetadata(options.version.contentPath);
84
+ const processedSidebars = await (0, processor_1.processSidebars)(normalizedSidebars, categoriesMetadata, options);
85
+ return (0, postProcessor_1.postProcessSidebars)(processedSidebars, options);
86
+ }
87
+ catch (err) {
88
+ logger_1.default.error `Sidebars file at path=${sidebarFilePath} failed to be loaded.`;
89
+ throw err;
90
+ }
91
+ }
92
+ 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 url=${'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,65 @@
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.path, 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
+ return category.link.type === 'doc'
43
+ ? {
44
+ type: 'doc',
45
+ label: category.label,
46
+ id: category.link.id,
47
+ }
48
+ : {
49
+ type: 'link',
50
+ label: category.label,
51
+ href: category.link.permalink,
52
+ };
53
+ }
54
+ // A non-collapsible category can't be collapsed!
55
+ if (category.collapsible === false) {
56
+ category.collapsed = false;
57
+ }
58
+ return category;
59
+ }
60
+ return item;
61
+ }
62
+ function postProcessSidebars(sidebars, params) {
63
+ return lodash_1.default.mapValues(sidebars, (sidebar) => sidebar.map((item) => postProcessSidebarItem(item, params)));
64
+ }
65
+ exports.postProcessSidebars = postProcessSidebars;
@@ -0,0 +1,10 @@
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: {
9
+ [filePath: string]: CategoryMetadataFile;
10
+ }, params: SidebarProcessorParams): Promise<ProcessedSidebars>;
@@ -0,0 +1,90 @@
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
+ 'title',
21
+ 'frontMatter',
22
+ 'source',
23
+ 'sourceDirName',
24
+ 'sidebarPosition',
25
+ ]);
26
+ }
27
+ function toSidebarItemsGeneratorVersion(version) {
28
+ return lodash_1.default.pick(version, ['versionName', 'contentPath']);
29
+ }
30
+ // Handle the generation of autogenerated sidebar items and other
31
+ // post-processing checks
32
+ async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
33
+ const { sidebarItemsGenerator, numberPrefixParser, docs, drafts, version } = params;
34
+ // Just a minor lazy transformation optimization
35
+ const getSidebarItemsGeneratorDocsAndVersion = lodash_1.default.memoize(() => ({
36
+ docs: docs.map(toSidebarItemsGeneratorDoc),
37
+ version: toSidebarItemsGeneratorVersion(version),
38
+ }));
39
+ async function processAutoGeneratedItem(item) {
40
+ const generatedItems = await sidebarItemsGenerator({
41
+ item,
42
+ numberPrefixParser,
43
+ defaultSidebarItemsGenerator: generator_1.DefaultSidebarItemsGenerator,
44
+ isCategoryIndex: docs_1.isCategoryIndex,
45
+ ...getSidebarItemsGeneratorDocsAndVersion(),
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
+ const draftIds = new Set(drafts.flatMap(docs_1.getDocIds));
55
+ const isDraftItem = (item) => {
56
+ if (item.type === 'doc' || item.type === 'ref') {
57
+ return draftIds.has(item.id);
58
+ }
59
+ // If a category only contains draft items, it should be filtered entirely.
60
+ if (item.type === 'category') {
61
+ return item.items.every(isDraftItem);
62
+ }
63
+ return false;
64
+ };
65
+ async function processItem(item) {
66
+ if (item.type === 'category') {
67
+ return [
68
+ {
69
+ ...item,
70
+ items: await processItems(item.items),
71
+ },
72
+ ];
73
+ }
74
+ if (item.type === 'autogenerated') {
75
+ return processAutoGeneratedItem(item);
76
+ }
77
+ return [item];
78
+ }
79
+ async function processItems(items) {
80
+ return (await Promise.all(items.filter((i) => !isDraftItem(i)).map(processItem))).flat();
81
+ }
82
+ const processedSidebar = await processItems(unprocessedSidebar);
83
+ return processedSidebar;
84
+ }
85
+ async function processSidebars(unprocessedSidebars, categoriesMetadata, params) {
86
+ const processedSidebars = await (0, combine_promises_1.default)(lodash_1.default.mapValues(unprocessedSidebars, (unprocessedSidebar) => processSidebar(unprocessedSidebar, categoriesMetadata, params)));
87
+ (0, validation_1.validateSidebars)(processedSidebars);
88
+ return processedSidebars;
89
+ }
90
+ exports.processSidebars = processSidebars;
@@ -0,0 +1,178 @@
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 { NumberPrefixParser, SidebarOptions, CategoryIndexMatcher, DocMetadataBase, VersionMetadata } from '@docusaurus/plugin-content-docs';
9
+ import type { Slugger } from '@docusaurus/utils';
10
+ declare type Expand<T extends {
11
+ [x: string]: unknown;
12
+ }> = {
13
+ [P in keyof T]: T[P];
14
+ };
15
+ export declare type SidebarItemBase = {
16
+ className?: string;
17
+ customProps?: {
18
+ [key: string]: unknown;
19
+ };
20
+ };
21
+ export declare type SidebarItemDoc = SidebarItemBase & {
22
+ type: 'doc' | 'ref';
23
+ label?: string;
24
+ id: string;
25
+ };
26
+ export declare type SidebarItemHtml = SidebarItemBase & {
27
+ type: 'html';
28
+ value: string;
29
+ defaultStyle?: boolean;
30
+ };
31
+ export declare type SidebarItemLink = SidebarItemBase & {
32
+ type: 'link';
33
+ href: string;
34
+ label: string;
35
+ };
36
+ export declare type SidebarItemAutogenerated = SidebarItemBase & {
37
+ type: 'autogenerated';
38
+ dirName: string;
39
+ };
40
+ declare type SidebarItemCategoryBase = SidebarItemBase & {
41
+ type: 'category';
42
+ label: string;
43
+ collapsed: boolean;
44
+ collapsible: boolean;
45
+ };
46
+ export declare type SidebarItemCategoryLinkDoc = {
47
+ type: 'doc';
48
+ id: string;
49
+ };
50
+ export declare type SidebarItemCategoryLinkGeneratedIndexConfig = {
51
+ type: 'generated-index';
52
+ slug?: string;
53
+ title?: string;
54
+ description?: string;
55
+ image?: string;
56
+ keywords?: string | readonly string[];
57
+ };
58
+ export declare type SidebarItemCategoryLinkGeneratedIndex = {
59
+ type: 'generated-index';
60
+ slug: string;
61
+ permalink: string;
62
+ title?: string;
63
+ description?: string;
64
+ image?: string;
65
+ keywords?: string | readonly string[];
66
+ };
67
+ export declare type SidebarItemCategoryLinkConfig = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndexConfig;
68
+ export declare type SidebarItemCategoryLink = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndex;
69
+ export declare type SidebarItemCategoryConfig = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
70
+ items: SidebarCategoriesShorthand | SidebarItemConfig[];
71
+ link?: SidebarItemCategoryLinkConfig;
72
+ }>;
73
+ export declare type SidebarCategoriesShorthand = {
74
+ [sidebarCategory: string]: SidebarCategoriesShorthand | SidebarItemConfig[];
75
+ };
76
+ export declare type SidebarItemConfig = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | SidebarItemAutogenerated | SidebarItemCategoryConfig | string | SidebarCategoriesShorthand;
77
+ export declare type SidebarConfig = SidebarCategoriesShorthand | SidebarItemConfig[];
78
+ export declare type SidebarsConfig = {
79
+ [sidebarId: string]: SidebarConfig;
80
+ };
81
+ export declare type NormalizedSidebarItemCategory = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
82
+ items: NormalizedSidebarItem[];
83
+ link?: SidebarItemCategoryLinkConfig;
84
+ }>;
85
+ export declare type NormalizedSidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | NormalizedSidebarItemCategory | SidebarItemAutogenerated;
86
+ export declare type NormalizedSidebar = NormalizedSidebarItem[];
87
+ export declare type NormalizedSidebars = {
88
+ [sidebarId: string]: NormalizedSidebar;
89
+ };
90
+ export declare type ProcessedSidebarItemCategory = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
91
+ items: ProcessedSidebarItem[];
92
+ link?: SidebarItemCategoryLinkConfig;
93
+ }>;
94
+ export declare type ProcessedSidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | ProcessedSidebarItemCategory;
95
+ export declare type ProcessedSidebar = ProcessedSidebarItem[];
96
+ export declare type ProcessedSidebars = {
97
+ [sidebarId: string]: ProcessedSidebar;
98
+ };
99
+ export declare type SidebarItemCategory = Expand<SidebarItemCategoryBase & {
100
+ items: SidebarItem[];
101
+ link?: SidebarItemCategoryLink;
102
+ }>;
103
+ export declare type SidebarItemCategoryWithLink = Required<SidebarItemCategory, 'link'>;
104
+ export declare type SidebarItemCategoryWithGeneratedIndex = SidebarItemCategoryWithLink & {
105
+ link: SidebarItemCategoryLinkGeneratedIndex;
106
+ };
107
+ export declare type SidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | SidebarItemCategory;
108
+ export declare type SidebarNavigationItem = SidebarItemDoc | SidebarItemCategoryWithLink;
109
+ export declare type Sidebar = SidebarItem[];
110
+ export declare type SidebarItemType = SidebarItem['type'];
111
+ export declare type Sidebars = {
112
+ [sidebarId: string]: Sidebar;
113
+ };
114
+ export declare type PropSidebarItemCategory = Expand<SidebarItemCategoryBase & {
115
+ items: PropSidebarItem[];
116
+ href?: string;
117
+ }>;
118
+ export declare type PropSidebarItemLink = SidebarItemLink & {
119
+ docId?: string;
120
+ };
121
+ export declare type PropSidebarItemHtml = SidebarItemHtml;
122
+ export declare type PropSidebarItem = PropSidebarItemLink | PropSidebarItemCategory | PropSidebarItemHtml;
123
+ export declare type PropSidebar = PropSidebarItem[];
124
+ export declare type PropSidebars = {
125
+ [sidebarId: string]: PropSidebar;
126
+ };
127
+ export declare type PropSidebarBreadcrumbsItem = PropSidebarItemLink | PropSidebarItemCategory;
128
+ export declare type CategoryMetadataFile = {
129
+ label?: string;
130
+ position?: number;
131
+ collapsed?: boolean;
132
+ collapsible?: boolean;
133
+ className?: string;
134
+ link?: SidebarItemCategoryLinkConfig | null;
135
+ customProps?: {
136
+ [key: string]: unknown;
137
+ };
138
+ };
139
+ export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'unversionedId' | 'title' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
140
+ export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
141
+ export declare type SidebarItemsGeneratorArgs = {
142
+ /** The sidebar item with type "autogenerated" to be transformed. */
143
+ item: SidebarItemAutogenerated;
144
+ /** Useful metadata for the version this sidebar belongs to. */
145
+ version: SidebarItemsGeneratorVersion;
146
+ /** All the docs of that version (unfiltered). */
147
+ docs: SidebarItemsGeneratorDoc[];
148
+ /** Number prefix parser configured for this plugin. */
149
+ numberPrefixParser: NumberPrefixParser;
150
+ /** The default category index matcher which you can override. */
151
+ isCategoryIndex: CategoryIndexMatcher;
152
+ /**
153
+ * Key is the path relative to the doc content directory, value is the
154
+ * category metadata file's content.
155
+ */
156
+ categoriesMetadata: {
157
+ [filePath: string]: CategoryMetadataFile;
158
+ };
159
+ };
160
+ export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<NormalizedSidebar>;
161
+ export declare type SidebarItemsGeneratorOption = (generatorArgs: {
162
+ /**
163
+ * Useful to re-use/enhance the default sidebar generation logic from
164
+ * Docusaurus.
165
+ * @see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320
166
+ */
167
+ defaultSidebarItemsGenerator: SidebarItemsGenerator;
168
+ } & SidebarItemsGeneratorArgs) => Promise<NormalizedSidebarItem[]>;
169
+ export declare type SidebarProcessorParams = {
170
+ sidebarItemsGenerator: SidebarItemsGeneratorOption;
171
+ numberPrefixParser: NumberPrefixParser;
172
+ docs: DocMetadataBase[];
173
+ drafts: DocMetadataBase[];
174
+ version: VersionMetadata;
175
+ categoryLabelSlugger: Slugger;
176
+ sidebarOptions: SidebarOptions;
177
+ };
178
+ export {};
@@ -1,8 +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
- import { DocFrontMatter } from './types';
8
- export declare function validateDocFrontMatter(frontMatter: Record<string, unknown>): DocFrontMatter;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,54 @@
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, PropNavigationLink } from '@docusaurus/plugin-content-docs';
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): {
17
+ [sidebarId: string]: string[];
18
+ };
19
+ export declare function collectSidebarsNavigations(sidebars: Sidebars): {
20
+ [sidebarId: string]: SidebarNavigationItem[];
21
+ };
22
+ export declare type SidebarNavigation = {
23
+ sidebarName: string | undefined;
24
+ previous: SidebarNavigationItem | undefined;
25
+ next: SidebarNavigationItem | undefined;
26
+ };
27
+ export declare type SidebarsUtils = {
28
+ sidebars: Sidebars;
29
+ getFirstDocIdOfFirstSidebar: () => string | undefined;
30
+ getSidebarNameByDocId: (docId: string) => string | undefined;
31
+ getDocNavigation: (unversionedId: string, versionedId: string, displayedSidebar: string | null | undefined) => SidebarNavigation;
32
+ getCategoryGeneratedIndexList: () => SidebarItemCategoryWithGeneratedIndex[];
33
+ getCategoryGeneratedIndexNavigation: (categoryGeneratedIndexPermalink: string) => SidebarNavigation;
34
+ /**
35
+ * This function may return undefined. This is usually a user mistake, because
36
+ * it means this sidebar will never be displayed; however, we can still use
37
+ * `displayed_sidebar` to make it displayed. Pretty weird but valid use-case
38
+ */
39
+ getFirstLink: (sidebarId: string) => {
40
+ type: 'doc';
41
+ id: string;
42
+ label: string;
43
+ } | {
44
+ type: 'generated-index';
45
+ permalink: string;
46
+ label: string;
47
+ } | undefined;
48
+ checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
49
+ };
50
+ export declare function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils;
51
+ export declare function toDocNavigationLink(doc: DocMetadataBase): PropNavigationLink;
52
+ export declare function toNavigationLink(navigationItem: SidebarNavigationItem | undefined, docsById: {
53
+ [docId: string]: DocMetadataBase;
54
+ }): PropNavigationLink | undefined;