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

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 (197) hide show
  1. package/lib/categoryGeneratedIndex.d.ts +2 -2
  2. package/lib/categoryGeneratedIndex.js +2 -0
  3. package/lib/cli.d.ts +1 -1
  4. package/lib/cli.js +2 -1
  5. package/lib/client/docsClientUtils.d.ts +3 -22
  6. package/lib/client/docsClientUtils.js +5 -1
  7. package/lib/{theme/hooks/useDocs.d.ts → client/globalDataHooks.d.ts} +1 -2
  8. package/lib/{theme/hooks/useDocs.js → client/globalDataHooks.js} +2 -1
  9. package/{src/__tests__/__fixtures__/simple-site/docusaurus.config.js → lib/client/index.d.ts} +1 -8
  10. package/{src/__tests__/__fixtures__/site-with-doc-label/docusaurus.config.js → lib/client/index.js} +4 -8
  11. package/lib/docFrontMatter.js +1 -0
  12. package/lib/docs.d.ts +19 -6
  13. package/lib/docs.js +43 -22
  14. package/lib/globalData.d.ts +5 -1
  15. package/lib/globalData.js +34 -2
  16. package/lib/index.d.ts +3 -2
  17. package/lib/index.js +4 -10
  18. package/lib/lastUpdate.js +6 -5
  19. package/lib/markdown/index.d.ts +1 -1
  20. package/lib/markdown/linkify.d.ts +1 -1
  21. package/lib/numberPrefix.d.ts +1 -1
  22. package/lib/options.d.ts +1 -1
  23. package/lib/options.js +2 -2
  24. package/lib/routes.d.ts +4 -3
  25. package/lib/routes.js +8 -5
  26. package/lib/sidebars/generator.js +15 -17
  27. package/lib/sidebars/index.d.ts +3 -2
  28. package/lib/sidebars/processor.d.ts +3 -2
  29. package/lib/sidebars/processor.js +2 -0
  30. package/lib/sidebars/types.d.ts +8 -3
  31. package/lib/sidebars/utils.d.ts +12 -4
  32. package/lib/sidebars/utils.js +48 -3
  33. package/lib/sidebars/validation.d.ts +1 -1
  34. package/lib/sidebars/validation.js +4 -0
  35. package/lib/slug.d.ts +5 -4
  36. package/lib/slug.js +8 -7
  37. package/lib/translations.js +1 -1
  38. package/lib/types.d.ts +7 -78
  39. package/lib/versions.d.ts +3 -2
  40. package/lib/versions.js +27 -32
  41. package/package.json +14 -12
  42. package/src/categoryGeneratedIndex.ts +5 -3
  43. package/src/cli.ts +6 -2
  44. package/src/client/docsClientUtils.ts +22 -35
  45. package/src/{theme/hooks/useDocs.ts → client/globalDataHooks.ts} +6 -2
  46. package/src/{__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js → client/index.ts} +1 -9
  47. package/src/docFrontMatter.ts +2 -1
  48. package/src/docs.ts +77 -42
  49. package/src/globalData.ts +49 -3
  50. package/src/index.ts +11 -21
  51. package/src/lastUpdate.ts +6 -5
  52. package/src/markdown/index.ts +1 -1
  53. package/src/markdown/linkify.ts +1 -1
  54. package/src/numberPrefix.ts +1 -1
  55. package/src/options.ts +3 -7
  56. package/src/plugin-content-docs.d.ts +128 -18
  57. package/src/routes.ts +21 -11
  58. package/src/sidebars/generator.ts +28 -31
  59. package/src/sidebars/index.ts +3 -2
  60. package/src/sidebars/normalization.ts +2 -1
  61. package/src/sidebars/processor.ts +8 -7
  62. package/src/sidebars/types.ts +9 -5
  63. package/src/sidebars/utils.ts +76 -8
  64. package/src/sidebars/validation.ts +6 -1
  65. package/src/slug.ts +15 -11
  66. package/src/translations.ts +2 -2
  67. package/src/types.ts +12 -98
  68. package/src/versions.ts +51 -47
  69. package/lib/.tsbuildinfo +0 -1
  70. package/src/__tests__/__fixtures__/bad-id-site/docs/invalid-id.md +0 -5
  71. package/src/__tests__/__fixtures__/bad-slug-on-doc-home-site/docs/docWithSlug.md +0 -5
  72. package/src/__tests__/__fixtures__/empty-site/docusaurus.config.js +0 -16
  73. package/src/__tests__/__fixtures__/empty-site/sidebars.json +0 -1
  74. package/src/__tests__/__fixtures__/simple-site/docs/_partials/somePartial.md +0 -3
  75. package/src/__tests__/__fixtures__/simple-site/docs/_partials/subfolder/somePartial.md +0 -3
  76. package/src/__tests__/__fixtures__/simple-site/docs/_somePartial.md +0 -3
  77. package/src/__tests__/__fixtures__/simple-site/docs/foo/bar.md +0 -69
  78. package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +0 -75
  79. package/src/__tests__/__fixtures__/simple-site/docs/headingAsTitle.md +0 -1
  80. package/src/__tests__/__fixtures__/simple-site/docs/hello.md +0 -55
  81. package/src/__tests__/__fixtures__/simple-site/docs/ipsum.md +0 -5
  82. package/src/__tests__/__fixtures__/simple-site/docs/lorem.md +0 -6
  83. package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +0 -7
  84. package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +0 -7
  85. package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +0 -7
  86. package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +0 -7
  87. package/src/__tests__/__fixtures__/simple-site/docs/slugs/absoluteSlug.md +0 -5
  88. package/src/__tests__/__fixtures__/simple-site/docs/slugs/relativeSlug.md +0 -5
  89. package/src/__tests__/__fixtures__/simple-site/docs/slugs/resolvedSlug.md +0 -5
  90. package/src/__tests__/__fixtures__/simple-site/docs/slugs/tryToEscapeSlug.md +0 -5
  91. package/src/__tests__/__fixtures__/simple-site/sidebars.json +0 -37
  92. package/src/__tests__/__fixtures__/simple-site/wrong-sidebars.json +0 -7
  93. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/0-getting-started.md +0 -3
  94. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/1-installation.md +0 -3
  95. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/00_api-overview.md +0 -3
  96. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/0 --- Client API.md +0 -1
  97. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/1 --- Server API.md +0 -1
  98. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/0. Plugin API.md +0 -1
  99. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/1. Theme API.md +0 -1
  100. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/_category_.yml +0 -1
  101. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/03_api-end.md +0 -3
  102. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/_category_.json +0 -3
  103. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/0-guide2.5.md +0 -8
  104. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/02-guide2.md +0 -7
  105. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/_category_.json +0 -3
  106. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/a-guide4.md +0 -7
  107. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/b-guide5.md +0 -7
  108. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/guide3.md +0 -8
  109. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/z-guide1.md +0 -8
  110. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docusaurus.config.js +0 -14
  111. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars.js +0 -23
  112. package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-1.md +0 -8
  113. package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-2.md +0 -8
  114. package/src/__tests__/__fixtures__/site-with-doc-label/sidebars.json +0 -14
  115. package/src/__tests__/__fixtures__/versioned-site/community/team.md +0 -1
  116. package/src/__tests__/__fixtures__/versioned-site/community_sidebars.json +0 -3
  117. package/src/__tests__/__fixtures__/versioned-site/community_versioned_docs/version-1.0.0/team.md +0 -1
  118. package/src/__tests__/__fixtures__/versioned-site/community_versioned_sidebars/version-1.0.0-sidebars.json +0 -3
  119. package/src/__tests__/__fixtures__/versioned-site/community_versions.json +0 -1
  120. package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +0 -10
  121. package/src/__tests__/__fixtures__/versioned-site/docs/hello.md +0 -4
  122. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/absoluteSlug.md +0 -5
  123. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/relativeSlug.md +0 -5
  124. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/resolvedSlug.md +0 -5
  125. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/tryToEscapeSlug.md +0 -5
  126. package/src/__tests__/__fixtures__/versioned-site/docusaurus.config.js +0 -18
  127. package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -4
  128. package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs-community/current/team.md +0 -5
  129. package/src/__tests__/__fixtures__/versioned-site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -4
  130. package/src/__tests__/__fixtures__/versioned-site/sidebars.json +0 -10
  131. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/bar.md +0 -4
  132. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/baz.md +0 -1
  133. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md +0 -4
  134. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/somePartial.md +0 -3
  135. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/subfolder/somePartial.md +0 -3
  136. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_somePartial.md +0 -3
  137. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/foo/bar.md +0 -1
  138. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md +0 -4
  139. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootAbsoluteSlug.md +0 -5
  140. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootRelativeSlug.md +0 -5
  141. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootResolvedSlug.md +0 -5
  142. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootTryToEscapeSlug.md +0 -5
  143. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/absoluteSlug.md +0 -5
  144. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/relativeSlug.md +0 -5
  145. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/resolvedSlug.md +0 -5
  146. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/tryToEscapeSlug.md +0 -5
  147. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.0-sidebars.json +0 -11
  148. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +0 -10
  149. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-withSlugs-sidebars.json +0 -5
  150. package/src/__tests__/__fixtures__/versioned-site/versions.json +0 -5
  151. package/src/__tests__/__snapshots__/cli.test.ts.snap +0 -65
  152. package/src/__tests__/__snapshots__/docs.test.ts.snap +0 -140
  153. package/src/__tests__/__snapshots__/index.test.ts.snap +0 -2550
  154. package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -514
  155. package/src/__tests__/cli.test.ts +0 -337
  156. package/src/__tests__/docFrontMatter.test.ts +0 -359
  157. package/src/__tests__/docs.test.ts +0 -1039
  158. package/src/__tests__/index.test.ts +0 -1910
  159. package/src/__tests__/lastUpdate.test.ts +0 -69
  160. package/src/__tests__/numberPrefix.test.ts +0 -199
  161. package/src/__tests__/options.test.ts +0 -276
  162. package/src/__tests__/props.test.ts +0 -62
  163. package/src/__tests__/slug.test.ts +0 -216
  164. package/src/__tests__/translations.test.ts +0 -164
  165. package/src/__tests__/versions.test.ts +0 -744
  166. package/src/client/__tests__/docsClientUtils.test.ts +0 -371
  167. package/src/markdown/__tests__/__fixtures__/docs/doc-localized.md +0 -1
  168. package/src/markdown/__tests__/__fixtures__/docs/doc1.md +0 -13
  169. package/src/markdown/__tests__/__fixtures__/docs/doc2.md +0 -12
  170. package/src/markdown/__tests__/__fixtures__/docs/doc4.md +0 -19
  171. package/src/markdown/__tests__/__fixtures__/docs/doc5.md +0 -6
  172. package/src/markdown/__tests__/__fixtures__/docs/subdir/doc3.md +0 -3
  173. package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/doc2.md +0 -7
  174. package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/subdir/doc1.md +0 -3
  175. package/src/markdown/__tests__/__snapshots__/linkify.test.ts.snap +0 -82
  176. package/src/markdown/__tests__/linkify.test.ts +0 -190
  177. package/src/sidebars/__tests__/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -34
  178. package/src/sidebars/__tests__/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -11
  179. package/src/sidebars/__tests__/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -11
  180. package/src/sidebars/__tests__/__fixtures__/sidebars/sidebars-category.js +0 -44
  181. package/src/sidebars/__tests__/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -20
  182. package/src/sidebars/__tests__/__fixtures__/sidebars/sidebars-collapsed.json +0 -21
  183. package/src/sidebars/__tests__/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -10
  184. package/src/sidebars/__tests__/__fixtures__/sidebars/sidebars-first-level-not-category.js +0 -20
  185. package/src/sidebars/__tests__/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -11
  186. package/src/sidebars/__tests__/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -11
  187. package/src/sidebars/__tests__/__fixtures__/sidebars/sidebars-link.json +0 -11
  188. package/src/sidebars/__tests__/__fixtures__/sidebars/sidebars-unknown-type.json +0 -14
  189. package/src/sidebars/__tests__/__fixtures__/sidebars/sidebars-wrong-field.json +0 -20
  190. package/src/sidebars/__tests__/__fixtures__/sidebars/sidebars.json +0 -20
  191. package/src/sidebars/__tests__/__snapshots__/index.test.ts.snap +0 -248
  192. package/src/sidebars/__tests__/generator.test.ts +0 -461
  193. package/src/sidebars/__tests__/index.test.ts +0 -204
  194. package/src/sidebars/__tests__/processor.test.ts +0 -237
  195. package/src/sidebars/__tests__/utils.test.ts +0 -695
  196. package/src/sidebars/__tests__/validation.test.ts +0 -105
  197. package/tsconfig.json +0 -9
