@docusaurus/plugin-content-docs 2.0.0-beta.fc64c12e4 → 2.0.0

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 (236) 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 +57 -73
  5. package/lib/client/docsClientUtils.d.ts +9 -28
  6. package/lib/client/docsClientUtils.js +34 -43
  7. package/lib/client/index.d.ts +81 -0
  8. package/lib/client/index.js +67 -0
  9. package/lib/constants.d.ts +4 -0
  10. package/lib/constants.js +4 -1
  11. package/lib/docs.d.ts +33 -6
  12. package/lib/docs.js +201 -78
  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} +22 -3
  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 +120 -153
  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 +34 -26
  29. package/lib/props.d.ts +7 -2
  30. package/lib/props.js +84 -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 +25 -0
  35. package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +1 -7
  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 +59 -0
  41. package/lib/sidebars/postProcessor.d.ts +11 -0
  42. package/lib/sidebars/postProcessor.js +81 -0
  43. package/lib/sidebars/processor.d.ts +10 -0
  44. package/lib/sidebars/processor.js +79 -0
  45. package/lib/sidebars/types.d.ts +183 -0
  46. package/lib/{docFrontMatter.d.ts → sidebars/types.js} +2 -2
  47. package/lib/sidebars/utils.d.ts +55 -0
  48. package/lib/sidebars/utils.js +259 -0
  49. package/lib/sidebars/validation.d.ts +11 -0
  50. package/lib/sidebars/validation.js +143 -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 +100 -93
  57. package/lib/types.d.ts +13 -192
  58. package/lib/versions/files.d.ts +50 -0
  59. package/lib/versions/files.js +141 -0
  60. package/lib/versions/index.d.ts +36 -0
  61. package/lib/versions/index.js +154 -0
  62. package/lib/versions/validation.d.ts +17 -0
  63. package/lib/versions/validation.js +71 -0
  64. package/package.json +44 -30
  65. package/src/categoryGeneratedIndex.ts +60 -0
  66. package/src/cli.ts +88 -118
  67. package/src/client/docsClientUtils.ts +44 -71
  68. package/src/client/index.ts +158 -0
  69. package/src/constants.ts +4 -2
  70. package/src/docs.ts +277 -80
  71. package/src/frontMatter.ts +63 -0
  72. package/src/globalData.ts +57 -7
  73. package/src/index.ts +174 -221
  74. package/src/lastUpdate.ts +27 -38
  75. package/src/markdown/index.ts +10 -16
  76. package/src/markdown/linkify.ts +7 -4
  77. package/src/numberPrefix.ts +19 -26
  78. package/src/options.ts +38 -38
  79. package/src/plugin-content-docs.d.ts +570 -91
  80. package/src/props.ts +121 -20
  81. package/src/routes.ts +159 -0
  82. package/src/server-export.ts +26 -0
  83. package/src/sidebars/README.md +10 -0
  84. package/src/sidebars/generator.ts +292 -0
  85. package/src/sidebars/index.ts +118 -0
  86. package/src/sidebars/normalization.ts +91 -0
  87. package/src/sidebars/postProcessor.ts +112 -0
  88. package/src/sidebars/processor.ts +123 -0
  89. package/src/sidebars/types.ts +280 -0
  90. package/src/sidebars/utils.ts +393 -0
  91. package/src/sidebars/validation.ts +179 -0
  92. package/src/slug.ts +41 -22
  93. package/src/tags.ts +20 -0
  94. package/src/translations.ts +155 -124
  95. package/src/types.ts +17 -259
  96. package/src/versions/files.ts +216 -0
  97. package/src/versions/index.ts +246 -0
  98. package/src/versions/validation.ts +115 -0
  99. package/lib/.tsbuildinfo +0 -1
  100. package/lib/sidebarItemsGenerator.js +0 -215
  101. package/lib/sidebars.d.ts +0 -45
  102. package/lib/sidebars.js +0 -354
  103. package/lib/theme/hooks/useDocs.d.ts +0 -20
  104. package/lib/theme/hooks/useDocs.js +0 -75
  105. package/lib/versions.d.ts +0 -16
  106. package/lib/versions.js +0 -319
  107. package/src/__tests__/__fixtures__/bad-id-site/docs/invalid-id.md +0 -5
  108. package/src/__tests__/__fixtures__/bad-slug-on-doc-home-site/docs/docWithSlug.md +0 -5
  109. package/src/__tests__/__fixtures__/empty-site/docusaurus.config.js +0 -16
  110. package/src/__tests__/__fixtures__/empty-site/sidebars.json +0 -1
  111. package/src/__tests__/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -34
  112. package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -11
  113. package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -11
  114. package/src/__tests__/__fixtures__/sidebars/sidebars-category.js +0 -44
  115. package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -20
  116. package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed.json +0 -21
  117. package/src/__tests__/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -10
  118. package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -11
  119. package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -11
  120. package/src/__tests__/__fixtures__/sidebars/sidebars-link.json +0 -11
  121. package/src/__tests__/__fixtures__/sidebars/sidebars-unknown-type.json +0 -14
  122. package/src/__tests__/__fixtures__/sidebars/sidebars-wrong-field.json +0 -20
  123. package/src/__tests__/__fixtures__/sidebars/sidebars.json +0 -20
  124. package/src/__tests__/__fixtures__/simple-site/docs/_partials/somePartial.md +0 -3
  125. package/src/__tests__/__fixtures__/simple-site/docs/_partials/subfolder/somePartial.md +0 -3
  126. package/src/__tests__/__fixtures__/simple-site/docs/_somePartial.md +0 -3
  127. package/src/__tests__/__fixtures__/simple-site/docs/foo/bar.md +0 -69
  128. package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +0 -70
  129. package/src/__tests__/__fixtures__/simple-site/docs/headingAsTitle.md +0 -1
  130. package/src/__tests__/__fixtures__/simple-site/docs/hello.md +0 -53
  131. package/src/__tests__/__fixtures__/simple-site/docs/ipsum.md +0 -5
  132. package/src/__tests__/__fixtures__/simple-site/docs/lorem.md +0 -6
  133. package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +0 -5
  134. package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +0 -5
  135. package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +0 -5
  136. package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +0 -5
  137. package/src/__tests__/__fixtures__/simple-site/docs/slugs/absoluteSlug.md +0 -5
  138. package/src/__tests__/__fixtures__/simple-site/docs/slugs/relativeSlug.md +0 -5
  139. package/src/__tests__/__fixtures__/simple-site/docs/slugs/resolvedSlug.md +0 -5
  140. package/src/__tests__/__fixtures__/simple-site/docs/slugs/tryToEscapeSlug.md +0 -5
  141. package/src/__tests__/__fixtures__/simple-site/docusaurus.config.js +0 -14
  142. package/src/__tests__/__fixtures__/simple-site/sidebars.json +0 -23
  143. package/src/__tests__/__fixtures__/simple-site/wrong-sidebars.json +0 -7
  144. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/0-getting-started.md +0 -3
  145. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/1-installation.md +0 -3
  146. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/00_api-overview.md +0 -3
  147. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/0 --- Client API.md +0 -1
  148. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/1 --- Server API.md +0 -1
  149. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/0. Plugin API.md +0 -1
  150. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/1. Theme API.md +0 -1
  151. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/_category_.yml +0 -1
  152. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/03_api-end.md +0 -3
  153. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/_category_.json +0 -3
  154. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/0-guide2.5.md +0 -8
  155. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/02-guide2.md +0 -7
  156. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/_category_.json +0 -3
  157. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/a-guide4.md +0 -7
  158. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/b-guide5.md +0 -7
  159. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/guide3.md +0 -8
  160. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/z-guide1.md +0 -8
  161. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars.js +0 -23
  162. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js +0 -16
  163. package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-1.md +0 -7
  164. package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-2.md +0 -8
  165. package/src/__tests__/__fixtures__/site-with-doc-label/docusaurus.config.js +0 -14
  166. package/src/__tests__/__fixtures__/site-with-doc-label/sidebars.json +0 -14
  167. package/src/__tests__/__fixtures__/versioned-site/community/team.md +0 -1
  168. package/src/__tests__/__fixtures__/versioned-site/community_sidebars.json +0 -3
  169. package/src/__tests__/__fixtures__/versioned-site/community_versioned_docs/version-1.0.0/team.md +0 -1
  170. package/src/__tests__/__fixtures__/versioned-site/community_versioned_sidebars/version-1.0.0-sidebars.json +0 -3
  171. package/src/__tests__/__fixtures__/versioned-site/community_versions.json +0 -1
  172. package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +0 -4
  173. package/src/__tests__/__fixtures__/versioned-site/docs/hello.md +0 -1
  174. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/absoluteSlug.md +0 -5
  175. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/relativeSlug.md +0 -5
  176. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/resolvedSlug.md +0 -5
  177. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/tryToEscapeSlug.md +0 -5
  178. package/src/__tests__/__fixtures__/versioned-site/docusaurus.config.js +0 -18
  179. package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
  180. package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs-community/current/team.md +0 -5
  181. package/src/__tests__/__fixtures__/versioned-site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
  182. package/src/__tests__/__fixtures__/versioned-site/sidebars.json +0 -10
  183. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/bar.md +0 -4
  184. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/baz.md +0 -1
  185. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md +0 -1
  186. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/somePartial.md +0 -3
  187. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/subfolder/somePartial.md +0 -3
  188. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_somePartial.md +0 -3
  189. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/foo/bar.md +0 -1
  190. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md +0 -1
  191. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootAbsoluteSlug.md +0 -5
  192. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootRelativeSlug.md +0 -5
  193. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootResolvedSlug.md +0 -5
  194. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootTryToEscapeSlug.md +0 -5
  195. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/absoluteSlug.md +0 -5
  196. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/relativeSlug.md +0 -5
  197. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/resolvedSlug.md +0 -5
  198. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/tryToEscapeSlug.md +0 -5
  199. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.0-sidebars.json +0 -11
  200. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +0 -10
  201. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-withSlugs-sidebars.json +0 -5
  202. package/src/__tests__/__fixtures__/versioned-site/versions.json +0 -5
  203. package/src/__tests__/__snapshots__/cli.test.ts.snap +0 -95
  204. package/src/__tests__/__snapshots__/index.test.ts.snap +0 -1926
  205. package/src/__tests__/__snapshots__/sidebars.test.ts.snap +0 -233
  206. package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -484
  207. package/src/__tests__/cli.test.ts +0 -337
  208. package/src/__tests__/docFrontMatter.test.ts +0 -244
  209. package/src/__tests__/docs.test.ts +0 -878
  210. package/src/__tests__/index.test.ts +0 -1885
  211. package/src/__tests__/lastUpdate.test.ts +0 -69
  212. package/src/__tests__/numberPrefix.test.ts +0 -199
  213. package/src/__tests__/options.test.ts +0 -272
  214. package/src/__tests__/sidebarItemsGenerator.test.ts +0 -358
  215. package/src/__tests__/sidebars.test.ts +0 -746
  216. package/src/__tests__/slug.test.ts +0 -109
  217. package/src/__tests__/translations.test.ts +0 -158
  218. package/src/__tests__/versions.test.ts +0 -741
  219. package/src/client/__tests__/docsClientUtils.test.ts +0 -371
  220. package/src/docFrontMatter.ts +0 -41
  221. package/src/markdown/__tests__/__fixtures__/docs/doc-localized.md +0 -1
  222. package/src/markdown/__tests__/__fixtures__/docs/doc1.md +0 -13
  223. package/src/markdown/__tests__/__fixtures__/docs/doc2.md +0 -12
  224. package/src/markdown/__tests__/__fixtures__/docs/doc4.md +0 -19
  225. package/src/markdown/__tests__/__fixtures__/docs/doc5.md +0 -6
  226. package/src/markdown/__tests__/__fixtures__/docs/subdir/doc3.md +0 -3
  227. package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/doc2.md +0 -7
  228. package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/subdir/doc1.md +0 -3
  229. package/src/markdown/__tests__/__snapshots__/linkify.test.ts.snap +0 -82
  230. package/src/markdown/__tests__/linkify.test.ts +0 -190
  231. package/src/sidebarItemsGenerator.ts +0 -315
  232. package/src/sidebars.ts +0 -589
  233. package/src/theme/hooks/useDocs.ts +0 -103
  234. package/src/versions.ts +0 -572
  235. package/tsconfig.json +0 -9
  236. package/types.d.ts +0 -13
