@docusaurus/plugin-content-docs 2.0.0-beta.ff31de0ff → 2.0.0-rc.1

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 (231) 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 +62 -72
  5. package/lib/client/docsClientUtils.d.ts +9 -28
  6. package/lib/client/docsClientUtils.js +35 -51
  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 +35 -8
  12. package/lib/docs.js +211 -78
  13. package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js → lib/frontMatter.d.ts} +4 -10
  14. package/lib/frontMatter.js +53 -0
  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 +137 -146
  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 +7 -4
  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 +57 -29
  29. package/lib/props.d.ts +7 -2
  30. package/lib/props.js +87 -16
  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 -6
  36. package/lib/sidebars/generator.js +209 -0
  37. package/lib/sidebars/index.d.ts +13 -0
  38. package/lib/sidebars/index.js +92 -0
  39. package/lib/sidebars/normalization.d.ts +13 -0
  40. package/lib/sidebars/normalization.js +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/{types.d.ts → lib/sidebars/types.js} +2 -7
  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 +29 -19
  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 -172
  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 -29
  65. package/src/categoryGeneratedIndex.ts +60 -0
  66. package/src/cli.ts +94 -114
  67. package/src/client/docsClientUtils.ts +47 -84
  68. package/src/client/index.ts +158 -0
  69. package/src/constants.ts +4 -2
  70. package/src/docs.ts +294 -78
  71. package/src/frontMatter.ts +63 -0
  72. package/src/globalData.ts +57 -7
  73. package/src/index.ts +200 -204
  74. package/src/lastUpdate.ts +27 -34
  75. package/src/markdown/index.ts +10 -16
  76. package/src/markdown/linkify.ts +8 -5
  77. package/src/numberPrefix.ts +19 -26
  78. package/src/options.ts +61 -43
  79. package/src/plugin-content-docs.d.ts +575 -78
  80. package/src/props.ts +128 -23
  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 +42 -23
  93. package/src/tags.ts +20 -0
  94. package/src/translations.ts +155 -124
  95. package/src/types.ts +17 -234
  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 -4673
  100. package/lib/docFrontMatter.d.ts +0 -21
  101. package/lib/docFrontMatter.js +0 -33
  102. package/lib/sidebarItemsGenerator.js +0 -211
  103. package/lib/sidebars.d.ts +0 -42
  104. package/lib/sidebars.js +0 -309
  105. package/lib/theme/hooks/useDocs.d.ts +0 -20
  106. package/lib/theme/hooks/useDocs.js +0 -72
  107. package/lib/versions.d.ts +0 -16
  108. package/lib/versions.js +0 -287
  109. package/src/__tests__/__fixtures__/bad-id-site/docs/invalid-id.md +0 -5
  110. package/src/__tests__/__fixtures__/bad-slug-on-doc-home-site/docs/docWithSlug.md +0 -5
  111. package/src/__tests__/__fixtures__/empty-site/docusaurus.config.js +0 -16
  112. package/src/__tests__/__fixtures__/empty-site/sidebars.json +0 -1
  113. package/src/__tests__/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -34
  114. package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -11
  115. package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -11
  116. package/src/__tests__/__fixtures__/sidebars/sidebars-category.js +0 -44
  117. package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -20
  118. package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed.json +0 -21
  119. package/src/__tests__/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -10
  120. package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -11
  121. package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -11
  122. package/src/__tests__/__fixtures__/sidebars/sidebars-link.json +0 -11
  123. package/src/__tests__/__fixtures__/sidebars/sidebars-unknown-type.json +0 -14
  124. package/src/__tests__/__fixtures__/sidebars/sidebars-wrong-field.json +0 -20
  125. package/src/__tests__/__fixtures__/sidebars/sidebars.json +0 -20
  126. package/src/__tests__/__fixtures__/simple-site/docs/foo/bar.md +0 -69
  127. package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +0 -67
  128. package/src/__tests__/__fixtures__/simple-site/docs/headingAsTitle.md +0 -1
  129. package/src/__tests__/__fixtures__/simple-site/docs/hello.md +0 -52
  130. package/src/__tests__/__fixtures__/simple-site/docs/ipsum.md +0 -5
  131. package/src/__tests__/__fixtures__/simple-site/docs/lorem.md +0 -6
  132. package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +0 -5
  133. package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +0 -5
  134. package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +0 -5
  135. package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +0 -5
  136. package/src/__tests__/__fixtures__/simple-site/docs/slugs/absoluteSlug.md +0 -5
  137. package/src/__tests__/__fixtures__/simple-site/docs/slugs/relativeSlug.md +0 -5
  138. package/src/__tests__/__fixtures__/simple-site/docs/slugs/resolvedSlug.md +0 -5
  139. package/src/__tests__/__fixtures__/simple-site/docs/slugs/tryToEscapeSlug.md +0 -5
  140. package/src/__tests__/__fixtures__/simple-site/docusaurus.config.js +0 -14
  141. package/src/__tests__/__fixtures__/simple-site/sidebars.json +0 -23
  142. package/src/__tests__/__fixtures__/simple-site/wrong-sidebars.json +0 -7
  143. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/0-getting-started.md +0 -3
  144. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/1-installation.md +0 -3
  145. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/00_api-overview.md +0 -3
  146. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/0 --- Client API.md +0 -1
  147. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/1 --- Server API.md +0 -1
  148. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/0. Plugin API.md +0 -1
  149. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/1. Theme API.md +0 -1
  150. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/_category_.yml +0 -1
  151. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/03_api-end.md +0 -3
  152. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/_category_.json +0 -3
  153. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/0-guide2.5.md +0 -8
  154. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/02-guide2.md +0 -7
  155. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/_category_.json +0 -3
  156. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/a-guide4.md +0 -7
  157. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/b-guide5.md +0 -7
  158. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/guide3.md +0 -8
  159. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/z-guide1.md +0 -8
  160. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docusaurus.config.js +0 -14
  161. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars.js +0 -23
  162. package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-1.md +0 -7
  163. package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-2.md +0 -8
  164. package/src/__tests__/__fixtures__/site-with-doc-label/docusaurus.config.js +0 -14
  165. package/src/__tests__/__fixtures__/site-with-doc-label/sidebars.json +0 -14
  166. package/src/__tests__/__fixtures__/versioned-site/community/team.md +0 -1
  167. package/src/__tests__/__fixtures__/versioned-site/community_sidebars.json +0 -3
  168. package/src/__tests__/__fixtures__/versioned-site/community_versioned_docs/version-1.0.0/team.md +0 -1
  169. package/src/__tests__/__fixtures__/versioned-site/community_versioned_sidebars/version-1.0.0-sidebars.json +0 -3
  170. package/src/__tests__/__fixtures__/versioned-site/community_versions.json +0 -1
  171. package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +0 -4
  172. package/src/__tests__/__fixtures__/versioned-site/docs/hello.md +0 -1
  173. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/absoluteSlug.md +0 -5
  174. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/relativeSlug.md +0 -5
  175. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/resolvedSlug.md +0 -5
  176. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/tryToEscapeSlug.md +0 -5
  177. package/src/__tests__/__fixtures__/versioned-site/docusaurus.config.js +0 -18
  178. package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
  179. package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs-community/current/team.md +0 -5
  180. package/src/__tests__/__fixtures__/versioned-site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
  181. package/src/__tests__/__fixtures__/versioned-site/sidebars.json +0 -10
  182. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/bar.md +0 -4
  183. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/baz.md +0 -1
  184. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md +0 -1
  185. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/foo/bar.md +0 -1
  186. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md +0 -1
  187. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootAbsoluteSlug.md +0 -5
  188. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootRelativeSlug.md +0 -5
  189. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootResolvedSlug.md +0 -5
  190. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootTryToEscapeSlug.md +0 -5
  191. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/absoluteSlug.md +0 -5
  192. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/relativeSlug.md +0 -5
  193. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/resolvedSlug.md +0 -5
  194. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/tryToEscapeSlug.md +0 -5
  195. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.0-sidebars.json +0 -11
  196. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +0 -10
  197. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-withSlugs-sidebars.json +0 -5
  198. package/src/__tests__/__fixtures__/versioned-site/versions.json +0 -5
  199. package/src/__tests__/__snapshots__/cli.test.ts.snap +0 -90
  200. package/src/__tests__/__snapshots__/index.test.ts.snap +0 -1907
  201. package/src/__tests__/__snapshots__/sidebars.test.ts.snap +0 -218
  202. package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -487
  203. package/src/__tests__/cli.test.ts +0 -333
  204. package/src/__tests__/docFrontMatter.test.ts +0 -204
  205. package/src/__tests__/docs.test.ts +0 -875
  206. package/src/__tests__/index.test.ts +0 -1831
  207. package/src/__tests__/lastUpdate.test.ts +0 -68
  208. package/src/__tests__/numberPrefix.test.ts +0 -199
  209. package/src/__tests__/options.test.ts +0 -232
  210. package/src/__tests__/sidebarItemsGenerator.test.ts +0 -336
  211. package/src/__tests__/sidebars.test.ts +0 -638
  212. package/src/__tests__/slug.test.ts +0 -109
  213. package/src/__tests__/translations.test.ts +0 -159
  214. package/src/__tests__/versions.test.ts +0 -718
  215. package/src/client/__tests__/docsClientUtils.test.ts +0 -372
  216. package/src/docFrontMatter.ts +0 -53
  217. package/src/markdown/__tests__/__fixtures__/docs/doc-localized.md +0 -1
  218. package/src/markdown/__tests__/__fixtures__/docs/doc1.md +0 -13
  219. package/src/markdown/__tests__/__fixtures__/docs/doc2.md +0 -12
  220. package/src/markdown/__tests__/__fixtures__/docs/doc4.md +0 -19
  221. package/src/markdown/__tests__/__fixtures__/docs/doc5.md +0 -6
  222. package/src/markdown/__tests__/__fixtures__/docs/subdir/doc3.md +0 -3
  223. package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/doc2.md +0 -7
  224. package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/subdir/doc1.md +0 -3
  225. package/src/markdown/__tests__/__snapshots__/linkify.test.ts.snap +0 -82
  226. package/src/markdown/__tests__/linkify.test.ts +0 -190
  227. package/src/sidebarItemsGenerator.ts +0 -307
  228. package/src/sidebars.ts +0 -489
  229. package/src/theme/hooks/useDocs.ts +0 -99
  230. package/src/versions.ts +0 -511
  231. package/tsconfig.json +0 -9