@@ -10,7 +10,7 @@ exports.DefaultSidebarItemsGenerator = exports.CategoryMetadataFilenamePattern =
10
10
  const tslib_1 = require("tslib");
11
11
  const lodash_1 = require("lodash");
12
12
  const utils_1 = require("@docusaurus/utils");
13
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
13
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
14
14
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
15
15
  const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
16
16
  const js_yaml_1 = (0, tslib_1.__importDefault)(require("js-yaml"));
@@ -37,22 +37,15 @@ async function readCategoryMetadataFile(categoryDirPath) {
37
37
  return (0, validation_1.validateCategoryMetadataFile)(unsafeContent);
38
38
  }
39
39
  catch (e) {
40
- console.error(chalk_1.default.red(`The docs sidebar category metadata file looks invalid!\nPath: ${filePath}`));
40
+ logger_1.default.error `The docs sidebar category metadata file path=${filePath} looks invalid!`;
41
41
  throw e;
42
42
  }
43
43
  }
44
- // eslint-disable-next-line no-restricted-syntax
45
- for (const ext of ['.json', '.yml', '.yaml']) {
46
- // Simpler to use only posix paths for mocking file metadata in tests
47
- const filePath = (0, utils_1.posixPath)(path_1.default.join(categoryDirPath, `${exports.CategoryMetadataFilenameBase}${ext}`));
48
- if (await fs_extra_1.default.pathExists(filePath)) {
49
- return tryReadFile(filePath);
50
- }
51
- }
52
- return null;
44
+ const filePath = await (0, utils_1.findAsyncSequential)(['.json', '.yml', '.yaml'].map((ext) => (0, utils_1.posixPath)(path_1.default.join(categoryDirPath, `${exports.CategoryMetadataFilenameBase}${ext}`))), fs_extra_1.default.pathExists);
45
+ return filePath ? tryReadFile(filePath) : null;
53
46
  }