package/lib/index.js CHANGED
@@ -9,37 +9,35 @@ 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");
12
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
13
14
  const utils_1 = require("@docusaurus/utils");
14
15
  const sidebars_1 = require("./sidebars");
16
+ const generator_1 = require("./sidebars/generator");
15
17
  const docs_1 = require("./docs");
16
18
  const versions_1 = require("./versions");
17
19
  const cli_1 = require("./cli");
18
- const constants_2 = require("./constants");
19
- const lodash_1 = require("lodash");
20
+ const constants_1 = require("./constants");
20
21
  const globalData_1 = require("./globalData");
21
22
  const props_1 = require("./props");
23
+ const categoryGeneratedIndex_1 = require("./categoryGeneratedIndex");
22
24
  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;
25
+ const tags_1 = require("./tags");
26
+ const routes_1 = require("./routes");
27
+ const utils_2 = require("./sidebars/utils");
28
+ async function pluginContentDocs(context, options) {
27
29
  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;
30
+ // Mutate options to resolve sidebar path according to siteDir
31
+ options.sidebarPath = (0, sidebars_1.resolveSidebarPathOption)(siteDir, options.sidebarPath);
32
+ const versionsMetadata = await (0, versions_1.readVersionsMetadata)({ context, options });
33
+ const pluginId = options.id;
30
34
  const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-docs');
31
35
  const dataDir = path_1.default.join(pluginDataDirRoot, pluginId);
32
- const aliasedSource = (source) => `~docs/${utils_1.posixPath(path_1.default.relative(pluginDataDirRoot, source))}`;
36
+ const aliasedSource = (source) => `~docs/${(0, utils_1.posixPath)(path_1.default.relative(pluginDataDirRoot, source))}`;
33
37
  return {
34
38
  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
39
  extendCli(cli) {
42
- const isDefaultPluginId = pluginId === constants_1.DEFAULT_PLUGIN_ID;
40
+ const isDefaultPluginId = pluginId === utils_1.DEFAULT_PLUGIN_ID;
43
41
  // Need to create one distinct command per plugin instance
44
42
  // otherwise 2 instances would try to execute the command!
45
43
  const command = isDefaultPluginId
@@ -52,121 +50,71 @@ function pluginContentDocs(context, options) {
52
50
  .command(command)
53
51
  .arguments('<version>')
54
52
  .description(commandDescription)
55
- .action((version) => {
56
- cli_1.cliDocsVersionCommand(version, siteDir, pluginId, {
57
- path: options.path,
58
- sidebarPath: options.sidebarPath,
59
- sidebarCollapsed: options.sidebarCollapsed,
60
- sidebarCollapsible: options.sidebarCollapsible,
61
- });
62
- });
53
+ .action((version) => (0, cli_1.cliDocsVersionCommand)(version, options, context));
63
54
  },
64
- async getTranslationFiles({ content }) {
65
- return translations_1.getLoadedContentTranslationFiles(content);
55
+ getTranslationFiles({ content }) {
56
+ return (0, translations_1.getLoadedContentTranslationFiles)(content);
66
57
  },
67
58
  getPathsToWatch() {
68
59
  function getVersionPathsToWatch(version) {
69
60
  const result = [
70
- ...lodash_1.flatten(options.include.map((pattern) => versions_1.getDocsDirPaths(version).map((docsDirPath) => `${docsDirPath}/${pattern}`))),
71
- `${version.contentPath}/**/${sidebarItemsGenerator_1.CategoryMetadataFilenamePattern}`,
61
+ ...options.include.flatMap((pattern) => (0, utils_1.getContentPathList)(version).map((docsDirPath) => `${docsDirPath}/${pattern}`)),
62
+ `${version.contentPath}/**/${generator_1.CategoryMetadataFilenamePattern}`,
72
63
  ];
73
64
  if (typeof version.sidebarFilePath === 'string') {
74
65
  result.unshift(version.sidebarFilePath);
75
66
  }
76
67
  return result;
77
68
  }
78
- return lodash_1.flatten(versionsMetadata.map(getVersionPathsToWatch));
69
+ return versionsMetadata.flatMap(getVersionPathsToWatch);
79
70
  },
80
71
  async loadContent() {
81
72
  async function loadVersionDocsBase(versionMetadata) {
82
- const docFiles = await docs_1.readVersionDocs(versionMetadata, options);
73
+ const docFiles = await (0, docs_1.readVersionDocs)(versionMetadata, options);
83
74
  if (docFiles.length === 0) {
84
75
  throw new Error(`Docs version "${versionMetadata.versionName}" has no docs! At least one doc should exist at "${path_1.default.relative(siteDir, versionMetadata.contentPath)}".`);
85
76
  }
86
- async function processVersionDoc(docFile) {
87
- return docs_1.processDocMetadata({
77
+ function processVersionDoc(docFile) {
78
+ return (0, docs_1.processDocMetadata)({
88
79
  docFile,
89
80
  versionMetadata,
90
81
  context,
91
82
  options,
83
+ env: process.env.NODE_ENV,
92
84
  });
93
85
  }
94
86
  return Promise.all(docFiles.map(processVersionDoc));
95
87
  }
96
88
  async function doLoadVersion(versionMetadata) {
97
- const unprocessedSidebars = sidebars_1.loadSidebars(versionMetadata.sidebarFilePath, {
98
- sidebarCollapsed: options.sidebarCollapsed,
99
- sidebarCollapsible: options.sidebarCollapsible,
100
- });
101
89
  const docsBase = await loadVersionDocsBase(versionMetadata);
102
- const docsBaseById = lodash_1.keyBy(docsBase, (doc) => doc.id);
103
- const sidebars = await sidebars_1.processSidebars({
90
+ const [drafts, docs] = lodash_1.default.partition(docsBase, (doc) => doc.draft);
91
+ const sidebars = await (0, sidebars_1.loadSidebars)(versionMetadata.sidebarFilePath, {
104
92
  sidebarItemsGenerator: options.sidebarItemsGenerator,
105
93
  numberPrefixParser: options.numberPrefixParser,
106
- unprocessedSidebars,
107
- docs: docsBase,
94
+ docs,
95
+ drafts,
108
96
  version: versionMetadata,
109
- options: {
97
+ sidebarOptions: {
110
98
  sidebarCollapsed: options.sidebarCollapsed,
111
99
  sidebarCollapsible: options.sidebarCollapsible,
112
100
  },
101
+ categoryLabelSlugger: (0, utils_1.createSlugger)(),
113
102
  });
114
- const sidebarsUtils = sidebars_1.createSidebarsUtils(sidebars);
115
- const validDocIds = Object.keys(docsBaseById);
116
- sidebarsUtils.checkSidebarsDocIds(validDocIds, versionMetadata.sidebarFilePath);
117
- // Add sidebar/next/previous to the docs
118
- function addNavData(doc) {
119
- const { sidebarName, previousId, nextId, } = sidebarsUtils.getDocNavigation(doc.id);
120
- const toDocNavLink = (navDocId) => {
121
- var _a, _b;
122
- const { title, permalink, frontMatter } = docsBaseById[navDocId];
123
- return {
124
- title: (_b = (_a = frontMatter.pagination_label) !== null && _a !== void 0 ? _a : frontMatter.sidebar_label) !== null && _b !== void 0 ? _b : title,
125
- permalink,
126
- };
127
- };
128
- return {
129
- ...doc,
130
- sidebar: sidebarName,
131
- previous: previousId ? toDocNavLink(previousId) : undefined,
132
- next: nextId ? toDocNavLink(nextId) : undefined,
133
- };
134
- }
135
- const docs = docsBase.map(addNavData);
136
- // sort to ensure consistent output for tests
137
- docs.sort((a, b) => a.id.localeCompare(b.id));
138
- // The "main doc" is the "version entry point"
139
- // We browse this doc by clicking on a version:
140
- // - the "home" doc (at '/docs/')
141
- // - the first doc of the first sidebar
142
- // - a random doc (if no docs are in any sidebar... edge case)
143
- function getMainDoc() {
144
- const versionHomeDoc = docs.find((doc) => doc.unversionedId === options.homePageId || doc.slug === '/');
145
- const firstDocIdOfFirstSidebar = sidebarsUtils.getFirstDocIdOfFirstSidebar();
146
- if (versionHomeDoc) {
147
- return versionHomeDoc;
148
- }
149
- else if (firstDocIdOfFirstSidebar) {
150
- return docs.find((doc) => doc.id === firstDocIdOfFirstSidebar);
151
- }
152
- else {
153
- return docs[0];
154
- }
155
- }
103
+ const sidebarsUtils = (0, utils_2.createSidebarsUtils)(sidebars);
156
104
  return {
157
105
  ...versionMetadata,
158
- mainDocId: getMainDoc().unversionedId,
106
+ docs: (0, docs_1.addDocNavigation)(docs, sidebarsUtils, versionMetadata.sidebarFilePath),
107
+ drafts,
159
108
  sidebars,
160
- docs: docs.map(addNavData),
161
109
  };
162
110
  }
163
111
  async function loadVersion(versionMetadata) {
164
112
  try {
165
113
  return await doLoadVersion(versionMetadata);
166
114
  }
167
- catch (e) {
168
- console.error(chalk_1.default.red(`Loading of version failed for version "${versionMetadata.versionName}"`));
169
- throw e;
115
+ catch (err) {
116
+ logger_1.default.error `Loading of version failed for version name=${versionMetadata.versionName}`;
117
+ throw err;
170
118
  }
171
119
  }
172
120
  return {
@@ -174,123 +122,142 @@ function pluginContentDocs(context, options) {
174
122
  };
175
123
  },
176
124
  translateContent({ content, translationFiles }) {
177
- return translations_1.translateLoadedContent(content, translationFiles);
125
+ return (0, translations_1.translateLoadedContent)(content, translationFiles);
178
126
  },
179
127
  async contentLoaded({ content, actions }) {
180
128
  const { loadedVersions } = content;
181
- const { docLayoutComponent, docItemComponent } = options;
129
+ const { docLayoutComponent, docItemComponent, docCategoryGeneratedIndexComponent, breadcrumbs, } = options;
182
130
  const { addRoute, createData, setGlobalData } = actions;
183
- const createDocRoutes = async (docs) => {
184
- const routes = await Promise.all(docs.map(async (metadataItem) => {
185
- await createData(
186
- // Note that this created data path must be in sync with
187
- // metadataPath provided to mdx-loader.
188
- `${utils_1.docuHash(metadataItem.source)}.json`, JSON.stringify(metadataItem, null, 2));
189
- const docRoute = {
190
- path: metadataItem.permalink,
191
- component: docItemComponent,
131
+ const versions = loadedVersions.map((version) => {
132
+ const sidebarsUtils = (0, utils_2.createSidebarsUtils)(version.sidebars);
133
+ return {
134
+ ...version,
135
+ sidebarsUtils,
136
+ categoryGeneratedIndices: (0, categoryGeneratedIndex_1.getCategoryGeneratedIndexMetadataList)({
137
+ docs: version.docs,
138
+ sidebarsUtils,
139
+ }),
140
+ };
141
+ });
142
+ async function createVersionTagsRoutes(version) {
143
+ const versionTags = (0, tags_1.getVersionTags)(version.docs);
144
+ // TODO tags should be a sub route of the version route
145
+ async function createTagsListPage() {
146
+ const tagsProp = Object.values(versionTags).map((tagValue) => ({
147
+ label: tagValue.label,
148
+ permalink: tagValue.permalink,
149
+ count: tagValue.docIds.length,
150
+ }));
151
+ // Only create /tags page if there are tags.
152
+ if (tagsProp.length > 0) {
153
+ const tagsPropPath = await createData(`${(0, utils_1.docuHash)(`tags-list-${version.versionName}-prop`)}.json`, JSON.stringify(tagsProp, null, 2));
154
+ addRoute({
155
+ path: version.tagsPath,
156
+ exact: true,
157
+ component: options.docTagsListComponent,
158
+ modules: {
159
+ tags: aliasedSource(tagsPropPath),
160
+ },
161
+ });
162
+ }
163
+ }
164
+ // TODO tags should be a sub route of the version route
165
+ async function createTagDocListPage(tag) {
166
+ const tagProps = (0, props_1.toTagDocListProp)({
167
+ allTagsPath: version.tagsPath,
168
+ tag,
169
+ docs: version.docs,
170
+ });
171
+ const tagPropPath = await createData(`${(0, utils_1.docuHash)(`tag-${tag.permalink}`)}.json`, JSON.stringify(tagProps, null, 2));
172
+ addRoute({
173
+ path: tag.permalink,
174
+ component: options.docTagDocListComponent,
192
175
  exact: true,
193
176
  modules: {
194
- content: metadataItem.source,
177
+ tag: aliasedSource(tagPropPath),
195
178
  },
196
- // Because the parent (DocPage) comp need to access it easily
197
- // This permits to render the sidebar once without unmount/remount when navigating (and preserve sidebar state)
198
- ...(metadataItem.sidebar && {
199
- sidebar: metadataItem.sidebar,
200
- }),
201
- };
202
- return docRoute;
203
- }));
204
- return routes.sort((a, b) => a.path.localeCompare(b.path));
205
- };
206
- async function doCreateVersionRoutes(loadedVersion) {
207
- const versionMetadata = props_1.toVersionMetadataProp(pluginId, loadedVersion);
208
- const versionMetadataPropPath = await createData(`${utils_1.docuHash(`version-${loadedVersion.versionName}-metadata-prop`)}.json`, JSON.stringify(versionMetadata, null, 2));
209
- addRoute({
210
- path: loadedVersion.versionPath,
211
- // allow matching /docs/* as well
212
- exact: false,
213
- // main docs component (DocPage)
214
- component: docLayoutComponent,
215
- // sub-routes for each doc
216
- routes: await createDocRoutes(loadedVersion.docs),
217
- modules: {
218
- versionMetadata: aliasedSource(versionMetadataPropPath),
219
- },
220
- priority: loadedVersion.routePriority,
221
- });
222
- }
223
- async function createVersionRoutes(loadedVersion) {
224
- try {
225
- return await doCreateVersionRoutes(loadedVersion);
226
- }
227
- catch (e) {
228
- console.error(chalk_1.default.red(`Can't create version routes for version "${loadedVersion.versionName}"`));
229
- throw e;
179
+ });
230
180
  }
181
+ await createTagsListPage();
182
+ await Promise.all(Object.values(versionTags).map(createTagDocListPage));
231
183
  }
232
- await Promise.all(loadedVersions.map(createVersionRoutes));
184
+ await Promise.all(versions.map((version) => (0, routes_1.createVersionRoutes)({
185
+ version,
186
+ docItemComponent,
187
+ docLayoutComponent,
188
+ docCategoryGeneratedIndexComponent,
189
+ pluginId,
190
+ aliasedSource,
191
+ actions,
192
+ })));
193
+ // TODO tags should be a sub route of the version route
194
+ await Promise.all(versions.map(createVersionTagsRoutes));
233
195
  setGlobalData({
234
- path: utils_1.normalizeUrl([baseUrl, options.routeBasePath]),
235
- versions: loadedVersions.map(globalData_1.toGlobalDataVersion),
196
+ path: (0, utils_1.normalizeUrl)([baseUrl, options.routeBasePath]),
197
+ versions: versions.map(globalData_1.toGlobalDataVersion),
198
+ breadcrumbs,
236
199
  });
237
200
  },
238
201
  configureWebpack(_config, isServer, utils, content) {
239
202
  const { getJSLoader } = utils;
240
203
  const { rehypePlugins, remarkPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
241
204
  function getSourceToPermalink() {
242
- const allDocs = lodash_1.flatten(content.loadedVersions.map((v) => v.docs));
243
- return lodash_1.mapValues(lodash_1.keyBy(allDocs, (d) => d.source), (d) => d.permalink);
205
+ const allDocs = content.loadedVersions.flatMap((v) => v.docs);
206
+ return Object.fromEntries(allDocs.map(({ source, permalink }) => [source, permalink]));
244
207
  }
245
208
  const docsMarkdownOptions = {
246
209
  siteDir,
247
210
  sourceToPermalink: getSourceToPermalink(),
248
211
  versionsMetadata,
249
212
  onBrokenMarkdownLink: (brokenMarkdownLink) => {
250
- if (siteConfig.onBrokenMarkdownLinks === 'ignore') {
251
- return;
252
- }
253
- utils_1.reportMessage(`Docs markdown link couldn't be resolved: (${brokenMarkdownLink.link}) in ${brokenMarkdownLink.filePath} for version ${brokenMarkdownLink.contentPaths.versionName}`, siteConfig.onBrokenMarkdownLinks);
213
+ logger_1.default.report(siteConfig.onBrokenMarkdownLinks) `Docs markdown link couldn't be resolved: (url=${brokenMarkdownLink.link}) in path=${brokenMarkdownLink.filePath} for version number=${brokenMarkdownLink.contentPaths.versionName}`;
254
214
  },
255
215
  };
256
216
  function createMDXLoaderRule() {
257
- const contentDirs = lodash_1.flatten(versionsMetadata.map(versions_1.getDocsDirPaths));
217
+ const contentDirs = versionsMetadata.flatMap(utils_1.getContentPathList);
258
218
  return {
259
- test: /(\.mdx?)$/,
219
+ test: /\.mdx?$/i,
260
220
  include: contentDirs
261
221
  // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
262
222
  .map(utils_1.addTrailingPathSeparator),
263
- use: lodash_1.compact([
223
+ use: [
264
224
  getJSLoader({ isServer }),
265
225
  {
266
226
  loader: require.resolve('@docusaurus/mdx-loader'),
267
227
  options: {
228
+ admonitions: options.admonitions,
268
229
  remarkPlugins,
269
230
  rehypePlugins,
270
231
  beforeDefaultRehypePlugins,
271
232
  beforeDefaultRemarkPlugins,
272
- staticDir: path_1.default.join(siteDir, constants_1.STATIC_DIR_NAME),
273
- isMDXPartial: utils_1.createAbsoluteFilePathMatcher(options.exclude, contentDirs),
233
+ staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
234
+ siteDir,
235
+ isMDXPartial: (0, utils_1.createAbsoluteFilePathMatcher)(options.exclude, contentDirs),
274
236
  metadataPath: (mdxPath) => {
275
237
  // Note that metadataPath must be the same/in-sync as
276
238
  // the path from createData for each MDX.
277
- const aliasedPath = utils_1.aliasedSitePath(mdxPath, siteDir);
278
- return path_1.default.join(dataDir, `${utils_1.docuHash(aliasedPath)}.json`);
239
+ const aliasedPath = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
240
+ return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
279
241
  },
242
+ // Assets allow to convert some relative images paths to
243
+ // require(...) calls
244
+ createAssets: ({ frontMatter, }) => ({
245
+ image: frontMatter.image,
246
+ }),
280
247
  },
281
248
  },
282
249
  {
283
250
  loader: path_1.default.resolve(__dirname, './markdown/index.js'),
284
251
  options: docsMarkdownOptions,
285
252
  },
286
- ]),
253
+ ].filter(Boolean),
287
254
  };
288
255
  }
289
256
  return {
290
257
  ignoreWarnings: [
291
258
  // Suppress warnings about non-existing of versions file.
292
259
  (e) => e.message.includes("Can't resolve") &&
293
- e.message.includes(constants_2.VERSIONS_JSON_FILE),
260
+ e.message.includes(constants_1.VERSIONS_JSON_FILE),
294
261
  ],
295
262
  resolve: {
296
263
  alias: {
@@ -4,9 +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
- declare type FileLastUpdateData = {
8
- timestamp?: number;
9
- author?: string;
10
- };
11
- export declare function getFileLastUpdate(filePath?: string): Promise<FileLastUpdateData | null>;
12
- export {};
7
+ export declare function getFileLastUpdate(filePath: string): Promise<{
8
+ timestamp: number;
9
+ author: string;
10
+ } | null>;
package/lib/lastUpdate.js CHANGED
@@ -8,44 +8,40 @@
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;
14
+ let showedFileNotTrackedError = false;
16
15
  async function getFileLastUpdate(filePath) {
17
16
  if (!filePath) {
18
17
  return null;
19
18
  }
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
19
  // Wrap in try/catch in case the shell commands fail
30
20
  // (e.g. project doesn't use Git, etc).
31
21
  try {
32
- if (!shelljs_1.default.which('git')) {
22
+ const result = (0, utils_1.getFileCommitDate)(filePath, {
23
+ age: 'newest',
24
+ includeAuthor: true,
25
+ });
26
+ return { timestamp: result.timestamp, author: result.author };
27
+ }
28
+ catch (err) {
29
+ if (err instanceof utils_1.GitNotFoundError) {
33
30
  if (!showedGitRequirementError) {
31
+ logger_1.default.warn('Sorry, the docs plugin last update options require Git.');
34
32
  showedGitRequirementError = true;
35
- console.warn('Sorry, the docs plugin last update options require Git.');
36
33
  }
37
- return null;
38
34
  }
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,
43
- });
44
- return getTimestampAndAuthor(stdout);
45
- }
46
- catch (error) {
47
- console.error(error);
35
+ else if (err instanceof utils_1.FileNotTrackedError) {
36
+ if (!showedFileNotTrackedError) {
37
+ logger_1.default.warn('Cannot infer the update date for some files, as they are not tracked by git.');
38
+ showedFileNotTrackedError = true;
39
+ }
40
+ }
41
+ else {
42
+ logger_1.default.warn(err);
43
+ }
44
+ return null;
48
45
  }
49
- return null;
50
46
  }
51
47
  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(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;
@@ -7,10 +7,13 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.linkify = void 0;
10
- const versions_1 = require("../versions");
11
10
  const utils_1 = require("@docusaurus/utils");
12
11
  function getVersion(filePath, options) {
13
- const versionFound = options.versionsMetadata.find((version) => versions_1.getDocsDirPaths(version).some((docsDirPath) => filePath.startsWith(docsDirPath)));
12
+ const versionFound = options.versionsMetadata.find((version) => (0, utils_1.getContentPathList)(version).some((docsDirPath) => filePath.startsWith(docsDirPath)));
13
+ // At this point, this should never happen, because the MDX loaders' paths are
14
+ // literally using the version content paths; but if we allow sourcing content
15
+ // from outside the docs directory (through the `include` option, for example;
16
+ // is there a compelling use-case?), this would actually be testable
14
17
  if (!versionFound) {
15
18
  throw new Error(`Unexpected error: Markdown file at "${filePath}" does not belong to any docs version!`);
16
19
  }
@@ -18,7 +21,7 @@ function getVersion(filePath, options) {
18
21
  }
19
22
  function linkify(fileString, filePath, options) {
20
23
  const { siteDir, sourceToPermalink, onBrokenMarkdownLink } = options;
21
- const { newContent, brokenMarkdownLinks } = utils_1.replaceMarkdownLinks({
24
+ const { newContent, brokenMarkdownLinks } = (0, utils_1.replaceMarkdownLinks)({
22
25
  siteDir,
23
26
  fileString,
24
27
  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,33 +8,28 @@
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 () {
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}))?)(.*)$/;
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+)(.*)$/;
19
- return new RegExp(`${DateLikePrefixRegex.source}|${VersionLikePrefixRegex.source}`);
20
- })();
21
- const NumberPrefixRegex = /^(?<numberPrefix>\d+)(?<separator>\s*[-_.]+\s*)(?<suffix>.*)$/;
11
+ // ignore common date-like patterns: https://github.com/facebook/docusaurus/issues/4640
12
+ // ignore common versioning patterns: https://github.com/facebook/docusaurus/issues/4653
13
+ // Both of them would look like 7.0-foo or 2021-11-foo
14
+ // note: we could try to parse float numbers in filenames, but that is probably
15
+ // not worth it, as a version such as "8.0" can be interpreted as either a
16
+ // version or a float. User can configure her own NumberPrefixParser if she
17
+ // wants 8.0 to be interpreted as a float
18
+ const ignoredPrefixPattern = /^\d+[-_.]\d+/;
19
+ const numberPrefixPattern = /^(?<numberPrefix>\d+)\s*[-_.]+\s*(?<suffix>[^-_.\s].*)$/;
22
20
  // 0-myDoc => {filename: myDoc, numberPrefix: 0}
23
21
  // 003 - myDoc => {filename: myDoc, numberPrefix: 3}
24
22
  const DefaultNumberPrefixParser = (filename) => {
25
- var _a, _b, _c;
26
- if (IgnoredPrefixPatterns.exec(filename)) {
23
+ if (ignoredPrefixPattern.test(filename)) {
24
+ return { filename, numberPrefix: undefined };
25
+ }
26
+ const match = numberPrefixPattern.exec(filename);
27
+ if (!match) {
27
28
  return { filename, numberPrefix: undefined };
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;
32
- const numberPrefix = numberPrefixString
33
- ? parseInt(numberPrefixString, 10)
34
- : undefined;
35
30
  return {
36
- filename: cleanFileName,
37
- numberPrefix,
31
+ filename: match.groups.suffix,
32
+ numberPrefix: parseInt(match.groups.numberPrefix, 10),
38
33
  };
39
34
  };
40
35
  exports.DefaultNumberPrefixParser = DefaultNumberPrefixParser;
package/lib/options.d.ts CHANGED
@@ -4,9 +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 { PluginOptions } from './types';
8
- import { Joi } from '@docusaurus/utils-validation';
9
- import { OptionValidationContext, ValidationResult } from '@docusaurus/types';
7
+ import type { OptionValidationContext } from '@docusaurus/types';
8
+ import type { PluginOptions, Options } from '@docusaurus/plugin-content-docs';
10
9
  export declare const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'>;
11
- export declare const OptionsSchema: Joi.ObjectSchema<any>;
12
- export declare function validateOptions({ validate, options: userOptions, }: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions>;
10
+ export declare function validateOptions({ validate, options: userOptions, }: OptionValidationContext<Options, PluginOptions>): PluginOptions;