@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
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.getVersionMetadataPaths = exports.readVersionNames = exports.readVersionsFile = exports.getVersionsFilePath = exports.getDocsDirPathLocalized = exports.getVersionSidebarsPath = exports.getVersionDocsDirPath = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const path_1 = tslib_1.__importDefault(require("path"));
12
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
+ const utils_1 = require("@docusaurus/utils");
14
+ const constants_1 = require("../constants");
15
+ const validation_1 = require("./validation");
16
+ /** Add a prefix like `community_version-1.0.0`. No-op for default instance. */
17
+ function addPluginIdPrefix(fileOrDir, pluginId) {
18
+ return pluginId === utils_1.DEFAULT_PLUGIN_ID
19
+ ? fileOrDir
20
+ : `${pluginId}_${fileOrDir}`;
21
+ }
22
+ /** `[siteDir]/community_versioned_docs/version-1.0.0` */
23
+ function getVersionDocsDirPath(siteDir, pluginId, versionName) {
24
+ return path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONED_DOCS_DIR, pluginId), `version-${versionName}`);
25
+ }
26
+ exports.getVersionDocsDirPath = getVersionDocsDirPath;
27
+ /** `[siteDir]/community_versioned_sidebars/version-1.0.0-sidebars.json` */
28
+ function getVersionSidebarsPath(siteDir, pluginId, versionName) {
29
+ return path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONED_SIDEBARS_DIR, pluginId), `version-${versionName}-sidebars.json`);
30
+ }
31
+ exports.getVersionSidebarsPath = getVersionSidebarsPath;
32
+ function getDocsDirPathLocalized({ localizationDir, pluginId, versionName, }) {
33
+ return (0, utils_1.getPluginI18nPath)({
34
+ localizationDir,
35
+ pluginName: 'docusaurus-plugin-content-docs',
36
+ pluginId,
37
+ subPaths: [
38
+ versionName === constants_1.CURRENT_VERSION_NAME
39
+ ? constants_1.CURRENT_VERSION_NAME
40
+ : `version-${versionName}`,
41
+ ],
42
+ });
43
+ }
44
+ exports.getDocsDirPathLocalized = getDocsDirPathLocalized;
45
+ /** `community` => `[siteDir]/community_versions.json` */
46
+ function getVersionsFilePath(siteDir, pluginId) {
47
+ return path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONS_JSON_FILE, pluginId));
48
+ }
49
+ exports.getVersionsFilePath = getVersionsFilePath;
50
+ /**
51
+ * Reads the plugin's respective `versions.json` file, and returns its content.
52
+ *
53
+ * @throws Throws if validation fails, i.e. `versions.json` doesn't contain an
54
+ * array of valid version names.
55
+ */
56
+ async function readVersionsFile(siteDir, pluginId) {
57
+ const versionsFilePath = getVersionsFilePath(siteDir, pluginId);
58
+ if (await fs_extra_1.default.pathExists(versionsFilePath)) {
59
+ const content = await fs_extra_1.default.readJSON(versionsFilePath);
60
+ (0, validation_1.validateVersionNames)(content);
61
+ return content;
62
+ }
63
+ return null;
64
+ }
65
+ exports.readVersionsFile = readVersionsFile;
66
+ /**
67
+ * Reads the `versions.json` file, and returns an ordered list of version names.
68
+ *
69
+ * - If `disableVersioning` is turned on, it will return `["current"]` (requires
70
+ * `includeCurrentVersion` to be true);
71
+ * - If `includeCurrentVersion` is turned on, "current" will be inserted at the
72
+ * beginning, if not already there.
73
+ *
74
+ * You need to use {@link filterVersions} after this.
75
+ *
76
+ * @throws Throws an error if `disableVersioning: true` but `versions.json`
77
+ * doesn't exist (i.e. site is not versioned)
78
+ * @throws Throws an error if versions list is empty (empty `versions.json` or
79
+ * `disableVersioning` is true, and not including current version)
80
+ */
81
+ async function readVersionNames(siteDir, options) {
82
+ const versionFileContent = await readVersionsFile(siteDir, options.id);
83
+ if (!versionFileContent && options.disableVersioning) {
84
+ throw new Error(`Docs: using "disableVersioning: true" option on a non-versioned site does not make sense.`);
85
+ }
86
+ const versions = options.disableVersioning ? [] : versionFileContent ?? [];
87
+ // We add the current version at the beginning, unless:
88
+ // - user don't want to; or
89
+ // - it's already been explicitly added to versions.json
90
+ if (options.includeCurrentVersion &&
91
+ !versions.includes(constants_1.CURRENT_VERSION_NAME)) {
92
+ versions.unshift(constants_1.CURRENT_VERSION_NAME);
93
+ }
94
+ if (versions.length === 0) {
95
+ throw new Error(`It is not possible to use docs without any version. No version is included because you have requested to not include ${path_1.default.resolve(options.path)} through "includeCurrentVersion: false", while ${options.disableVersioning
96
+ ? 'versioning is disabled with "disableVersioning: true"'
97
+ : `the versions file is empty/non-existent`}.`);
98
+ }
99
+ return versions;
100
+ }
101
+ exports.readVersionNames = readVersionNames;
102
+ /**
103
+ * Gets the path-related version metadata.
104
+ *
105
+ * @throws Throws if the resolved docs folder or sidebars file doesn't exist.
106
+ * Does not throw if a versioned sidebar is missing (since we don't create empty
107
+ * files).
108
+ */
109
+ async function getVersionMetadataPaths({ versionName, context, options, }) {
110
+ const isCurrent = versionName === constants_1.CURRENT_VERSION_NAME;
111
+ const contentPathLocalized = getDocsDirPathLocalized({
112
+ localizationDir: context.localizationDir,
113
+ pluginId: options.id,
114
+ versionName,
115
+ });
116
+ const contentPath = isCurrent
117
+ ? path_1.default.resolve(context.siteDir, options.path)
118
+ : getVersionDocsDirPath(context.siteDir, options.id, versionName);
119
+ const sidebarFilePath = isCurrent
120
+ ? options.sidebarPath
121
+ : getVersionSidebarsPath(context.siteDir, options.id, versionName);
122
+ if (!(await fs_extra_1.default.pathExists(contentPath))) {
123
+ throw new Error(`The docs folder does not exist for version "${versionName}". A docs folder is expected to be found at ${path_1.default.relative(context.siteDir, contentPath)}.`);
124
+ }
125
+ // If the current version defines a path to a sidebar file that does not
126
+ // exist, we throw! Note: for versioned sidebars, the file may not exist (as
127
+ // we prefer to not create it rather than to create an empty file)
128
+ // See https://github.com/facebook/docusaurus/issues/3366
129
+ // See https://github.com/facebook/docusaurus/pull/4775
130
+ if (versionName === constants_1.CURRENT_VERSION_NAME &&
131
+ typeof sidebarFilePath === 'string' &&
132
+ !(await fs_extra_1.default.pathExists(sidebarFilePath))) {
133
+ throw new Error(`The path to the sidebar file does not exist at "${path_1.default.relative(context.siteDir, sidebarFilePath)}".
134
+ Please set the docs "sidebarPath" field in your config file to:
135
+ - a sidebars path that exists
136
+ - false: to disable the sidebar
137
+ - undefined: for Docusaurus to generate it automatically`);
138
+ }
139
+ return { contentPath, contentPathLocalized, sidebarFilePath };
140
+ }
141
+ exports.getVersionMetadataPaths = getVersionMetadataPaths;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { PluginOptions, VersionBanner, VersionMetadata } from '@docusaurus/plugin-content-docs';
8
+ import type { LoadContext } from '@docusaurus/types';
9
+ export declare type VersionContext = {
10
+ /** The version name to get banner of. */
11
+ versionName: string;
12
+ /** All versions, ordered from newest to oldest. */
13
+ versionNames: string[];
14
+ lastVersionName: string;
15
+ context: LoadContext;
16
+ options: PluginOptions;
17
+ };
18
+ /**
19
+ * The default version banner depends on the version's relative position to the
20
+ * latest version. More recent ones are "unreleased", and older ones are
21
+ * "unmaintained".
22
+ */
23
+ export declare function getDefaultVersionBanner({ versionName, versionNames, lastVersionName, }: VersionContext): VersionBanner | null;
24
+ export declare function getVersionBanner(context: VersionContext): VersionMetadata['banner'];
25
+ export declare function getVersionBadge({ versionName, versionNames, options, }: VersionContext): VersionMetadata['badge'];
26
+ /**
27
+ * Filter versions according to provided options (i.e. `onlyIncludeVersions`).
28
+ *
29
+ * Note: we preserve the order in which versions are provided; the order of the
30
+ * `onlyIncludeVersions` array does not matter
31
+ */
32
+ export declare function filterVersions(versionNamesUnfiltered: string[], options: PluginOptions): string[];
33
+ export declare function readVersionsMetadata({ context, options, }: {
34
+ context: LoadContext;
35
+ options: PluginOptions;
36
+ }): Promise<VersionMetadata[]>;
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.readVersionsMetadata = exports.filterVersions = exports.getVersionBadge = exports.getVersionBanner = exports.getDefaultVersionBanner = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const path_1 = tslib_1.__importDefault(require("path"));
12
+ const utils_1 = require("@docusaurus/utils");
13
+ const constants_1 = require("../constants");
14
+ const validation_1 = require("./validation");
15
+ const files_1 = require("./files");
16
+ function getVersionEditUrls({ contentPath, contentPathLocalized, context, options, }) {
17
+ // If the user is using the functional form of editUrl,
18
+ // she has total freedom and we can't compute a "version edit url"
19
+ if (!options.editUrl || typeof options.editUrl === 'function') {
20
+ return { editUrl: undefined, editUrlLocalized: undefined };
21
+ }
22
+ const editDirPath = options.editCurrentVersion ? options.path : contentPath;
23
+ const editDirPathLocalized = options.editCurrentVersion
24
+ ? (0, files_1.getDocsDirPathLocalized)({
25
+ localizationDir: context.localizationDir,
26
+ versionName: constants_1.CURRENT_VERSION_NAME,
27
+ pluginId: options.id,
28
+ })
29
+ : contentPathLocalized;
30
+ const versionPathSegment = (0, utils_1.posixPath)(path_1.default.relative(context.siteDir, path_1.default.resolve(context.siteDir, editDirPath)));
31
+ const versionPathSegmentLocalized = (0, utils_1.posixPath)(path_1.default.relative(context.siteDir, path_1.default.resolve(context.siteDir, editDirPathLocalized)));
32
+ const editUrl = (0, utils_1.normalizeUrl)([options.editUrl, versionPathSegment]);
33
+ const editUrlLocalized = (0, utils_1.normalizeUrl)([
34
+ options.editUrl,
35
+ versionPathSegmentLocalized,
36
+ ]);
37
+ return { editUrl, editUrlLocalized };
38
+ }
39
+ /**
40
+ * The default version banner depends on the version's relative position to the
41
+ * latest version. More recent ones are "unreleased", and older ones are
42
+ * "unmaintained".
43
+ */
44
+ function getDefaultVersionBanner({ versionName, versionNames, lastVersionName, }) {
45
+ // Current version: good, no banner
46
+ if (versionName === lastVersionName) {
47
+ return null;
48
+ }
49
+ // Upcoming versions: unreleased banner
50
+ if (versionNames.indexOf(versionName) < versionNames.indexOf(lastVersionName)) {
51
+ return 'unreleased';
52
+ }
53
+ // Older versions: display unmaintained banner
54
+ return 'unmaintained';
55
+ }
56
+ exports.getDefaultVersionBanner = getDefaultVersionBanner;
57
+ function getVersionBanner(context) {
58
+ const { versionName, options } = context;
59
+ const versionBannerOption = options.versions[versionName]?.banner;
60
+ if (versionBannerOption) {
61
+ return versionBannerOption === 'none' ? null : versionBannerOption;
62
+ }
63
+ return getDefaultVersionBanner(context);
64
+ }
65
+ exports.getVersionBanner = getVersionBanner;
66
+ function getVersionBadge({ versionName, versionNames, options, }) {
67
+ // If site is not versioned or only one version is included
68
+ // we don't show the version badge by default
69
+ // See https://github.com/facebook/docusaurus/issues/3362
70
+ const defaultVersionBadge = versionNames.length !== 1;
71
+ return options.versions[versionName]?.badge ?? defaultVersionBadge;
72
+ }
73
+ exports.getVersionBadge = getVersionBadge;
74
+ function getVersionClassName({ versionName, options, }) {
75
+ const defaultVersionClassName = `docs-version-${versionName}`;
76
+ return options.versions[versionName]?.className ?? defaultVersionClassName;
77
+ }
78
+ function getVersionLabel({ versionName, options, }) {
79
+ const defaultVersionLabel = versionName === constants_1.CURRENT_VERSION_NAME ? 'Next' : versionName;
80
+ return options.versions[versionName]?.label ?? defaultVersionLabel;
81
+ }
82
+ function getVersionPathPart({ versionName, options, lastVersionName, }) {
83
+ function getDefaultVersionPathPart() {
84
+ if (versionName === lastVersionName) {
85
+ return '';
86
+ }
87
+ return versionName === constants_1.CURRENT_VERSION_NAME ? 'next' : versionName;
88
+ }
89
+ return options.versions[versionName]?.path ?? getDefaultVersionPathPart();
90
+ }
91
+ async function createVersionMetadata(context) {
92
+ const { versionName, lastVersionName, options, context: loadContext } = context;
93
+ const { sidebarFilePath, contentPath, contentPathLocalized } = await (0, files_1.getVersionMetadataPaths)(context);
94
+ const versionPathPart = getVersionPathPart(context);
95
+ const routePath = (0, utils_1.normalizeUrl)([
96
+ loadContext.baseUrl,
97
+ options.routeBasePath,
98
+ versionPathPart,
99
+ ]);
100
+ const versionEditUrls = getVersionEditUrls({
101
+ contentPath,
102
+ contentPathLocalized,
103
+ context: loadContext,
104
+ options,
105
+ });
106
+ return {
107
+ versionName,
108
+ label: getVersionLabel(context),
109
+ banner: getVersionBanner(context),
110
+ badge: getVersionBadge(context),
111
+ className: getVersionClassName(context),
112
+ path: routePath,
113
+ tagsPath: (0, utils_1.normalizeUrl)([routePath, options.tagsBasePath]),
114
+ ...versionEditUrls,
115
+ isLast: versionName === lastVersionName,
116
+ routePriority: versionPathPart === '' ? -1 : undefined,
117
+ sidebarFilePath,
118
+ contentPath,
119
+ contentPathLocalized,
120
+ };
121
+ }
122
+ /**
123
+ * Filter versions according to provided options (i.e. `onlyIncludeVersions`).
124
+ *
125
+ * Note: we preserve the order in which versions are provided; the order of the
126
+ * `onlyIncludeVersions` array does not matter
127
+ */
128
+ function filterVersions(versionNamesUnfiltered, options) {
129
+ if (options.onlyIncludeVersions) {
130
+ return versionNamesUnfiltered.filter((name) => options.onlyIncludeVersions.includes(name));
131
+ }
132
+ return versionNamesUnfiltered;
133
+ }
134
+ exports.filterVersions = filterVersions;
135
+ function getLastVersionName({ versionNames, options, }) {
136
+ return (options.lastVersion ??
137
+ versionNames.find((name) => name !== constants_1.CURRENT_VERSION_NAME) ??
138
+ constants_1.CURRENT_VERSION_NAME);
139
+ }
140
+ async function readVersionsMetadata({ context, options, }) {
141
+ const allVersionNames = await (0, files_1.readVersionNames)(context.siteDir, options);
142
+ (0, validation_1.validateVersionsOptions)(allVersionNames, options);
143
+ const versionNames = filterVersions(allVersionNames, options);
144
+ const lastVersionName = getLastVersionName({ versionNames, options });
145
+ const versionsMetadata = await Promise.all(versionNames.map((versionName) => createVersionMetadata({
146
+ versionName,
147
+ versionNames,
148
+ lastVersionName,
149
+ context,
150
+ options,
151
+ })));
152
+ return versionsMetadata;
153
+ }
154
+ exports.readVersionsMetadata = readVersionsMetadata;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { VersionsOptions } from '@docusaurus/plugin-content-docs';
8
+ export declare function validateVersionName(name: unknown): asserts name is string;
9
+ export declare function validateVersionNames(names: unknown): asserts names is string[];
10
+ /**
11
+ * @throws Throws for one of the following invalid options:
12
+ * - `lastVersion` is non-existent
13
+ * - `versions` includes unknown keys
14
+ * - `onlyIncludeVersions` is empty, contains unknown names, or doesn't include
15
+ * `latestVersion` (if provided)
16
+ */
17
+ export declare function validateVersionsOptions(availableVersionNames: string[], options: VersionsOptions): void;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.validateVersionsOptions = exports.validateVersionNames = exports.validateVersionName = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
+ function validateVersionName(name) {
13
+ if (typeof name !== 'string') {
14
+ throw new Error(`Versions should be strings. Found type "${typeof name}" for version ${JSON.stringify(name)}.`);
15
+ }
16
+ if (!name.trim()) {
17
+ throw new Error(`Invalid version name "${name}": version name must contain at least one non-whitespace character.`);
18
+ }
19
+ const errors = [
20
+ [/[/\\]/, 'should not include slash (/) or backslash (\\)'],
21
+ [/.{33,}/, 'cannot be longer than 32 characters'],
22
+ // eslint-disable-next-line no-control-regex
23
+ [/[<>:"|?*\x00-\x1F]/, 'should be a valid file path'],
24
+ [/^\.\.?$/, 'should not be "." or ".."'],
25
+ ];
26
+ errors.forEach(([pattern, message]) => {
27
+ if (pattern.test(name)) {
28
+ throw new Error(`Invalid version name "${name}": version name ${message}.`);
29
+ }
30
+ });
31
+ }
32
+ exports.validateVersionName = validateVersionName;
33
+ function validateVersionNames(names) {
34
+ if (!Array.isArray(names)) {
35
+ throw new Error(`The versions file should contain an array of version names! Found content: ${JSON.stringify(names)}`);
36
+ }
37
+ names.forEach(validateVersionName);
38
+ }
39
+ exports.validateVersionNames = validateVersionNames;
40
+ /**
41
+ * @throws Throws for one of the following invalid options:
42
+ * - `lastVersion` is non-existent
43
+ * - `versions` includes unknown keys
44
+ * - `onlyIncludeVersions` is empty, contains unknown names, or doesn't include
45
+ * `latestVersion` (if provided)
46
+ */
47
+ function validateVersionsOptions(availableVersionNames, options) {
48
+ const availableVersionNamesMsg = `Available version names are: ${availableVersionNames.join(', ')}`;
49
+ if (options.lastVersion &&
50
+ !availableVersionNames.includes(options.lastVersion)) {
51
+ throw new Error(`Docs option lastVersion: ${options.lastVersion} is invalid. ${availableVersionNamesMsg}`);
52
+ }
53
+ const unknownVersionConfigNames = lodash_1.default.difference(Object.keys(options.versions), availableVersionNames);
54
+ if (unknownVersionConfigNames.length > 0) {
55
+ throw new Error(`Invalid docs option "versions": unknown versions (${unknownVersionConfigNames.join(',')}) found. ${availableVersionNamesMsg}`);
56
+ }
57
+ if (options.onlyIncludeVersions) {
58
+ if (options.onlyIncludeVersions.length === 0) {
59
+ throw new Error(`Invalid docs option "onlyIncludeVersions": an empty array is not allowed, at least one version is needed.`);
60
+ }
61
+ const unknownOnlyIncludeVersionNames = lodash_1.default.difference(options.onlyIncludeVersions, availableVersionNames);
62
+ if (unknownOnlyIncludeVersionNames.length > 0) {
63
+ throw new Error(`Invalid docs option "onlyIncludeVersions": unknown versions (${unknownOnlyIncludeVersionNames.join(',')}) found. ${availableVersionNamesMsg}`);
64
+ }
65
+ if (options.lastVersion &&
66
+ !options.onlyIncludeVersions.includes(options.lastVersion)) {
67
+ throw new Error(`Invalid docs option "lastVersion": if you use both the "onlyIncludeVersions" and "lastVersion" options, then "lastVersion" must be present in the provided "onlyIncludeVersions" array.`);
68
+ }
69
+ }
70
+ }
71
+ exports.validateVersionsOptions = validateVersionsOptions;
package/package.json CHANGED
@@ -1,12 +1,28 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "2.0.0-beta.fc64c12e4",
3
+ "version": "2.0.0",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
+ "sideEffects": false,
7
+ "exports": {
8
+ "./src/*": "./src/*",
9
+ "./client": {
10
+ "type": "./lib/client/index.d.ts",
11
+ "default": "./lib/client/index.js"
12
+ },
13
+ "./server": {
14
+ "type": "./lib/server-export.d.ts",
15
+ "default": "./lib/server-export.js"
16
+ },
17
+ ".": {
18
+ "types": "./src/plugin-content-docs.d.ts",
19
+ "default": "./lib/index.js"
20
+ }
21
+ },
6
22
  "types": "src/plugin-content-docs.d.ts",
7
23
  "scripts": {
8
- "build": "tsc",
9
- "watch": "tsc --watch"
24
+ "build": "tsc --build",
25
+ "watch": "tsc --build --watch"
10
26
  },
11
27
  "publishConfig": {
12
28
  "access": "public"
@@ -17,41 +33,39 @@
17
33
  "directory": "packages/docusaurus-plugin-content-docs"
18
34
  },
19
35
  "license": "MIT",
20
- "devDependencies": {
21
- "@docusaurus/module-type-aliases": "2.0.0-beta.fc64c12e4",
22
- "@types/js-yaml": "^4.0.0",
23
- "@types/picomatch": "^2.2.1",
24
- "commander": "^5.1.0",
25
- "picomatch": "^2.1.1"
26
- },
27
36
  "dependencies": {
28
- "@docusaurus/core": "2.0.0-beta.fc64c12e4",
29
- "@docusaurus/mdx-loader": "2.0.0-beta.fc64c12e4",
30
- "@docusaurus/types": "2.0.0-beta.fc64c12e4",
31
- "@docusaurus/utils": "2.0.0-beta.fc64c12e4",
32
- "@docusaurus/utils-validation": "2.0.0-beta.fc64c12e4",
33
- "chalk": "^4.1.1",
37
+ "@docusaurus/core": "2.0.0",
38
+ "@docusaurus/logger": "2.0.0",
39
+ "@docusaurus/mdx-loader": "2.0.0",
40
+ "@docusaurus/module-type-aliases": "2.0.0",
41
+ "@docusaurus/types": "2.0.0",
42
+ "@docusaurus/utils": "2.0.0",
43
+ "@docusaurus/utils-validation": "2.0.0",
44
+ "@types/react-router-config": "^5.0.6",
34
45
  "combine-promises": "^1.1.0",
35
- "escape-string-regexp": "^4.0.0",
36
- "execa": "^5.0.0",
37
- "fs-extra": "^10.0.0",
38
- "globby": "^11.0.2",
39
- "import-fresh": "^3.2.2",
40
- "js-yaml": "^4.0.0",
41
- "loader-utils": "^1.2.3",
42
- "lodash": "^4.17.20",
43
- "remark-admonitions": "^1.2.1",
44
- "shelljs": "^0.8.4",
45
- "tslib": "^2.2.0",
46
+ "fs-extra": "^10.1.0",
47
+ "import-fresh": "^3.3.0",
48
+ "js-yaml": "^4.1.0",
49
+ "lodash": "^4.17.21",
50
+ "tslib": "^2.4.0",
46
51
  "utility-types": "^3.10.0",
47
- "webpack": "^5.40.0"
52
+ "webpack": "^5.73.0"
53
+ },
54
+ "devDependencies": {
55
+ "@docusaurus/types": "2.0.0-beta.21",
56
+ "@types/js-yaml": "^4.0.5",
57
+ "@types/picomatch": "^2.3.0",
58
+ "commander": "^5.1.0",
59
+ "escape-string-regexp": "^4.0.0",
60
+ "picomatch": "^2.3.1",
61
+ "shelljs": "^0.8.5"
48
62
  },
49
63
  "peerDependencies": {
50
64
  "react": "^16.8.4 || ^17.0.0",
51
65
  "react-dom": "^16.8.4 || ^17.0.0"
52
66
  },
53
67
  "engines": {
54
- "node": ">=12.13.0"
68
+ "node": ">=16.14"
55
69
  },
56
- "gitHead": "830d9e29a94866f19318e19565b9e177af06b964"
70
+ "gitHead": "2a9e8f5ec807e49a973fc72326f1ef26092e977e"
57
71
  }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import {type SidebarsUtils, toNavigationLink} from './sidebars/utils';
9
+ import {createDocsByIdIndex} from './docs';
10
+ import type {
11
+ CategoryGeneratedIndexMetadata,
12
+ DocMetadataBase,
13
+ } from '@docusaurus/plugin-content-docs';
14
+ import type {SidebarItemCategoryWithGeneratedIndex} from './sidebars/types';
15
+
16
+ function getCategoryGeneratedIndexMetadata({
17
+ category,
18
+ sidebarsUtils,
19
+ docsById,
20
+ }: {
21
+ category: SidebarItemCategoryWithGeneratedIndex;
22
+ sidebarsUtils: SidebarsUtils;
23
+ docsById: {[docId: string]: DocMetadataBase};
24
+ }): CategoryGeneratedIndexMetadata {
25
+ const {sidebarName, previous, next} =
26
+ sidebarsUtils.getCategoryGeneratedIndexNavigation(category.link.permalink);
27
+ return {
28
+ title: category.link.title ?? category.label,
29
+ description: category.link.description,
30
+ image: category.link.image,
31
+ keywords: category.link.keywords,
32
+ slug: category.link.slug,
33
+ permalink: category.link.permalink,
34
+ sidebar: sidebarName!,
35
+ navigation: {
36
+ previous: toNavigationLink(previous, docsById),
37
+ next: toNavigationLink(next, docsById),
38
+ },
39
+ };
40
+ }
41
+
42
+ export function getCategoryGeneratedIndexMetadataList({
43
+ docs,
44
+ sidebarsUtils,
45
+ }: {
46
+ sidebarsUtils: SidebarsUtils;
47
+ docs: DocMetadataBase[];
48
+ }): CategoryGeneratedIndexMetadata[] {
49
+ const docsById = createDocsByIdIndex(docs);
50
+
51
+ const categoryGeneratedIndexItems =
52
+ sidebarsUtils.getCategoryGeneratedIndexList();
53
+ return categoryGeneratedIndexItems.map((category) =>
54
+ getCategoryGeneratedIndexMetadata({
55
+ category,
56
+ sidebarsUtils,
57
+ docsById,
58
+ }),
59
+ );
60
+ }