54
47
  // Comment for this feature: https://github.com/facebook/docusaurus/issues/3464#issuecomment-818670449
55
- const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, docs: allDocs, options, item: { dirName: autogenDir }, version, }) => {
48
+ const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, isCategoryIndex, docs: allDocs, options, item: { dirName: autogenDir }, version, }) => {
56
49
  const docsById = (0, docs_1.createDocsByIdIndex)(allDocs);
57
50
  const findDoc = (docId) => docsById[docId];
58
51
  const getDoc = (docId) => {
@@ -78,7 +71,7 @@ const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, docs: allDocs,
78
71
  }
79
72
  const docs = allDocs.filter(isInAutogeneratedDir);
80
73
  if (docs.length === 0) {
81
- console.warn(chalk_1.default.yellow(`No docs found in dir ${autogenDir}: can't auto-generate a sidebar.`));
74
+ logger_1.default.warn `No docs found in path=${autogenDir}: can't auto-generate a sidebar.`;
82
75
  }
83
76
  return docs;
84
77
  }
@@ -101,13 +94,12 @@ const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, docs: allDocs,
101
94
  docs.forEach((doc) => {
102
95
  const breadcrumb = getRelativeBreadcrumb(doc);
103
96
  let currentDir = treeRoot; // We walk down the file's path to generate the fs structure
104
- // eslint-disable-next-line no-restricted-syntax
105
- for (const dir of breadcrumb) {
97
+ breadcrumb.forEach((dir) => {
106
98
  if (typeof currentDir[dir] === 'undefined') {
107
99
  currentDir[dir] = {}; // Create new folder.
108
100
  }
109
101
  currentDir = currentDir[dir]; // Go into the subdirectory.
110
- }
102
+ });
111
103
  currentDir[`${docIdPrefix}${doc.id}`] = null; // We've walked through the file path. Register the file in this directory.
112
104
  });