@@ -1,72 +0,0 @@
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.useDocVersionSuggestions = exports.useActiveDocContext = exports.useActiveVersion = exports.useLatestVersion = exports.useVersions = exports.useActivePluginAndVersion = exports.useActivePlugin = exports.useDocsData = exports.useAllDocsData = void 0;
10
- const tslib_1 = require("tslib");
11
- const router_1 = require("@docusaurus/router");
12
- const useGlobalData_1 = tslib_1.__importStar(require("@docusaurus/useGlobalData"));
13
- const docsClientUtils_1 = require("../../client/docsClientUtils");
14
- // Not using useAllPluginInstancesData() because in blog-only mode, docs hooks are still used by the theme
15
- // We need a fail-safe fallback when the docs plugin is not in use
16
- const useAllDocsData = () => { var _a;
17
- // useAllPluginInstancesData('docusaurus-plugin-content-docs');
18
- return (_a = useGlobalData_1.default()['docusaurus-plugin-content-docs']) !== null && _a !== void 0 ? _a : {}; };
19
- exports.useAllDocsData = useAllDocsData;
20
- const useDocsData = (pluginId) => useGlobalData_1.usePluginData('docusaurus-plugin-content-docs', pluginId);
21
- exports.useDocsData = useDocsData;
22
- const useActivePlugin = (options = {}) => {
23
- const data = exports.useAllDocsData();
24
- const { pathname } = router_1.useLocation();
25
- return docsClientUtils_1.getActivePlugin(data, pathname, options);
26
- };
27
- exports.useActivePlugin = useActivePlugin;
28
- const useActivePluginAndVersion = (options = {}) => {
29
- const activePlugin = exports.useActivePlugin(options);
30
- const { pathname } = router_1.useLocation();
31
- if (activePlugin) {
32
- const activeVersion = docsClientUtils_1.getActiveVersion(activePlugin.pluginData, pathname);
33
- return {
34
- activePlugin,
35
- activeVersion,
36
- };
37
- }
38
- return undefined;
39
- };
40
- exports.useActivePluginAndVersion = useActivePluginAndVersion;
41
- // versions are returned ordered (most recent first)
42
- const useVersions = (pluginId) => {
43
- const data = exports.useDocsData(pluginId);
44
- return data.versions;
45
- };
46
- exports.useVersions = useVersions;
47
- const useLatestVersion = (pluginId) => {
48
- const data = exports.useDocsData(pluginId);
49
- return docsClientUtils_1.getLatestVersion(data);
50
- };
51
- exports.useLatestVersion = useLatestVersion;
52
- // Note: return undefined on doc-unrelated pages,
53
- // because there's no version currently considered as active
54
- const useActiveVersion = (pluginId) => {
55
- const data = exports.useDocsData(pluginId);
56
- const { pathname } = router_1.useLocation();
57
- return docsClientUtils_1.getActiveVersion(data, pathname);
58
- };
59
- exports.useActiveVersion = useActiveVersion;
60
- const useActiveDocContext = (pluginId) => {
61
- const data = exports.useDocsData(pluginId);
62
- const { pathname } = router_1.useLocation();
63
- return docsClientUtils_1.getActiveDocContext(data, pathname);
64
- };
65
- exports.useActiveDocContext = useActiveDocContext;
66
- // Useful to say "hey, you are not on the latest docs version, please switch"
67
- const useDocVersionSuggestions = (pluginId) => {
68
- const data = exports.useDocsData(pluginId);
69
- const { pathname } = router_1.useLocation();
70
- return docsClientUtils_1.getDocVersionSuggestions(data, pathname);
71
- };
72
- exports.useDocVersionSuggestions = useDocVersionSuggestions;
package/lib/versions.d.ts DELETED
@@ -1,16 +0,0 @@
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 { PluginOptions, VersionMetadata } from './types';
8
- import { LoadContext } from '@docusaurus/types';
9
- export declare function getVersionedDocsDirPath(siteDir: string, pluginId: string): string;
10
- export declare function getVersionedSidebarsDirPath(siteDir: string, pluginId: string): string;
11
- export declare function getVersionsFilePath(siteDir: string, pluginId: string): string;
12
- export declare function readVersionsMetadata({ context, options, }: {
13
- context: Pick<LoadContext, 'siteDir' | 'baseUrl' | 'i18n'>;
14
- options: Pick<PluginOptions, 'id' | 'path' | 'sidebarPath' | 'routeBasePath' | 'includeCurrentVersion' | 'disableVersioning' | 'lastVersion' | 'versions' | 'onlyIncludeVersions' | 'editUrl' | 'editCurrentVersion'>;
15
- }): VersionMetadata[];
16
- export declare function getDocsDirPaths(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>): [string, string];
package/lib/versions.js DELETED
@@ -1,287 +0,0 @@
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.getDocsDirPaths = exports.readVersionsMetadata = exports.getVersionsFilePath = exports.getVersionedSidebarsDirPath = exports.getVersionedDocsDirPath = 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 constants_1 = require("./constants");
14
- const constants_2 = require("@docusaurus/core/lib/constants");
15
- const utils_1 = require("@docusaurus/utils");
16
- const lodash_1 = require("lodash");
17
- // retro-compatibility: no prefix for the default plugin id
18
- function addPluginIdPrefix(fileOrDir, pluginId) {
19
- if (pluginId === constants_2.DEFAULT_PLUGIN_ID) {
20
- return fileOrDir;
21
- }
22
- else {
23
- return `${pluginId}_${fileOrDir}`;
24
- }
25
- }
26
- function getVersionedDocsDirPath(siteDir, pluginId) {
27
- return path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONED_DOCS_DIR, pluginId));
28
- }
29
- exports.getVersionedDocsDirPath = getVersionedDocsDirPath;
30
- function getVersionedSidebarsDirPath(siteDir, pluginId) {
31
- return path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONED_SIDEBARS_DIR, pluginId));
32
- }
33
- exports.getVersionedSidebarsDirPath = getVersionedSidebarsDirPath;
34
- function getVersionsFilePath(siteDir, pluginId) {
35
- return path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONS_JSON_FILE, pluginId));
36
- }
37
- exports.getVersionsFilePath = getVersionsFilePath;
38
- function ensureValidVersionString(version) {
39
- if (typeof version !== 'string') {
40
- throw new Error(`versions should be strings. Found type=[${typeof version}] for version=[${version}]`);
41
- }
42
- // Should we forbid versions with special chars like / ?
43
- if (version.trim().length === 0) {
44
- throw new Error(`Invalid version=[${version}]`);
45
- }
46
- }
47
- function ensureValidVersionArray(versionArray) {
48
- if (!(versionArray instanceof Array)) {
49
- throw new Error(`The versions file should contain an array of versions! Found content=${JSON.stringify(versionArray)}`);
50
- }
51
- versionArray.forEach(ensureValidVersionString);
52
- }
53
- // TODO not easy to make async due to many deps
54
- function readVersionsFile(siteDir, pluginId) {
55
- const versionsFilePath = getVersionsFilePath(siteDir, pluginId);
56
- if (fs_extra_1.default.existsSync(versionsFilePath)) {
57
- const content = JSON.parse(fs_extra_1.default.readFileSync(versionsFilePath, 'utf8'));
58
- ensureValidVersionArray(content);
59
- return content;
60
- }
61
- else {
62
- return null;
63
- }
64
- }
65
- // TODO not easy to make async due to many deps
66
- function readVersionNames(siteDir, options) {
67
- const versionFileContent = readVersionsFile(siteDir, options.id);
68
- if (!versionFileContent && options.disableVersioning) {
69
- throw new Error(`Docs: using disableVersioning=${options.disableVersioning} option on a non-versioned site does not make sense`);
70
- }
71
- const versions = options.disableVersioning ? [] : versionFileContent !== null && versionFileContent !== void 0 ? versionFileContent : [];
72
- // We add the current version at the beginning, unless
73
- // - user don't want to
74
- // - it's been explicitly added to versions.json
75
- if (options.includeCurrentVersion &&
76
- !versions.includes(constants_1.CURRENT_VERSION_NAME)) {
77
- versions.unshift(constants_1.CURRENT_VERSION_NAME);
78
- }
79
- if (versions.length === 0) {
80
- throw new Error(`It is not possible to use docs without any version. Please check the configuration of these options: includeCurrentVersion=${options.includeCurrentVersion} disableVersioning=${options.disableVersioning}`);
81
- }
82
- return versions;
83
- }
84
- function getDocsDirPathLocalized({ siteDir, locale, pluginId, versionName, }) {
85
- return utils_1.getPluginI18nPath({
86
- siteDir,
87
- locale,
88
- pluginName: 'docusaurus-plugin-content-docs',
89
- pluginId,
90
- subPaths: [
91
- versionName === constants_1.CURRENT_VERSION_NAME
92
- ? constants_1.CURRENT_VERSION_NAME
93
- : `version-${versionName}`,
94
- ],
95
- });
96
- }
97
- function getVersionMetadataPaths({ versionName, context, options, }) {
98
- const isCurrentVersion = versionName === constants_1.CURRENT_VERSION_NAME;
99
- const contentPath = isCurrentVersion
100
- ? path_1.default.resolve(context.siteDir, options.path)
101
- : path_1.default.join(getVersionedDocsDirPath(context.siteDir, options.id), `version-${versionName}`);
102
- const contentPathLocalized = getDocsDirPathLocalized({
103
- siteDir: context.siteDir,
104
- locale: context.i18n.currentLocale,
105
- pluginId: options.id,
106
- versionName,
107
- });
108
- function getSidebarFilePath() {
109
- if (isCurrentVersion) {
110
- return options.sidebarPath
111
- ? path_1.default.resolve(context.siteDir, options.sidebarPath)
112
- : options.sidebarPath;
113
- }
114
- else {
115
- return path_1.default.join(getVersionedSidebarsDirPath(context.siteDir, options.id), `version-${versionName}-sidebars.json`);
116
- }
117
- }
118
- return {
119
- contentPath,
120
- contentPathLocalized,
121
- sidebarFilePath: getSidebarFilePath(),
122
- };
123
- }
124
- function getVersionEditUrls({ contentPath, contentPathLocalized, context: { siteDir, i18n }, options: { id, path: currentVersionPath, editUrl, editCurrentVersion }, }) {
125
- if (!editUrl) {
126
- return undefined;
127
- }
128
- // if the user is using the functional form of editUrl,
129
- // he has total freedom and we can't compute a "version edit url"
130
- if (typeof editUrl === 'function') {
131
- return undefined;
132
- }
133
- const editDirPath = editCurrentVersion ? currentVersionPath : contentPath;
134
- const editDirPathLocalized = editCurrentVersion
135
- ? getDocsDirPathLocalized({
136
- siteDir,
137
- locale: i18n.currentLocale,
138
- versionName: constants_1.CURRENT_VERSION_NAME,
139
- pluginId: id,
140
- })
141
- : contentPathLocalized;
142
- const versionPathSegment = utils_1.posixPath(path_1.default.relative(siteDir, path_1.default.resolve(siteDir, editDirPath)));
143
- const versionPathSegmentLocalized = utils_1.posixPath(path_1.default.relative(siteDir, path_1.default.resolve(siteDir, editDirPathLocalized)));
144
- const versionEditUrl = utils_1.normalizeUrl([editUrl, versionPathSegment]);
145
- const versionEditUrlLocalized = utils_1.normalizeUrl([
146
- editUrl,
147
- versionPathSegmentLocalized,
148
- ]);
149
- return {
150
- versionEditUrl,
151
- versionEditUrlLocalized,
152
- };
153
- }
154
- function createVersionMetadata({ versionName, isLast, context, options, }) {
155
- var _a, _b, _c;
156
- const { sidebarFilePath, contentPath, contentPathLocalized, } = getVersionMetadataPaths({
157
- versionName,
158
- context,
159
- options,
160
- });
161
- // retro-compatible values
162
- const defaultVersionLabel = versionName === constants_1.CURRENT_VERSION_NAME ? 'Next' : versionName;
163
- const defaultVersionPathPart = isLast
164
- ? ''
165
- : versionName === constants_1.CURRENT_VERSION_NAME
166
- ? 'next'
167
- : versionName;
168
- const versionOptions = (_a = options.versions[versionName]) !== null && _a !== void 0 ? _a : {};
169
- const versionLabel = (_b = versionOptions.label) !== null && _b !== void 0 ? _b : defaultVersionLabel;
170
- const versionPathPart = (_c = versionOptions.path) !== null && _c !== void 0 ? _c : defaultVersionPathPart;
171
- const versionPath = utils_1.normalizeUrl([
172
- context.baseUrl,
173
- options.routeBasePath,
174
- versionPathPart,
175
- ]);
176
- const versionEditUrls = getVersionEditUrls({
177
- contentPath,
178
- contentPathLocalized,
179
- context,
180
- options,
181
- });
182
- // Because /docs/:route` should always be after `/docs/versionName/:route`.
183
- const routePriority = versionPathPart === '' ? -1 : undefined;
184
- return {
185
- versionName,
186
- versionLabel,
187
- versionPath,
188
- versionEditUrl: versionEditUrls === null || versionEditUrls === void 0 ? void 0 : versionEditUrls.versionEditUrl,
189
- versionEditUrlLocalized: versionEditUrls === null || versionEditUrls === void 0 ? void 0 : versionEditUrls.versionEditUrlLocalized,
190
- isLast,
191
- routePriority,
192
- sidebarFilePath,
193
- contentPath,
194
- contentPathLocalized,
195
- };
196
- }
197
- function checkVersionMetadataPaths({ versionMetadata, context, }) {
198
- const { versionName, contentPath, sidebarFilePath } = versionMetadata;
199
- const { siteDir } = context;
200
- const isCurrentVersion = versionName === constants_1.CURRENT_VERSION_NAME;
201
- if (!fs_extra_1.default.existsSync(contentPath)) {
202
- 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(siteDir, contentPath)}`);
203
- }
204
- // If the current version defines a path to a sidebar file that does not exist, we throw!
205
- // Note: for versioned sidebars, the file may not exist (as we prefer to not create it rather than to create an empty file)
206
- // See https://github.com/facebook/docusaurus/issues/3366
207
- // See https://github.com/facebook/docusaurus/pull/4775
208
- if (isCurrentVersion &&
209
- typeof sidebarFilePath === 'string' &&
210
- !fs_extra_1.default.existsSync(sidebarFilePath)) {
211
- throw new Error(`The path to the sidebar file does not exist at [${path_1.default.relative(siteDir, sidebarFilePath)}].
212
- Please set the docs [sidebarPath] field in your config file to:
213
- - a sidebars path that exists
214
- - false: to disable the sidebar
215
- - undefined: for Docusaurus generates it automatically`);
216
- }
217
- }
218
- // TODO for retrocompatibility with existing behavior
219
- // We should make this configurable
220
- // "last version" is not a very good concept nor api surface
221
- function getDefaultLastVersionName(versionNames) {
222
- if (versionNames.length === 1) {
223
- return versionNames[0];
224
- }
225
- else {
226
- return versionNames.filter((versionName) => versionName !== constants_1.CURRENT_VERSION_NAME)[0];
227
- }
228
- }
229
- function checkVersionsOptions(availableVersionNames, options) {
230
- const availableVersionNamesMsg = `Available version names are: ${availableVersionNames.join(', ')}`;
231
- if (options.lastVersion &&
232
- !availableVersionNames.includes(options.lastVersion)) {
233
- throw new Error(`Docs option lastVersion=${options.lastVersion} is invalid. ${availableVersionNamesMsg}`);
234
- }
235
- const unknownVersionConfigNames = lodash_1.difference(Object.keys(options.versions), availableVersionNames);
236
- if (unknownVersionConfigNames.length > 0) {
237
- throw new Error(`Bad docs options.versions: unknown versions found: ${unknownVersionConfigNames.join(',')}. ${availableVersionNamesMsg}`);
238
- }
239
- if (options.onlyIncludeVersions) {
240
- if (options.onlyIncludeVersions.length === 0) {
241
- throw new Error(`Bad docs options.onlyIncludeVersions: an empty array is not allowed, at least one version is needed`);
242
- }
243
- const unknownOnlyIncludeVersionNames = lodash_1.difference(options.onlyIncludeVersions, availableVersionNames);
244
- if (unknownOnlyIncludeVersionNames.length > 0) {
245
- throw new Error(`Bad docs options.onlyIncludeVersions: unknown versions found: ${unknownOnlyIncludeVersionNames.join(',')}. ${availableVersionNamesMsg}`);
246
- }
247
- if (options.lastVersion &&
248
- !options.onlyIncludeVersions.includes(options.lastVersion)) {
249
- throw new Error(`Bad docs options.lastVersion: if you use both the onlyIncludeVersions and lastVersion options, then lastVersion must be present in the provided onlyIncludeVersions array`);
250
- }
251
- }
252
- }
253
- // Filter versions according to provided options
254
- // Note: we preserve the order in which versions are provided
255
- // the order of the onlyIncludeVersions array does not matter
256
- function filterVersions(versionNamesUnfiltered, options) {
257
- if (options.onlyIncludeVersions) {
258
- return versionNamesUnfiltered.filter((name) => (options.onlyIncludeVersions || []).includes(name));
259
- }
260
- else {
261
- return versionNamesUnfiltered;
262
- }
263
- }
264
- // TODO make this async (requires plugin init to be async)
265
- function readVersionsMetadata({ context, options, }) {
266
- var _a;
267
- const versionNamesUnfiltered = readVersionNames(context.siteDir, options);
268
- checkVersionsOptions(versionNamesUnfiltered, options);
269
- const versionNames = filterVersions(versionNamesUnfiltered, options);
270
- const lastVersionName = (_a = options.lastVersion) !== null && _a !== void 0 ? _a : getDefaultLastVersionName(versionNames);
271
- const versionsMetadata = versionNames.map((versionName) => createVersionMetadata({
272
- versionName,
273
- isLast: versionName === lastVersionName,
274
- context,
275
- options,
276
- }));
277
- versionsMetadata.forEach((versionMetadata) => checkVersionMetadataPaths({ versionMetadata, context }));
278
- return versionsMetadata;
279
- }
280
- exports.readVersionsMetadata = readVersionsMetadata;
281
- // order matter!
282
- // Read in priority the localized path, then the unlocalized one
283
- // We want the localized doc to "override" the unlocalized one
284
- function getDocsDirPaths(versionMetadata) {
285
- return [versionMetadata.contentPathLocalized, versionMetadata.contentPath];
286
- }
287
- exports.getDocsDirPaths = getDocsDirPaths;
@@ -1,5 +0,0 @@
1
- ---
2
- id: hello/super
3
- ---
4
-
5
- Lorem
@@ -1,5 +0,0 @@
1
- ---
2
- slug: docWithSlug.html
3
- ---
4
-
5
- Lorem
@@ -1,16 +0,0 @@
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
- module.exports = {
9
- title: 'My Site',
10
- tagline: 'The tagline of my site',
11
- url: 'https://your-docusaurus-test-site.com',
12
- baseUrl: '/',
13
- favicon: 'img/favicon.ico',
14
- organizationName: 'facebook', // Usually your GitHub org/user name.
15
- projectName: 'docusaurus', // Usually your repo name.
16
- };
@@ -1,34 +0,0 @@
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
- module.exports = {
9
- docs: [
10
- {
11
- 'level 1': [
12
- 'a',
13
- {
14
- 'level 2': [
15
- {
16
- 'level 3': [
17
- 'c',
18
- {
19
- 'level 4': [
20
- 'd',
21
- {
22
- 'deeper more more': ['e'],
23
- },
24
- ],
25
- },
26
- ],
27
- },
28
- 'f',
29
- ],
30
- },
31
- ],
32
- },
33
- ],
34
- };
@@ -1,11 +0,0 @@
1
- {
2
- "docs": {
3
- "Test": [
4
- {
5
- "type": "category",
6
- "label": "Category Label",
7
- "items": "doc1"
8
- }
9
- ]
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- {
2
- "docs": {
3
- "Test": [
4
- {
5
- "type": "category",
6
- "label": true,
7
- "items": ["doc1"]
8
- }
9
- ]
10
- }
11
- }
@@ -1,44 +0,0 @@
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
- module.exports = {
9
- docs: [
10
- {
11
- type: 'category',
12
- label: 'level 1',
13
- items: [
14
- 'a',
15
- {
16
- type: 'category',
17
- label: 'level 2',
18
- items: [
19
- {
20
- type: 'category',
21
- label: 'level 3',
22
- items: [
23
- 'c',
24
- {
25
- type: 'category',
26
- label: 'level 4',
27
- items: [
28
- 'd',
29
- {
30
- type: 'category',
31
- label: 'deeper more more',
32
- items: ['e'],
33
- },
34
- ],
35
- },
36
- ],
37
- },
38
- 'f',
39
- ],
40
- },
41
- ],
42
- },
43
- ],
44
- };
@@ -1,20 +0,0 @@
1
- {
2
- "docs": [
3
- {
4
- "type": "category",
5
- "label": "Introduction",
6
- "items": [
7
- "doc1"
8
- ],
9
- "collapsed": false
10
- },
11
- {
12
- "type": "category",
13
- "label": "Powering MDX",
14
- "items": [
15
- "doc2"
16
- ],
17
- "collapsed": false
18
- }
19
- ]
20
- }
@@ -1,21 +0,0 @@
1
- {
2
- "docs": {
3
- "Test": [
4
- {
5
- "type": "category",
6
- "label": "Introduction",
7
- "items": ["doc1"],
8
- "collapsed": false
9
- }
10
- ],
11
- "Reference": [
12
- {
13
- "type": "category",
14
- "label": "Powering MDX",
15
- "items": ["doc2"],
16
- "collapsed": false
17
- }
18
- ]
19
- }
20
- }
21
-
@@ -1,10 +0,0 @@
1
- {
2
- "docs": {
3
- "Test": [
4
- {
5
- "type": "doc",
6
- "id": ["doc1"]
7
- }
8
- ]
9
- }
10
- }
@@ -1,11 +0,0 @@
1
- {
2
- "docs": {
3
- "Test": [
4
- {
5
- "type": "link",
6
- "label": "GitHub",
7
- "href": ["example.com"]
8
- }
9
- ]
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- {
2
- "docs": {
3
- "Test": [
4
- {
5
- "type": "link",
6
- "label": false,
7
- "href": "https://github.com"
8
- }
9
- ]
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- {
2
- "docs": {
3
- "Test": [
4
- {
5
- "type": "link",
6
- "label": "category",
7
- "href": "https://github.com"
8
- }
9
- ]
10
- }
11
- }
@@ -1,14 +0,0 @@
1
- {
2
- "docs": {
3
- "Test": [
4
- "foo/bar",
5
- "foo/baz",
6
- {
7
- "type": "superman"
8
- }
9
- ],
10
- "Guides": [
11
- "hello"
12
- ]
13
- }
14
- }
@@ -1,20 +0,0 @@
1
- {
2
- "docs": {
3
- "Test": [
4
- "foo/bar",
5
- "foo/baz",
6
- {
7
- "type": "category",
8
- "label": "category",
9
- "href": "https://github.com"
10
- },
11
- {
12
- "type": "ref",
13
- "id": "hello"
14
- }
15
- ],
16
- "Guides": [
17
- "hello"
18
- ]
19
- }
20
- }
@@ -1,20 +0,0 @@
1
- {
2
- "docs": {
3
- "Test": [
4
- "foo/bar",
5
- "foo/baz",
6
- {
7
- "type": "link",
8
- "label": "Github",
9
- "href": "https://github.com"
10
- },
11
- {
12
- "type": "ref",
13
- "id": "hello"
14
- }
15
- ],
16
- "Guides": [
17
- "hello"
18
- ]
19
- }
20
- }