@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
package/lib/index.js CHANGED
@@ -9,37 +9,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.validateOptions = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
- const constants_1 = require("@docusaurus/core/lib/constants");
13
12
  const utils_1 = require("@docusaurus/utils");
14
13
  const sidebars_1 = require("./sidebars");
14
+ const generator_1 = require("./sidebars/generator");
15
15
  const docs_1 = require("./docs");
16
16
  const versions_1 = require("./versions");
17
17
  const cli_1 = require("./cli");
18
- const constants_2 = require("./constants");
19
- const lodash_1 = require("lodash");
18
+ const constants_1 = require("./constants");
20
19
  const globalData_1 = require("./globalData");
21
20
  const props_1 = require("./props");
22
21
  const translations_1 = require("./translations");
23
- const sidebarItemsGenerator_1 = require("./sidebarItemsGenerator");
24
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
25
- function pluginContentDocs(context, options) {
26
- var _a;
22
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
23
+ const tags_1 = require("./tags");
24
+ const routes_1 = require("./routes");
25
+ const utils_2 = require("./sidebars/utils");
26
+ const categoryGeneratedIndex_1 = require("./categoryGeneratedIndex");
27
+ async function pluginContentDocs(context, options) {
27
28
  const { siteDir, generatedFilesDir, baseUrl, siteConfig } = context;
28
- const versionsMetadata = versions_1.readVersionsMetadata({ context, options });
29
- const pluginId = (_a = options.id) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_PLUGIN_ID;
29
+ const versionsMetadata = await (0, versions_1.readVersionsMetadata)({ context, options });
30
+ const pluginId = options.id ?? utils_1.DEFAULT_PLUGIN_ID;
30
31
  const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-docs');
31
32
  const dataDir = path_1.default.join(pluginDataDirRoot, pluginId);
32
- const aliasedSource = (source) => `~docs/${utils_1.posixPath(path_1.default.relative(pluginDataDirRoot, source))}`;
33
+ const aliasedSource = (source) => `~docs/${(0, utils_1.posixPath)(path_1.default.relative(pluginDataDirRoot, source))}`;
33
34
  return {
34
35
  name: 'docusaurus-plugin-content-docs',
35
- getThemePath() {
36
- return path_1.default.resolve(__dirname, './theme');
37
- },
38
- getTypeScriptThemePath() {
39
- return path_1.default.resolve(__dirname, '..', 'src', 'theme');
40
- },
41
36
  extendCli(cli) {
42
- const isDefaultPluginId = pluginId === constants_1.DEFAULT_PLUGIN_ID;
37
+ const isDefaultPluginId = pluginId === utils_1.DEFAULT_PLUGIN_ID;
43
38
  // Need to create one distinct command per plugin instance
44
39
  // otherwise 2 instances would try to execute the command!
45
40
  const command = isDefaultPluginId
@@ -53,43 +48,38 @@ function pluginContentDocs(context, options) {
53
48
  .arguments('<version>')
54
49
  .description(commandDescription)
55
50
  .action((version) => {
56
- cli_1.cliDocsVersionCommand(version, siteDir, pluginId, {
51
+ (0, cli_1.cliDocsVersionCommand)(version, siteDir, pluginId, {
57
52
  path: options.path,
58
53
  sidebarPath: options.sidebarPath,
54
+ sidebarCollapsed: options.sidebarCollapsed,
55
+ sidebarCollapsible: options.sidebarCollapsible,
59
56
  });
60
57
  });
61
58
  },
62
59
  async getTranslationFiles({ content }) {
63
- return translations_1.getLoadedContentTranslationFiles(content);
64
- },
65
- getClientModules() {
66
- const modules = [];
67
- if (options.admonitions) {
68
- modules.push(require.resolve('remark-admonitions/styles/infima.css'));
69
- }
70
- return modules;
60
+ return (0, translations_1.getLoadedContentTranslationFiles)(content);
71
61
  },
72
62
  getPathsToWatch() {
73
63
  function getVersionPathsToWatch(version) {
74
64
  const result = [
75
- ...lodash_1.flatten(options.include.map((pattern) => versions_1.getDocsDirPaths(version).map((docsDirPath) => `${docsDirPath}/${pattern}`))),
76
- `${version.contentPath}/**/${sidebarItemsGenerator_1.CategoryMetadataFilenamePattern}`,
65
+ ...options.include.flatMap((pattern) => (0, versions_1.getDocsDirPaths)(version).map((docsDirPath) => `${docsDirPath}/${pattern}`)),
66
+ `${version.contentPath}/**/${generator_1.CategoryMetadataFilenamePattern}`,
77
67
  ];
78
68
  if (typeof version.sidebarFilePath === 'string') {
79
69
  result.unshift(version.sidebarFilePath);
80
70
  }
81
71
  return result;
82
72
  }
83
- return lodash_1.flatten(versionsMetadata.map(getVersionPathsToWatch));
73
+ return versionsMetadata.flatMap(getVersionPathsToWatch);
84
74
  },
85
75
  async loadContent() {
86
76
  async function loadVersionDocsBase(versionMetadata) {
87
- const docFiles = await docs_1.readVersionDocs(versionMetadata, options);
77
+ const docFiles = await (0, docs_1.readVersionDocs)(versionMetadata, options);
88
78
  if (docFiles.length === 0) {
89
79
  throw new Error(`Docs version "${versionMetadata.versionName}" has no docs! At least one doc should exist at "${path_1.default.relative(siteDir, versionMetadata.contentPath)}".`);
90
80
  }
91
81
  async function processVersionDoc(docFile) {
92
- return docs_1.processDocMetadata({
82
+ return (0, docs_1.processDocMetadata)({
93
83
  docFile,
94
84
  versionMetadata,
95
85
  context,
@@ -99,80 +89,37 @@ function pluginContentDocs(context, options) {
99
89
  return Promise.all(docFiles.map(processVersionDoc));
100
90
  }
101
91
  async function doLoadVersion(versionMetadata) {
102
- const unprocessedSidebars = sidebars_1.loadSidebars(versionMetadata.sidebarFilePath);
103
- const docsBase = await loadVersionDocsBase(versionMetadata);
104
- const docsBaseById = lodash_1.keyBy(docsBase, (doc) => doc.id);
105
- const sidebars = await sidebars_1.processSidebars({
92
+ const docs = await loadVersionDocsBase(versionMetadata);
93
+ const sidebars = await (0, sidebars_1.loadSidebars)(versionMetadata.sidebarFilePath, {
106
94
  sidebarItemsGenerator: options.sidebarItemsGenerator,
107
95
  numberPrefixParser: options.numberPrefixParser,
108
- unprocessedSidebars,
109
- docs: docsBase,
96
+ docs,
110
97
  version: versionMetadata,
98
+ sidebarOptions: {
99
+ sidebarCollapsed: options.sidebarCollapsed,
100
+ sidebarCollapsible: options.sidebarCollapsible,
101
+ },
102
+ categoryLabelSlugger: (0, utils_1.createSlugger)(),
111
103
  });
112
- const sidebarsUtils = sidebars_1.createSidebarsUtils(sidebars);
113
- const validDocIds = Object.keys(docsBaseById);
114
- sidebarsUtils.checkSidebarsDocIds(validDocIds, versionMetadata.sidebarFilePath);
115
- // Add sidebar/next/previous to the docs
116
- function addNavData(doc) {
117
- const { sidebarName, previousId, nextId, } = sidebarsUtils.getDocNavigation(doc.id);
118
- const toDocNavLink = (navDocId) => {
119
- var _a, _b;
120
- const { title, permalink, frontMatter } = docsBaseById[navDocId];
121
- return {
122
- title: (_b = (_a = frontMatter.pagination_label) !== null && _a !== void 0 ? _a : frontMatter.sidebar_label) !== null && _b !== void 0 ? _b : title,
123
- permalink,
124
- };
125
- };
126
- return {
127
- ...doc,
128
- sidebar: sidebarName,
129
- previous: previousId ? toDocNavLink(previousId) : undefined,
130
- next: nextId ? toDocNavLink(nextId) : undefined,
131
- };
132
- }
133
- const docs = docsBase.map(addNavData);
134
- // sort to ensure consistent output for tests
135
- docs.sort((a, b) => a.id.localeCompare(b.id));
136
- // TODO really useful? replace with global state logic?
137
- const permalinkToSidebar = {};
138
- Object.values(docs).forEach((doc) => {
139
- if (doc.sidebar) {
140
- permalinkToSidebar[doc.permalink] = doc.sidebar;
141
- }
142
- });
143
- // The "main doc" is the "version entry point"
144
- // We browse this doc by clicking on a version:
145
- // - the "home" doc (at '/docs/')
146
- // - the first doc of the first sidebar
147
- // - a random doc (if no docs are in any sidebar... edge case)
148
- function getMainDoc() {
149
- const versionHomeDoc = docs.find((doc) => doc.unversionedId === options.homePageId || doc.slug === '/');
150
- const firstDocIdOfFirstSidebar = sidebarsUtils.getFirstDocIdOfFirstSidebar();
151
- if (versionHomeDoc) {
152
- return versionHomeDoc;
153
- }
154
- else if (firstDocIdOfFirstSidebar) {
155
- return docs.find((doc) => doc.id === firstDocIdOfFirstSidebar);
156
- }
157
- else {
158
- return docs[0];
159
- }
160
- }
104
+ const sidebarsUtils = (0, utils_2.createSidebarsUtils)(sidebars);
161
105
  return {
162
106
  ...versionMetadata,
163
- mainDocId: getMainDoc().unversionedId,
107
+ docs: (0, docs_1.addDocNavigation)(docs, sidebarsUtils, versionMetadata.sidebarFilePath),
164
108
  sidebars,
165
- permalinkToSidebar,
166
- docs: docs.map(addNavData),
109
+ mainDocId: (0, docs_1.getMainDocId)({ docs, sidebarsUtils }),
110
+ categoryGeneratedIndices: (0, categoryGeneratedIndex_1.getCategoryGeneratedIndexMetadataList)({
111
+ docs,
112
+ sidebarsUtils,
113
+ }),
167
114
  };
168
115
  }
169
116
  async function loadVersion(versionMetadata) {
170
117
  try {
171
118
  return await doLoadVersion(versionMetadata);
172
119
  }
173
- catch (e) {
174
- console.error(chalk_1.default.red(`Loading of version failed for version "${versionMetadata.versionName}"`));
175
- throw e;
120
+ catch (err) {
121
+ logger_1.default.error `Loading of version failed for version name=${versionMetadata.versionName}`;
122
+ throw err;
176
123
  }
177
124
  }
178
125
  return {
@@ -180,66 +127,77 @@ function pluginContentDocs(context, options) {
180
127
  };
181
128
  },
182
129
  translateContent({ content, translationFiles }) {
183
- return translations_1.translateLoadedContent(content, translationFiles);
130
+ return (0, translations_1.translateLoadedContent)(content, translationFiles);
184
131
  },
185
132
  async contentLoaded({ content, actions }) {
186
133
  const { loadedVersions } = content;
187
- const { docLayoutComponent, docItemComponent } = options;
134
+ const { docLayoutComponent, docItemComponent, docCategoryGeneratedIndexComponent, breadcrumbs, } = options;
188
135
  const { addRoute, createData, setGlobalData } = actions;
189
- const createDocRoutes = async (docs) => {
190
- const routes = await Promise.all(docs.map(async (metadataItem) => {
191
- await createData(
192
- // Note that this created data path must be in sync with
193
- // metadataPath provided to mdx-loader.
194
- `${utils_1.docuHash(metadataItem.source)}.json`, JSON.stringify(metadataItem, null, 2));
195
- return {
196
- path: metadataItem.permalink,
197
- component: docItemComponent,
136
+ async function createVersionTagsRoutes(version) {
137
+ const versionTags = (0, tags_1.getVersionTags)(version.docs);
138
+ // TODO tags should be a sub route of the version route
139
+ async function createTagsListPage() {
140
+ const tagsProp = Object.values(versionTags).map((tagValue) => ({
141
+ name: tagValue.name,
142
+ permalink: tagValue.permalink,
143
+ count: tagValue.docIds.length,
144
+ }));
145
+ // Only create /tags page if there are tags.
146
+ if (Object.keys(tagsProp).length > 0) {
147
+ const tagsPropPath = await createData(`${(0, utils_1.docuHash)(`tags-list-${version.versionName}-prop`)}.json`, JSON.stringify(tagsProp, null, 2));
148
+ addRoute({
149
+ path: version.tagsPath,
150
+ exact: true,
151
+ component: options.docTagsListComponent,
152
+ modules: {
153
+ tags: aliasedSource(tagsPropPath),
154
+ },
155
+ });
156
+ }
157
+ }
158
+ // TODO tags should be a sub route of the version route
159
+ async function createTagDocListPage(tag) {
160
+ const tagProps = (0, props_1.toTagDocListProp)({
161
+ allTagsPath: version.tagsPath,
162
+ tag,
163
+ docs: version.docs,
164
+ });
165
+ const tagPropPath = await createData(`${(0, utils_1.docuHash)(`tag-${tag.permalink}`)}.json`, JSON.stringify(tagProps, null, 2));
166
+ addRoute({
167
+ path: tag.permalink,
168
+ component: options.docTagDocListComponent,
198
169
  exact: true,
199
170
  modules: {
200
- content: metadataItem.source,
171
+ tag: aliasedSource(tagPropPath),
201
172
  },
202
- };
203
- }));
204
- return routes.sort((a, b) => a.path.localeCompare(b.path));
205
- };
206
- async function doCreateVersionRoutes(loadedVersion) {
207
- const versionMetadataPropPath = await createData(`${utils_1.docuHash(`version-${loadedVersion.versionName}-metadata-prop`)}.json`, JSON.stringify(props_1.toVersionMetadataProp(pluginId, loadedVersion), null, 2));
208
- addRoute({
209
- path: loadedVersion.versionPath,
210
- // allow matching /docs/* as well
211
- exact: false,
212
- // main docs component (DocPage)
213
- component: docLayoutComponent,
214
- // sub-routes for each doc
215
- routes: await createDocRoutes(loadedVersion.docs),
216
- modules: {
217
- versionMetadata: aliasedSource(versionMetadataPropPath),
218
- },
219
- priority: loadedVersion.routePriority,
220
- });
221
- }
222
- async function createVersionRoutes(loadedVersion) {
223
- try {
224
- return await doCreateVersionRoutes(loadedVersion);
225
- }
226
- catch (e) {
227
- console.error(chalk_1.default.red(`Can't create version routes for version "${loadedVersion.versionName}"`));
228
- throw e;
173
+ });
229
174
  }
175
+ await createTagsListPage();
176
+ await Promise.all(Object.values(versionTags).map(createTagDocListPage));
230
177
  }
231
- await Promise.all(loadedVersions.map(createVersionRoutes));
178
+ await Promise.all(loadedVersions.map((loadedVersion) => (0, routes_1.createVersionRoutes)({
179
+ loadedVersion,
180
+ docItemComponent,
181
+ docLayoutComponent,
182
+ docCategoryGeneratedIndexComponent,
183
+ pluginId,
184
+ aliasedSource,
185
+ actions,
186
+ })));
187
+ // TODO tags should be a sub route of the version route
188
+ await Promise.all(loadedVersions.map(createVersionTagsRoutes));
232
189
  setGlobalData({
233
- path: utils_1.normalizeUrl([baseUrl, options.routeBasePath]),
190
+ path: (0, utils_1.normalizeUrl)([baseUrl, options.routeBasePath]),
234
191
  versions: loadedVersions.map(globalData_1.toGlobalDataVersion),
192
+ breadcrumbs,
235
193
  });
236
194
  },
237
195
  configureWebpack(_config, isServer, utils, content) {
238
196
  const { getJSLoader } = utils;
239
197
  const { rehypePlugins, remarkPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
240
198
  function getSourceToPermalink() {
241
- const allDocs = lodash_1.flatten(content.loadedVersions.map((v) => v.docs));
242
- return lodash_1.mapValues(lodash_1.keyBy(allDocs, (d) => d.source), (d) => d.permalink);
199
+ const allDocs = content.loadedVersions.flatMap((v) => v.docs);
200
+ return Object.fromEntries(allDocs.map(({ source, permalink }) => [source, permalink]));
243
201
  }
244
202
  const docsMarkdownOptions = {
245
203
  siteDir,
@@ -249,16 +207,17 @@ function pluginContentDocs(context, options) {
249
207
  if (siteConfig.onBrokenMarkdownLinks === 'ignore') {
250
208
  return;
251
209
  }
252
- utils_1.reportMessage(`Docs markdown link couldn't be resolved: (${brokenMarkdownLink.link}) in ${brokenMarkdownLink.filePath} for version ${brokenMarkdownLink.contentPaths.versionName}`, siteConfig.onBrokenMarkdownLinks);
210
+ (0, utils_1.reportMessage)(`Docs markdown link couldn't be resolved: (${brokenMarkdownLink.link}) in ${brokenMarkdownLink.filePath} for version ${brokenMarkdownLink.contentPaths.versionName}`, siteConfig.onBrokenMarkdownLinks);
253
211
  },
254
212
  };
255
213
  function createMDXLoaderRule() {
214
+ const contentDirs = versionsMetadata.flatMap(versions_1.getDocsDirPaths);
256
215
  return {
257
- test: /(\.mdx?)$/,
258
- include: lodash_1.flatten(versionsMetadata.map(versions_1.getDocsDirPaths))
216
+ test: /\.mdx?$/i,
217
+ include: contentDirs
259
218
  // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
260
219
  .map(utils_1.addTrailingPathSeparator),
261
- use: lodash_1.compact([
220
+ use: [
262
221
  getJSLoader({ isServer }),
263
222
  {
264
223
  loader: require.resolve('@docusaurus/mdx-loader'),
@@ -267,27 +226,34 @@ function pluginContentDocs(context, options) {
267
226
  rehypePlugins,
268
227
  beforeDefaultRehypePlugins,
269
228
  beforeDefaultRemarkPlugins,
270
- staticDir: path_1.default.join(siteDir, constants_1.STATIC_DIR_NAME),
229
+ staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
230
+ siteDir,
231
+ isMDXPartial: (0, utils_1.createAbsoluteFilePathMatcher)(options.exclude, contentDirs),
271
232
  metadataPath: (mdxPath) => {
272
233
  // Note that metadataPath must be the same/in-sync as
273
234
  // the path from createData for each MDX.
274
- const aliasedPath = utils_1.aliasedSitePath(mdxPath, siteDir);
275
- return path_1.default.join(dataDir, `${utils_1.docuHash(aliasedPath)}.json`);
235
+ const aliasedPath = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
236
+ return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
276
237
  },
238
+ // Assets allow to convert some relative images paths to
239
+ // require(...) calls
240
+ createAssets: ({ frontMatter, }) => ({
241
+ image: frontMatter.image,
242
+ }),
277
243
  },
278
244
  },
279
245
  {
280
246
  loader: path_1.default.resolve(__dirname, './markdown/index.js'),
281
247
  options: docsMarkdownOptions,
282
248
  },
283
- ]),
249
+ ].filter(Boolean),
284
250
  };
285
251
  }
286
252
  return {
287
253
  ignoreWarnings: [
288
254
  // Suppress warnings about non-existing of versions file.
289
255
  (e) => e.message.includes("Can't resolve") &&
290
- e.message.includes(constants_2.VERSIONS_JSON_FILE),
256
+ e.message.includes(constants_1.VERSIONS_JSON_FILE),
291
257
  ],
292
258
  resolve: {
293
259
  alias: {
package/lib/lastUpdate.js CHANGED
@@ -8,44 +8,31 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.getFileLastUpdate = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const shelljs_1 = tslib_1.__importDefault(require("shelljs"));
12
- const execa_1 = tslib_1.__importDefault(require("execa"));
13
- const path_1 = tslib_1.__importDefault(require("path"));
14
- const GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX = /^(\d+), (.+)$/;
11
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
+ const utils_1 = require("@docusaurus/utils");
15
13
  let showedGitRequirementError = false;
16
14
  async function getFileLastUpdate(filePath) {
17
15
  if (!filePath) {
18
16
  return null;
19
17
  }
20
- function getTimestampAndAuthor(str) {
21
- if (!str) {
22
- return null;
23
- }
24
- const temp = str.match(GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX);
25
- return !temp || temp.length < 3
26
- ? null
27
- : { timestamp: +temp[1], author: temp[2] };
28
- }
29
18
  // Wrap in try/catch in case the shell commands fail
30
19
  // (e.g. project doesn't use Git, etc).
31
20
  try {
32
- if (!shelljs_1.default.which('git')) {
33
- if (!showedGitRequirementError) {
34
- showedGitRequirementError = true;
35
- console.warn('Sorry, the docs plugin last update options require Git.');
36
- }
37
- return null;
38
- }
39
- const fileBasename = path_1.default.basename(filePath);
40
- const fileDirname = path_1.default.dirname(filePath);
41
- const { stdout } = await execa_1.default('git', ['log', '-1', '--format=%ct, %an', fileBasename], {
42
- cwd: fileDirname,
21
+ const result = (0, utils_1.getFileCommitDate)(filePath, {
22
+ age: 'newest',
23
+ includeAuthor: true,
43
24
  });
44
- return getTimestampAndAuthor(stdout);
25
+ return { timestamp: result.timestamp, author: result.author };
45
26
  }
46
- catch (error) {
47
- console.error(error);
27
+ catch (err) {
28
+ if (err instanceof utils_1.GitNotFoundError && !showedGitRequirementError) {
29
+ logger_1.default.warn('Sorry, the docs plugin last update options require Git.');
30
+ showedGitRequirementError = true;
31
+ }
32
+ else {
33
+ logger_1.default.error(err);
34
+ }
35
+ return null;
48
36
  }
49
- return null;
50
37
  }
51
38
  exports.getFileLastUpdate = getFileLastUpdate;
@@ -4,9 +4,6 @@
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
- /// <reference types="node" />
8
- interface Loader extends Function {
9
- (this: any, source: string): string | Buffer | void | undefined;
10
- }
11
- declare const markdownLoader: Loader;
12
- export default markdownLoader;
7
+ import type { DocsMarkdownOption } from '../types';
8
+ import type { LoaderContext } from 'webpack';
9
+ export default function markdownLoader(this: LoaderContext<DocsMarkdownOption>, source: string): void;
@@ -7,10 +7,10 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const linkify_1 = require("./linkify");
10
- const markdownLoader = function (source) {
10
+ function markdownLoader(source) {
11
11
  const fileString = source;
12
12
  const callback = this.async();
13
13
  const options = this.getOptions();
14
- return (callback && callback(null, linkify_1.linkify(fileString, this.resourcePath, options)));
15
- };
14
+ return (callback && callback(null, (0, linkify_1.linkify)(fileString, this.resourcePath, options)));
15
+ }
16
16
  exports.default = markdownLoader;
@@ -4,5 +4,5 @@
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 { DocsMarkdownOption } from '../types';
7
+ import type { DocsMarkdownOption } from '../types';
8
8
  export declare function linkify(fileString: string, filePath: string, options: DocsMarkdownOption): string;
@@ -10,7 +10,7 @@ exports.linkify = void 0;
10
10
  const versions_1 = require("../versions");
11
11
  const utils_1 = require("@docusaurus/utils");
12
12
  function getVersion(filePath, options) {
13
- const versionFound = options.versionsMetadata.find((version) => versions_1.getDocsDirPaths(version).some((docsDirPath) => filePath.startsWith(docsDirPath)));
13
+ const versionFound = options.versionsMetadata.find((version) => (0, versions_1.getDocsDirPaths)(version).some((docsDirPath) => filePath.startsWith(docsDirPath)));
14
14
  if (!versionFound) {
15
15
  throw new Error(`Unexpected error: Markdown file at "${filePath}" does not belong to any docs version!`);
16
16
  }
@@ -18,7 +18,7 @@ function getVersion(filePath, options) {
18
18
  }
19
19
  function linkify(fileString, filePath, options) {
20
20
  const { siteDir, sourceToPermalink, onBrokenMarkdownLink } = options;
21
- const { newContent, brokenMarkdownLinks } = utils_1.replaceMarkdownLinks({
21
+ const { newContent, brokenMarkdownLinks } = (0, utils_1.replaceMarkdownLinks)({
22
22
  siteDir,
23
23
  fileString,
24
24
  filePath,
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { NumberPrefixParser } from './types';
7
+ import type { NumberPrefixParser } from '@docusaurus/plugin-content-docs';
8
8
  export declare const DefaultNumberPrefixParser: NumberPrefixParser;
9
9
  export declare const DisabledNumberPrefixParser: NumberPrefixParser;
10
10
  export declare function stripNumberPrefix(str: string, parser: NumberPrefixParser): string;
@@ -8,27 +8,27 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.stripPathNumberPrefixes = exports.stripNumberPrefix = exports.DisabledNumberPrefixParser = exports.DefaultNumberPrefixParser = void 0;
10
10
  // Best-effort to avoid parsing some patterns as number prefix
11
- const IgnoredPrefixPatterns = (function () {
11
+ const IgnoredPrefixPatterns = (() => {
12
12
  // ignore common date-like patterns: https://github.com/facebook/docusaurus/issues/4640
13
- const DateLikePrefixRegex = /^((\d{2}|\d{4})[-_.]\d{2}([-_.](\d{2}|\d{4}))?)(.*)$/;
13
+ const DateLikePrefixRegex = /^(?:\d{2}|\d{4})[-_.]\d{2}(?:[-_.](?:\d{2}|\d{4}))?.*$/;
14
14
  // ignore common versioning patterns: https://github.com/facebook/docusaurus/issues/4653
15
- // note: we could try to parse float numbers in filenames but that is probably not worth it
16
- // as a version such as "8.0" can be interpreted as both a version and a float
17
- // User can configure his own NumberPrefixParser if he wants 8.0 to be interpreted as a float
18
- const VersionLikePrefixRegex = /^(\d+[-_.]\d+)(.*)$/;
15
+ // note: we could try to parse float numbers in filenames but that is
16
+ // probably not worth it as a version such as "8.0" can be interpreted as both
17
+ // a version and a float. User can configure her own NumberPrefixParser if
18
+ // she wants 8.0 to be interpreted as a float
19
+ const VersionLikePrefixRegex = /^\d+[-_.]\d+.*$/;
19
20
  return new RegExp(`${DateLikePrefixRegex.source}|${VersionLikePrefixRegex.source}`);
20
21
  })();
21
22
  const NumberPrefixRegex = /^(?<numberPrefix>\d+)(?<separator>\s*[-_.]+\s*)(?<suffix>.*)$/;
22
23
  // 0-myDoc => {filename: myDoc, numberPrefix: 0}
23
24
  // 003 - myDoc => {filename: myDoc, numberPrefix: 3}
24
25
  const DefaultNumberPrefixParser = (filename) => {
25
- var _a, _b, _c;
26
26
  if (IgnoredPrefixPatterns.exec(filename)) {
27
27
  return { filename, numberPrefix: undefined };
28
28
  }
29
29
  const match = NumberPrefixRegex.exec(filename);
30
- const cleanFileName = (_b = (_a = match === null || match === void 0 ? void 0 : match.groups) === null || _a === void 0 ? void 0 : _a.suffix) !== null && _b !== void 0 ? _b : filename;
31
- const numberPrefixString = (_c = match === null || match === void 0 ? void 0 : match.groups) === null || _c === void 0 ? void 0 : _c.numberPrefix;
30
+ const cleanFileName = match?.groups?.suffix ?? filename;
31
+ const numberPrefixString = match?.groups?.numberPrefix;
32
32
  const numberPrefix = numberPrefixString
33
33
  ? parseInt(numberPrefixString, 10)
34
34
  : undefined;
package/lib/options.d.ts CHANGED
@@ -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 { PluginOptions } from './types';
7
+ import type { PluginOptions } from '@docusaurus/plugin-content-docs';
8
8
  import { Joi } from '@docusaurus/utils-validation';
9
- import { OptionValidationContext, ValidationResult } from '@docusaurus/types';
9
+ import type { OptionValidationContext, ValidationResult } from '@docusaurus/types';
10
10
  export declare const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'>;
11
11
  export declare const OptionsSchema: Joi.ObjectSchema<any>;
12
- export declare function validateOptions({ validate, options, }: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions>;
12
+ export declare function validateOptions({ validate, options: userOptions, }: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions>;