113
105
  return treeRoot;
@@ -141,7 +133,13 @@ const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, docs: allDocs,
141
133
  return allItems.find((item) => item.type === 'doc' && getLocalDocId(item.id) === localId);
142
134
  }
143
135
  function findConventionalCategoryDocLink() {
144
- return allItems.find((item) => item.type === 'doc' && (0, docs_1.isConventionalDocIndex)(getDoc(item.id)));
136
+ return allItems.find((item) => {
137
+ if (item.type !== 'doc') {
138
+ return false;
139
+ }
140
+ const doc = getDoc(item.id);
141
+ return isCategoryIndex((0, docs_1.toCategoryIndexMatcherParam)(doc));
142
+ });
145
143
  }
146
144
  function getCategoryLinkedDocId() {
147
145
  var _a, _b;
@@ -5,8 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { SidebarsConfig, Sidebars, NormalizedSidebars } from './types';
8
- import type { NormalizeSidebarsParams, PluginOptions } from '../types';
9
- import { SidebarProcessorParams } from './processor';
8
+ import type { NormalizeSidebarsParams } from '../types';
9
+ import { type SidebarProcessorParams } from './processor';
10
+ import type { PluginOptions } from '@docusaurus/plugin-content-docs';
10
11
  export declare const DefaultSidebars: SidebarsConfig;
11
12
  export declare const DisabledSidebars: SidebarsConfig;
12
13
  export declare function resolveSidebarPathOption(siteDir: string, sidebarPathOption: PluginOptions['sidebarPath']): PluginOptions['sidebarPath'];
@@ -4,9 +4,10 @@
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 type { NumberPrefixParser, DocMetadataBase, VersionMetadata, SidebarOptions } from '../types';
7
+ import type { DocMetadataBase, VersionMetadata } from '../types';
8
8
  import type { Sidebars, NormalizedSidebars, SidebarItemsGeneratorOption } from './types';
9
- import { Slugger } from '@docusaurus/utils';
9
+ import type { Slugger } from '@docusaurus/utils';
10
+ import type { NumberPrefixParser, SidebarOptions } from '@docusaurus/plugin-content-docs';
10
11
  export declare type SidebarProcessorParams = {
11
12
  sidebarItemsGenerator: SidebarItemsGeneratorOption;
12
13
  numberPrefixParser: NumberPrefixParser;
@@ -13,6 +13,7 @@ const generator_1 = require("./generator");
13
13
  const lodash_1 = require("lodash");
14
14
  const combine_promises_1 = (0, tslib_1.__importDefault)(require("combine-promises"));
15
15
  const normalization_1 = require("./normalization");
16
+ const docs_1 = require("../docs");
16
17
  function toSidebarItemsGeneratorDoc(doc) {
17
18
  return (0, lodash_1.pick)(doc, [
18
19
  'id',
@@ -46,6 +47,7 @@ async function processSidebar(unprocessedSidebar, params) {
46
47
  item,
47
48
  numberPrefixParser,
48
49
  defaultSidebarItemsGenerator: generator_1.DefaultSidebarItemsGenerator,
50
+ isCategoryIndex: docs_1.isCategoryIndex,
49
51
  ...getSidebarItemsGeneratorDocsAndVersion(),
50
52
  options: sidebarOptions,
51
53
  });
@@ -4,9 +4,9 @@
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 type { Optional } from 'utility-types';
8
- import type { DocMetadataBase, VersionMetadata, NumberPrefixParser, SidebarOptions } from '../types';
9
- import { Required } from 'utility-types';
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
10
  declare type Expand<T extends Record<string, unknown>> = {
11
11
  [P in keyof T]: T[P];
12
12
  };
@@ -43,6 +43,8 @@ export declare type SidebarItemCategoryLinkGeneratedIndexConfig = {
43
43
  slug?: string;
44
44
  title?: string;
45
45
  description?: string;
46
+ image?: string;
47
+ keywords?: string | readonly string[];
46
48
  };
47
49
  export declare type SidebarItemCategoryLinkGeneratedIndex = {
48
50
  type: 'generated-index';
@@ -50,6 +52,8 @@ export declare type SidebarItemCategoryLinkGeneratedIndex = {
50
52
  permalink: string;
51
53
  title?: string;
52
54
  description?: string;
55
+ image?: string;
56
+ keywords?: string | readonly string[];
53
57
  };
54
58
  export declare type SidebarItemCategoryLinkConfig = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndexConfig;
55
59
  export declare type SidebarItemCategoryLink = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndex;
@@ -117,6 +121,7 @@ export declare type SidebarItemsGeneratorArgs = {
117
121
  version: SidebarItemsGeneratorVersion;
118
122
  docs: SidebarItemsGeneratorDoc[];
119
123
  numberPrefixParser: NumberPrefixParser;
124
+ isCategoryIndex: CategoryIndexMatcher;
120
125
  options: SidebarOptions;
121
126
  };
122
127
  export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<SidebarItem[]>;
@@ -4,9 +4,8 @@
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 type { Sidebars, Sidebar, SidebarItem, SidebarItemCategory, SidebarItemLink, SidebarItemDoc, SidebarCategoriesShorthand, SidebarItemConfig } from './types';
8
- import { DocMetadataBase, DocNavLink } from '../types';
9
- import { SidebarItemCategoryWithGeneratedIndex, SidebarNavigationItem } from './types';
7
+ import type { Sidebars, Sidebar, SidebarItem, SidebarItemCategory, SidebarItemLink, SidebarItemDoc, SidebarCategoriesShorthand, SidebarItemConfig, SidebarItemCategoryWithGeneratedIndex, SidebarNavigationItem } from './types';
8
+ import type { DocMetadataBase, DocNavLink } from '../types';
10
9
  export declare function isCategoriesShorthand(item: SidebarItemConfig): item is SidebarCategoriesShorthand;
11
10
  export declare function transformSidebarItems(sidebar: Sidebar, updateFn: (item: SidebarItem) => SidebarItem): Sidebar;
12
11
  export declare function collectSidebarDocItems(sidebar: Sidebar): SidebarItemDoc[];
@@ -25,9 +24,18 @@ export declare type SidebarsUtils = {
25
24
  sidebars: Sidebars;
26
25
  getFirstDocIdOfFirstSidebar: () => string | undefined;
27
26
  getSidebarNameByDocId: (docId: string) => string | undefined;
28
- getDocNavigation: (unversionedId: string, versionedId: string) => SidebarNavigation;
27
+ getDocNavigation: (unversionedId: string, versionedId: string, displayedSidebar: string | null | undefined) => SidebarNavigation;
29
28
  getCategoryGeneratedIndexList: () => SidebarItemCategoryWithGeneratedIndex[];
30
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;
31
39
  checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
32
40
  };
33
41
  export declare function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils;
@@ -104,15 +104,20 @@ function createSidebarsUtils(sidebars) {
104
104
  next: undefined,
105
105
  };
106
106
  }
107
- function getDocNavigation(unversionedId, versionedId) {
107
+ function getDocNavigation(unversionedId, versionedId, displayedSidebar) {
108
108
  // TODO legacy id retro-compatibility!
109
109
  let docId = unversionedId;
110
- let sidebarName = getSidebarNameByDocId(docId);
111
- if (!sidebarName) {
110
+ let sidebarName = displayedSidebar === undefined
111
+ ? getSidebarNameByDocId(docId)
112
+ : displayedSidebar;
113
+ if (sidebarName === undefined) {
112
114
  docId = versionedId;
113
115
  sidebarName = getSidebarNameByDocId(docId);
114
116
  }
115
117
  if (sidebarName) {
118
+ if (!sidebarNameToNavigationItems[sidebarName]) {
119
+ throw new Error(`Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`);
120
+ }
116
121
  const navigationItems = sidebarNameToNavigationItems[sidebarName];
117
122
  const currentItemIndex = navigationItems.findIndex((item) => {
118
123
  if (item.type === 'doc') {
@@ -123,6 +128,9 @@ function createSidebarsUtils(sidebars) {
123
128
  }
124
129
  return false;
125
130
  });
131
+ if (currentItemIndex === -1) {
132
+ return { sidebarName, next: undefined, previous: undefined };
133
+ }
126
134
  const { previous, next } = (0, utils_1.getElementsAround)(navigationItems, currentItemIndex);
127
135
  return { sidebarName, previous, next };
128
136
  }
@@ -173,6 +181,42 @@ Available document ids are:
173
181
  - ${(0, lodash_1.uniq)(validDocIds).sort().join('\n- ')}`);
174
182
  }
175
183
  }
184
+ function getFirstLink(sidebar) {
185
+ var _a, _b, _c;
186
+ // eslint-disable-next-line no-restricted-syntax
187
+ for (const item of sidebar) {
188
+ if (item.type === 'doc') {
189
+ return {
190
+ type: 'doc',
191
+ id: item.id,
192
+ label: (_a = item.label) !== null && _a !== void 0 ? _a : item.id,
193
+ };
194
+ }
195
+ else if (item.type === 'category') {
196
+ if (((_b = item.link) === null || _b === void 0 ? void 0 : _b.type) === 'doc') {
197
+ return {
198
+ type: 'doc',
199
+ id: item.link.id,
200
+ label: item.label,
201
+ };
202
+ }
203
+ else if (((_c = item.link) === null || _c === void 0 ? void 0 : _c.type) === 'generated-index') {
204
+ return {
205
+ type: 'generated-index',
206
+ slug: item.link.slug,
207
+ label: item.label,
208
+ };
209
+ }
210
+ else {
211
+ const firstSubItem = getFirstLink(item.items);
212
+ if (firstSubItem) {
213
+ return firstSubItem;
214
+ }
215
+ }
216
+ }
217
+ }
218
+ return undefined;
219
+ }
176
220
  return {
177
221
  sidebars,
178
222
  getFirstDocIdOfFirstSidebar,
@@ -181,6 +225,7 @@ Available document ids are:
181
225
  getCategoryGeneratedIndexList,
182
226
  getCategoryGeneratedIndexNavigation,
183
227
  checkSidebarsDocIds,
228
+ getFirstLink: (id) => getFirstLink(sidebars[id]),
184
229
  };
185
230
  }
186
231
  exports.createSidebarsUtils = createSidebarsUtils;
@@ -5,6 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { SidebarsConfig } from './types';
8
- import { CategoryMetadataFile } from './generator';
8
+ import type { CategoryMetadataFile } from './generator';
9
9
  export declare function validateSidebars(sidebars: unknown): asserts sidebars is SidebarsConfig;
10
10
  export declare function validateCategoryMetadataFile(unsafeContent: unknown): CategoryMetadataFile;
@@ -9,6 +9,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.validateCategoryMetadataFile = exports.validateSidebars = void 0;
10
10
  const utils_validation_1 = require("@docusaurus/utils-validation");
11
11
  const utils_1 = require("./utils");
12
+ // NOTE: we don't add any default values during validation on purpose!
13
+ // Config types are exposed to users for typechecking and we use the same type in normalization
12
14
  const sidebarItemBaseSchema = utils_validation_1.Joi.object({
13
15
  className: utils_validation_1.Joi.string(),
14
16
  customProps: utils_validation_1.Joi.object().unknown(),
@@ -50,6 +52,8 @@ const sidebarItemCategoryLinkSchema = utils_validation_1.Joi.object()
50
52
  // permalink: Joi.string().optional(), // No, this one is not in the user config, only in the normalized version
51
53
  title: utils_validation_1.Joi.string().optional(),
52
54
  description: utils_validation_1.Joi.string().optional(),
55
+ image: utils_validation_1.Joi.string().optional(),
56
+ keywords: [utils_validation_1.Joi.string(), utils_validation_1.Joi.array().items(utils_validation_1.Joi.string())],
53
57
  }),
54
58
  },
55
59
  {
package/lib/slug.d.ts CHANGED
@@ -4,11 +4,12 @@
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 type { DocMetadataBase, NumberPrefixParser } from './types';
8
- export default function getSlug({ baseID, frontmatterSlug, source, sourceDirName, stripDirNumberPrefixes, numberPrefixParser, }: {
7
+ import type { DocMetadataBase } from './types';
8
+ import type { NumberPrefixParser } from '@docusaurus/plugin-content-docs';
9
+ export default function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumberPrefixes, numberPrefixParser, }: {
9
10
  baseID: string;
10
- frontmatterSlug?: string;
11
- source: DocMetadataBase['slug'];
11
+ frontMatterSlug?: string;
12
+ source: DocMetadataBase['source'];
12
13
  sourceDirName: DocMetadataBase['sourceDirName'];
13
14
  stripDirNumberPrefixes?: boolean;
14
15
  numberPrefixParser?: NumberPrefixParser;
package/lib/slug.js CHANGED
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const utils_1 = require("@docusaurus/utils");
10
10
  const numberPrefix_1 = require("./numberPrefix");
11
11
  const docs_1 = require("./docs");
12
- function getSlug({ baseID, frontmatterSlug, source, sourceDirName, stripDirNumberPrefixes = true, numberPrefixParser = numberPrefix_1.DefaultNumberPrefixParser, }) {
12
+ function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumberPrefixes = true, numberPrefixParser = numberPrefix_1.DefaultNumberPrefixParser, }) {
13
13
  function getDirNameSlug() {
14
14
  const dirNameStripped = stripDirNumberPrefixes
15
15
  ? (0, numberPrefix_1.stripPathNumberPrefixes)(sourceDirName, numberPrefixParser)
@@ -20,15 +20,16 @@ function getSlug({ baseID, frontmatterSlug, source, sourceDirName, stripDirNumbe
20
20
  return resolveDirname;
21
21
  }
22
22
  function computeSlug() {
23
- if (frontmatterSlug === null || frontmatterSlug === void 0 ? void 0 : frontmatterSlug.startsWith('/')) {
24
- return frontmatterSlug;
23
+ if (frontMatterSlug === null || frontMatterSlug === void 0 ? void 0 : frontMatterSlug.startsWith('/')) {
24
+ return frontMatterSlug;
25
25
  }
26
26
  else {
27
27
  const dirNameSlug = getDirNameSlug();
28
- if (!frontmatterSlug && (0, docs_1.isConventionalDocIndex)({ source, sourceDirName })) {
28
+ if (!frontMatterSlug &&
29
+ (0, docs_1.isCategoryIndex)((0, docs_1.toCategoryIndexMatcherParam)({ source, sourceDirName }))) {
29
30
  return dirNameSlug;
30
31
  }
31
- const baseSlug = frontmatterSlug || baseID;
32
+ const baseSlug = frontMatterSlug || baseID;
32
33
  return (0, utils_1.resolvePathname)(baseSlug, getDirNameSlug());
33
34
  }
34
35
  }
@@ -36,8 +37,8 @@ function getSlug({ baseID, frontmatterSlug, source, sourceDirName, stripDirNumbe
36
37
  if (!(0, utils_1.isValidPathname)(slug)) {
37
38
  throw new Error(`We couldn't compute a valid slug for document with id "${baseID}" in "${sourceDirName}" directory.
38
39
  The slug we computed looks invalid: ${slug}.
39
- Maybe your slug frontmatter is incorrect or you use weird chars in the file path?
40
- By using the slug frontmatter, you should be able to fix this error, by using the slug of your choice:
40
+ Maybe your slug front matter is incorrect or you use weird chars in the file path?
41
+ By using the slug front matter, you should be able to fix this error, by using the slug of your choice:
41
42
 
42
43
  Example =>
43
44
  ---
@@ -33,7 +33,7 @@ function getNormalizedSidebarName({ versionName, sidebarName, }) {
33
33
  }
34
34
  /*
35
35
  // Do we need to translate doc metadata?
36
- // It seems translating frontmatter labels is good enough
36
+ // It seems translating front matter labels is good enough
37
37
  function getDocTranslations(doc: DocMetadata): TranslationFileContent {
38
38
  return {
39
39
  [`${doc.unversionedId}.title`]: {
package/lib/types.d.ts CHANGED
@@ -4,10 +4,10 @@
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 type { RemarkAndRehypePluginOptions } from '@docusaurus/mdx-loader';
7
+ import type { Sidebars } from './sidebars/types';
8
8
  import type { Tag, FrontMatterTag, Slugger } from '@docusaurus/utils';
9
9
  import type { BrokenMarkdownLink as IBrokenMarkdownLink, ContentPaths } from '@docusaurus/utils/lib/markdownLinks';
10
- import type { SidebarItemsGeneratorOption, Sidebars } from './sidebars/types';
10
+ import type { VersionBanner, SidebarOptions } from '@docusaurus/plugin-content-docs';
11
11
  export declare type DocFile = {
12
12
  contentPath: string;
13
13
  filePath: string;
@@ -15,9 +15,8 @@ export declare type DocFile = {
15
15
  content: string;
16
16
  lastUpdate: LastUpdateData;
17
17
  };
18
- export declare type VersionName = string;
19
18
  export declare type VersionMetadata = ContentPaths & {
20
- versionName: VersionName;
19
+ versionName: string;
21
20
  versionLabel: string;
22
21
  versionPath: string;
23
22
  tagsPath: string;
@@ -30,62 +29,10 @@ export declare type VersionMetadata = ContentPaths & {
30
29
  sidebarFilePath: string | false | undefined;
31
30
  routePriority: number | undefined;
32
31
  };
33
- export declare type EditUrlFunction = (editUrlParams: {
34
- version: string;
35
- versionDocsDirPath: string;
36
- docPath: string;
37
- permalink: string;
38
- locale: string;
39
- }) => string | undefined;
40
- export declare type MetadataOptions = {
41
- routeBasePath: string;
42
- editUrl?: string | EditUrlFunction;
43
- editCurrentVersion: boolean;
44
- editLocalizedFiles: boolean;
45
- showLastUpdateTime?: boolean;
46
- showLastUpdateAuthor?: boolean;
47
- numberPrefixParser: NumberPrefixParser;
48
- };
49
- export declare type PathOptions = {
50
- path: string;
51
- sidebarPath?: string | false | undefined;
52
- };
53
- export declare type VersionBanner = 'unreleased' | 'unmaintained';
54
- export declare type VersionOptions = {
55
- path?: string;
56
- label?: string;
57
- banner?: 'none' | VersionBanner;
58
- badge?: boolean;
59
- className?: string;
60
- };
61
- export declare type VersionsOptions = {
62
- lastVersion?: string;
63
- versions: Record<string, VersionOptions>;
64
- onlyIncludeVersions?: string[];
65
- };
66
- export declare type SidebarOptions = {
67
- sidebarCollapsible: boolean;
68
- sidebarCollapsed: boolean;
69
- };
70
32
  export declare type NormalizeSidebarsParams = SidebarOptions & {
71
33
  version: VersionMetadata;
72
34
  categoryLabelSlugger: Slugger;
73
35
  };
74
- export declare type PluginOptions = MetadataOptions & PathOptions & VersionsOptions & RemarkAndRehypePluginOptions & SidebarOptions & {
75
- id: string;
76
- include: string[];
77
- exclude: string[];
78
- docLayoutComponent: string;
79
- docItemComponent: string;
80
- docTagDocListComponent: string;
81
- docTagsListComponent: string;
82
- docCategoryGeneratedIndexComponent: string;
83
- admonitions: Record<string, unknown>;
84
- disableVersioning: boolean;
85
- includeCurrentVersion: boolean;
86
- sidebarItemsGenerator: SidebarItemsGeneratorOption;
87
- tagsBasePath: string;
88
- };
89
36
  export declare type LastUpdateData = {
90
37
  lastUpdatedAt?: number;
91
38
  formattedLastUpdatedAt?: string;
@@ -104,6 +51,7 @@ export declare type DocFrontMatter = {
104
51
  sidebar_label?: string;
105
52
  sidebar_position?: number;
106
53
  sidebar_class_name?: string;
54
+ displayed_sidebar?: string | null;
107
55
  pagination_label?: string;
108
56
  custom_edit_url?: string | null;
109
57
  parse_number_prefixes?: boolean;
@@ -115,7 +63,7 @@ export declare type DocFrontMatter = {
115
63
  export declare type DocMetadataBase = LastUpdateData & {
116
64
  id: string;
117
65
  unversionedId: string;
118
- version: VersionName;
66
+ version: string;
119
67
  title: string;
120
68
  description: string;
121
69
  source: string;
@@ -144,6 +92,8 @@ export declare type CategoryGeneratedIndexMetadata = {
144
92
  sidebar: string;
145
93
  previous?: DocNavLink;
146
94
  next?: DocNavLink;
95
+ image?: string;
96
+ keywords?: string | readonly string[];
147
97
  };
148
98
  export declare type SourceToPermalink = {
149
99
  [source: string]: string;
@@ -166,23 +116,6 @@ export declare type LoadedVersion = VersionMetadata & {
166
116
  export declare type LoadedContent = {
167
117
  loadedVersions: LoadedVersion[];
168
118
  };
169
- export declare type GlobalDoc = {
170
- id: string;
171
- path: string;
172
- sidebar: string | undefined;
173
- };
174
- export declare type GlobalVersion = {
175
- name: VersionName;
176
- label: string;
177
- isLast: boolean;
178
- path: string;
179
- mainDocId: string;
180
- docs: GlobalDoc[];
181
- };
182
- export declare type GlobalPluginData = {
183
- path: string;
184
- versions: GlobalVersion[];
185
- };
186
119
  export declare type BrokenMarkdownLink = IBrokenMarkdownLink<VersionMetadata>;
187
120
  export declare type DocsMarkdownOption = {
188
121
  versionsMetadata: VersionMetadata[];
@@ -190,7 +123,3 @@ export declare type DocsMarkdownOption = {
190
123
  sourceToPermalink: SourceToPermalink;
191
124
  onBrokenMarkdownLink: (brokenMarkdownLink: BrokenMarkdownLink) => void;
192
125
  };
193
- export declare type NumberPrefixParser = (filename: string) => {
194
- filename: string;
195
- numberPrefix?: number;
196
- };
package/lib/versions.d.ts CHANGED
@@ -4,7 +4,8 @@
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 type { PluginOptions, VersionMetadata } from './types';
7
+ import type { VersionMetadata } from './types';
8
+ import type { PluginOptions } from '@docusaurus/plugin-content-docs';
8
9
  import type { LoadContext } from '@docusaurus/types';
9
10
  export declare function getVersionedDocsDirPath(siteDir: string, pluginId: string): string;
10
11
  export declare function getVersionedSidebarsDirPath(siteDir: string, pluginId: string): string;
@@ -12,5 +13,5 @@ export declare function getVersionsFilePath(siteDir: string, pluginId: string):
12
13
  export declare function readVersionsMetadata({ context, options, }: {
13
14
  context: Pick<LoadContext, 'siteDir' | 'baseUrl' | 'i18n'>;
14
15
  options: Pick<PluginOptions, 'id' | 'path' | 'sidebarPath' | 'routeBasePath' | 'tagsBasePath' | 'includeCurrentVersion' | 'disableVersioning' | 'lastVersion' | 'versions' | 'onlyIncludeVersions' | 'editUrl' | 'editCurrentVersion'>;
15
- }): VersionMetadata[];
16
+ }): Promise<VersionMetadata[]>;
16
17
  export declare function getDocsDirPaths(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>): [string, string];