@docusaurus/plugin-content-docs 2.0.0-beta.16 → 2.0.0-beta.19

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 (93) hide show
  1. package/lib/categoryGeneratedIndex.d.ts +1 -1
  2. package/lib/categoryGeneratedIndex.js +5 -7
  3. package/lib/cli.d.ts +3 -2
  4. package/lib/cli.js +49 -41
  5. package/lib/client/docsClientUtils.d.ts +8 -5
  6. package/lib/client/docsClientUtils.js +13 -15
  7. package/lib/client/index.d.ts +12 -9
  8. package/lib/client/index.js +30 -33
  9. package/lib/constants.d.ts +4 -0
  10. package/lib/constants.js +4 -1
  11. package/lib/docs.d.ts +8 -15
  12. package/lib/docs.js +34 -39
  13. package/lib/{docFrontMatter.d.ts → frontMatter.d.ts} +4 -2
  14. package/lib/{docFrontMatter.js → frontMatter.js} +3 -0
  15. package/lib/globalData.d.ts +3 -7
  16. package/lib/globalData.js +9 -13
  17. package/lib/index.d.ts +1 -2
  18. package/lib/index.js +33 -26
  19. package/lib/lastUpdate.d.ts +4 -6
  20. package/lib/lastUpdate.js +14 -5
  21. package/lib/markdown/index.js +1 -1
  22. package/lib/markdown/linkify.js +5 -2
  23. package/lib/numberPrefix.js +16 -22
  24. package/lib/options.d.ts +3 -5
  25. package/lib/options.js +6 -5
  26. package/lib/props.d.ts +3 -3
  27. package/lib/props.js +10 -10
  28. package/lib/routes.d.ts +5 -4
  29. package/lib/routes.js +10 -24
  30. package/lib/server-export.d.ts +2 -1
  31. package/lib/server-export.js +3 -4
  32. package/lib/sidebars/generator.js +63 -44
  33. package/lib/sidebars/index.js +20 -16
  34. package/lib/sidebars/normalization.js +3 -3
  35. package/lib/sidebars/postProcessor.js +18 -25
  36. package/lib/sidebars/processor.d.ts +3 -1
  37. package/lib/sidebars/processor.js +17 -6
  38. package/lib/sidebars/types.d.ts +31 -19
  39. package/lib/sidebars/utils.d.ts +17 -6
  40. package/lib/sidebars/utils.js +27 -37
  41. package/lib/sidebars/validation.d.ts +3 -1
  42. package/lib/sidebars/validation.js +1 -0
  43. package/lib/slug.d.ts +1 -2
  44. package/lib/slug.js +4 -5
  45. package/lib/tags.d.ts +2 -1
  46. package/lib/tags.js +2 -2
  47. package/lib/translations.d.ts +3 -3
  48. package/lib/translations.js +28 -81
  49. package/lib/types.d.ts +10 -95
  50. package/lib/versions/files.d.ts +44 -0
  51. package/lib/versions/files.js +142 -0
  52. package/lib/versions/index.d.ts +36 -0
  53. package/lib/versions/index.js +155 -0
  54. package/lib/versions/validation.d.ts +17 -0
  55. package/lib/versions/validation.js +71 -0
  56. package/package.json +14 -12
  57. package/src/categoryGeneratedIndex.ts +10 -9
  58. package/src/cli.ts +64 -69
  59. package/src/client/docsClientUtils.ts +14 -16
  60. package/src/client/index.ts +42 -43
  61. package/src/constants.ts +4 -2
  62. package/src/deps.d.ts +1 -1
  63. package/src/docs.ts +48 -51
  64. package/src/{docFrontMatter.ts → frontMatter.ts} +9 -6
  65. package/src/globalData.ts +15 -16
  66. package/src/index.ts +45 -40
  67. package/src/lastUpdate.ts +20 -8
  68. package/src/markdown/index.ts +1 -3
  69. package/src/markdown/linkify.ts +6 -3
  70. package/src/numberPrefix.ts +18 -28
  71. package/src/options.ts +6 -8
  72. package/src/plugin-content-docs.d.ts +457 -116
  73. package/src/props.ts +12 -9
  74. package/src/routes.ts +13 -39
  75. package/src/server-export.ts +1 -3
  76. package/src/sidebars/generator.ts +88 -59
  77. package/src/sidebars/index.ts +20 -15
  78. package/src/sidebars/normalization.ts +1 -1
  79. package/src/sidebars/postProcessor.ts +6 -11
  80. package/src/sidebars/processor.ts +27 -14
  81. package/src/sidebars/types.ts +25 -23
  82. package/src/sidebars/utils.ts +45 -46
  83. package/src/sidebars/validation.ts +4 -3
  84. package/src/slug.ts +7 -6
  85. package/src/tags.ts +3 -2
  86. package/src/translations.ts +32 -84
  87. package/src/types.ts +15 -107
  88. package/src/versions/files.ts +220 -0
  89. package/src/versions/index.ts +247 -0
  90. package/src/versions/validation.ts +113 -0
  91. package/lib/versions.d.ts +0 -41
  92. package/lib/versions.js +0 -329
  93. package/src/versions.ts +0 -606
@@ -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 type { CategoryGeneratedIndexMetadata, DocMetadataBase } from './types';
7
+ import type { CategoryGeneratedIndexMetadata, DocMetadataBase } from '@docusaurus/plugin-content-docs';
8
8
  import { type SidebarsUtils } from './sidebars/utils';
9
9
  export declare function getCategoryGeneratedIndexMetadataList({ docs, sidebarsUtils, }: {
10
10
  sidebarsUtils: SidebarsUtils;
@@ -10,21 +10,19 @@ exports.getCategoryGeneratedIndexMetadataList = void 0;
10
10
  const utils_1 = require("./sidebars/utils");
11
11
  const docs_1 = require("./docs");
12
12
  function getCategoryGeneratedIndexMetadata({ category, sidebarsUtils, docsById, }) {
13
- var _a;
14
13
  const { sidebarName, previous, next } = sidebarsUtils.getCategoryGeneratedIndexNavigation(category.link.permalink);
15
- if (!sidebarName) {
16
- throw new Error('unexpected');
17
- }
18
14
  return {
19
- title: (_a = category.link.title) !== null && _a !== void 0 ? _a : category.label,
15
+ title: category.link.title ?? category.label,
20
16
  description: category.link.description,
21
17
  image: category.link.image,
22
18
  keywords: category.link.keywords,
23
19
  slug: category.link.slug,
24
20
  permalink: category.link.permalink,
25
21
  sidebar: sidebarName,
26
- previous: (0, utils_1.toNavigationLink)(previous, docsById),
27
- next: (0, utils_1.toNavigationLink)(next, docsById),
22
+ navigation: {
23
+ previous: (0, utils_1.toNavigationLink)(previous, docsById),
24
+ next: (0, utils_1.toNavigationLink)(next, docsById),
25
+ },
28
26
  };
29
27
  }
30
28
  function getCategoryGeneratedIndexMetadataList({ docs, sidebarsUtils, }) {
package/lib/cli.d.ts CHANGED
@@ -4,5 +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
- import type { PathOptions, SidebarOptions } from '@docusaurus/plugin-content-docs';
8
- export declare function cliDocsVersionCommand(version: string | null | undefined, siteDir: string, pluginId: string, options: PathOptions & SidebarOptions): Promise<void>;
7
+ import type { PluginOptions } from '@docusaurus/plugin-content-docs';
8
+ import type { LoadContext } from '@docusaurus/types';
9
+ export declare function cliDocsVersionCommand(version: string, { id: pluginId, path: docsPath, sidebarPath }: PluginOptions, { siteDir, i18n }: LoadContext): Promise<void>;
package/lib/cli.js CHANGED
@@ -8,12 +8,14 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.cliDocsVersionCommand = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const versions_1 = require("./versions");
12
- const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
13
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
11
+ const files_1 = require("./versions/files");
12
+ const validation_1 = require("./versions/validation");
13
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
14
+ const path_1 = tslib_1.__importDefault(require("path"));
14
15
  const sidebars_1 = require("./sidebars");
16
+ const constants_1 = require("./constants");
15
17
  const utils_1 = require("@docusaurus/utils");
16
- const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
18
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
17
19
  async function createVersionedSidebarFile({ siteDir, pluginId, sidebarPath, version, }) {
18
20
  // Load current sidebar and create a new versioned sidebars file (if needed).
19
21
  // Note: we don't need the sidebars file to be normalized: it's ok to let
@@ -24,67 +26,73 @@ async function createVersionedSidebarFile({ siteDir, pluginId, sidebarPath, vers
24
26
  // or sidebars are disabled/false)
25
27
  const shouldCreateVersionedSidebarFile = Object.keys(sidebars).length > 0;
26
28
  if (shouldCreateVersionedSidebarFile) {
27
- const versionedSidebarsDir = (0, versions_1.getVersionedSidebarsDirPath)(siteDir, pluginId);
28
- const newSidebarFile = path_1.default.join(versionedSidebarsDir, `version-${version}-sidebars.json`);
29
- await fs_extra_1.default.ensureDir(path_1.default.dirname(newSidebarFile));
30
- await fs_extra_1.default.writeFile(newSidebarFile, `${JSON.stringify(sidebars, null, 2)}\n`, 'utf8');
29
+ await fs_extra_1.default.outputFile((0, files_1.getVersionSidebarsPath)(siteDir, pluginId, version), `${JSON.stringify(sidebars, null, 2)}\n`, 'utf8');
31
30
  }
32
31
  }
33
32
  // Tests depend on non-default export for mocking.
34
- async function cliDocsVersionCommand(version, siteDir, pluginId, options) {
33
+ async function cliDocsVersionCommand(version, { id: pluginId, path: docsPath, sidebarPath }, { siteDir, i18n }) {
35
34
  // It wouldn't be very user-friendly to show a [default] log prefix,
36
35
  // so we use [docs] instead of [default]
37
36
  const pluginIdLogPrefix = pluginId === utils_1.DEFAULT_PLUGIN_ID ? '[docs]' : `[${pluginId}]`;
38
- if (!version) {
39
- throw new Error(`${pluginIdLogPrefix}: no version tag specified! Pass the version you wish to create as an argument, for example: 1.0.0.`);
37
+ try {
38
+ (0, validation_1.validateVersionName)(version);
40
39
  }
41
- if (version.includes('/') || version.includes('\\')) {
42
- throw new Error(`${pluginIdLogPrefix}: invalid version tag specified! Do not include slash (/) or backslash (\\). Try something like: 1.0.0.`);
43
- }
44
- if (version.length > 32) {
45
- throw new Error(`${pluginIdLogPrefix}: invalid version tag specified! Length cannot exceed 32 characters. Try something like: 1.0.0.`);
46
- }
47
- // Since we are going to create `version-${version}` folder, we need to make
48
- // sure it's a valid pathname.
49
- // eslint-disable-next-line no-control-regex
50
- if (/[<>:"|?*\x00-\x1F]/g.test(version)) {
51
- throw new Error(`${pluginIdLogPrefix}: invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0.`);
52
- }
53
- if (/^\.\.?$/.test(version)) {
54
- throw new Error(`${pluginIdLogPrefix}: invalid version tag specified! Do not name your version "." or "..". Try something like: 1.0.0.`);
40
+ catch (e) {
41
+ logger_1.default.info `${pluginIdLogPrefix}: Invalid version name provided. Try something like: 1.0.0`;
42
+ throw e;
55
43
  }
56
44
  // Load existing versions.
57
45
  let versions = [];
58
- const versionsJSONFile = (0, versions_1.getVersionsFilePath)(siteDir, pluginId);
46
+ const versionsJSONFile = (0, files_1.getVersionsFilePath)(siteDir, pluginId);
59
47
  if (await fs_extra_1.default.pathExists(versionsJSONFile)) {
60
- versions = JSON.parse(await fs_extra_1.default.readFile(versionsJSONFile, 'utf8'));
48
+ versions = await fs_extra_1.default.readJSON(versionsJSONFile);
61
49
  }
62
50
  // Check if version already exists.
63
51
  if (versions.includes(version)) {
64
52
  throw new Error(`${pluginIdLogPrefix}: this version already exists! Use a version tag that does not already exist.`);
65
53
  }
66
- const { path: docsPath, sidebarPath } = options;
67
- // Copy docs files.
68
- const docsDir = path_1.default.join(siteDir, docsPath);
69
- if ((await fs_extra_1.default.pathExists(docsDir)) &&
70
- (await fs_extra_1.default.readdir(docsDir)).length > 0) {
71
- const versionedDir = (0, versions_1.getVersionedDocsDirPath)(siteDir, pluginId);
72
- const newVersionDir = path_1.default.join(versionedDir, `version-${version}`);
73
- await fs_extra_1.default.copy(docsDir, newVersionDir);
74
- }
75
- else {
76
- throw new Error(`${pluginIdLogPrefix}: there is no docs to version!`);
54
+ if (i18n.locales.length > 1) {
55
+ logger_1.default.info `Versioned docs will be created for the following locales: name=${i18n.locales}`;
77
56
  }
57
+ await Promise.all(i18n.locales.map(async (locale) => {
58
+ // Copy docs files.
59
+ const docsDir = locale === i18n.defaultLocale
60
+ ? path_1.default.resolve(siteDir, docsPath)
61
+ : (0, files_1.getDocsDirPathLocalized)({
62
+ siteDir,
63
+ locale,
64
+ pluginId,
65
+ versionName: constants_1.CURRENT_VERSION_NAME,
66
+ });
67
+ if (!(await fs_extra_1.default.pathExists(docsDir)) ||
68
+ (await fs_extra_1.default.readdir(docsDir)).length === 0) {
69
+ if (locale === i18n.defaultLocale) {
70
+ throw new Error(logger_1.default.interpolate `${pluginIdLogPrefix}: no docs found in path=${docsDir}.`);
71
+ }
72
+ else {
73
+ logger_1.default.warn `${pluginIdLogPrefix}: no docs found in path=${docsDir}. Skipping.`;
74
+ return;
75
+ }
76
+ }
77
+ const newVersionDir = locale === i18n.defaultLocale
78
+ ? (0, files_1.getVersionDocsDirPath)(siteDir, pluginId, version)
79
+ : (0, files_1.getDocsDirPathLocalized)({
80
+ siteDir,
81
+ locale,
82
+ pluginId,
83
+ versionName: version,
84
+ });
85
+ await fs_extra_1.default.copy(docsDir, newVersionDir);
86
+ }));
78
87
  await createVersionedSidebarFile({
79
88
  siteDir,
80
89
  pluginId,
81
90
  version,
82
- sidebarPath: (0, sidebars_1.resolveSidebarPathOption)(siteDir, sidebarPath),
91
+ sidebarPath,
83
92
  });
84
93
  // Update versions.json file.
85
94
  versions.unshift(version);
86
- await fs_extra_1.default.ensureDir(path_1.default.dirname(versionsJSONFile));
87
- await fs_extra_1.default.writeFile(versionsJSONFile, `${JSON.stringify(versions, null, 2)}\n`);
95
+ await fs_extra_1.default.outputFile(versionsJSONFile, `${JSON.stringify(versions, null, 2)}\n`);
88
96
  logger_1.default.success `name=${pluginIdLogPrefix}: version name=${version} created!`;
89
97
  }
90
98
  exports.cliDocsVersionCommand = cliDocsVersionCommand;
@@ -4,9 +4,12 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import type { GlobalPluginData, GlobalVersion, GetActivePluginOptions, ActivePlugin, ActiveDocContext, DocVersionSuggestions } from '@docusaurus/plugin-content-docs/client';
8
- export declare function getActivePlugin(allPluginDatas: Record<string, GlobalPluginData>, pathname: string, options?: GetActivePluginOptions): ActivePlugin | undefined;
7
+ import type { GlobalPluginData, GlobalVersion, ActivePlugin, ActiveDocContext, DocVersionSuggestions } from '@docusaurus/plugin-content-docs/client';
8
+ import type { UseDataOptions } from '@docusaurus/types';
9
+ export declare function getActivePlugin(allPluginData: {
10
+ [pluginId: string]: GlobalPluginData;
11
+ }, pathname: string, options?: UseDataOptions): ActivePlugin | undefined;
9
12
  export declare const getLatestVersion: (data: GlobalPluginData) => GlobalVersion;
10
- export declare const getActiveVersion: (data: GlobalPluginData, pathname: string) => GlobalVersion | undefined;
11
- export declare const getActiveDocContext: (data: GlobalPluginData, pathname: string) => ActiveDocContext;
12
- export declare const getDocVersionSuggestions: (data: GlobalPluginData, pathname: string) => DocVersionSuggestions;
13
+ export declare function getActiveVersion(data: GlobalPluginData, pathname: string): GlobalVersion | undefined;
14
+ export declare function getActiveDocContext(data: GlobalPluginData, pathname: string): ActiveDocContext;
15
+ export declare function getDocVersionSuggestions(data: GlobalPluginData, pathname: string): DocVersionSuggestions;
@@ -12,8 +12,8 @@ const router_1 = require("@docusaurus/router");
12
12
  // get the data of the plugin that is currently "active"
13
13
  // ie the docs of that plugin are currently browsed
14
14
  // it is useful to support multiple docs plugin instances
15
- function getActivePlugin(allPluginDatas, pathname, options = {}) {
16
- const activeEntry = Object.entries(allPluginDatas)
15
+ function getActivePlugin(allPluginData, pathname, options = {}) {
16
+ const activeEntry = Object.entries(allPluginData)
17
17
  // Route sorting: '/android/foo' should match '/android' instead of '/'
18
18
  .sort((a, b) => b[1].path.localeCompare(a[1].path))
19
19
  .find(([, pluginData]) => !!(0, router_1.matchPath)(pathname, {
@@ -25,7 +25,7 @@ function getActivePlugin(allPluginDatas, pathname, options = {}) {
25
25
  ? { pluginId: activeEntry[0], pluginData: activeEntry[1] }
26
26
  : undefined;
27
27
  if (!activePlugin && options.failfast) {
28
- throw new Error(`Can't find active docs plugin for "${pathname}" pathname, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: ${Object.values(allPluginDatas)
28
+ throw new Error(`Can't find active docs plugin for "${pathname}" pathname, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: ${Object.values(allPluginData)
29
29
  .map((plugin) => plugin.path)
30
30
  .join(', ')}`);
31
31
  }
@@ -34,9 +34,7 @@ function getActivePlugin(allPluginDatas, pathname, options = {}) {
34
34
  exports.getActivePlugin = getActivePlugin;
35
35
  const getLatestVersion = (data) => data.versions.find((version) => version.isLast);
36
36
  exports.getLatestVersion = getLatestVersion;
37
- // Note: return undefined on doc-unrelated pages,
38
- // because there's no version currently considered as active
39
- const getActiveVersion = (data, pathname) => {
37
+ function getActiveVersion(data, pathname) {
40
38
  const lastVersion = (0, exports.getLatestVersion)(data);
41
39
  // Last version is a route like /docs/*,
42
40
  // we need to match it last or it would match /docs/version-1.0/* as well
@@ -49,11 +47,11 @@ const getActiveVersion = (data, pathname) => {
49
47
  exact: false,
50
48
  strict: false,
51
49
  }));
52
- };
50
+ }
53
51
  exports.getActiveVersion = getActiveVersion;
54
- const getActiveDocContext = (data, pathname) => {
55
- const activeVersion = (0, exports.getActiveVersion)(data, pathname);
56
- const activeDoc = activeVersion === null || activeVersion === void 0 ? void 0 : activeVersion.docs.find((doc) => !!(0, router_1.matchPath)(pathname, {
52
+ function getActiveDocContext(data, pathname) {
53
+ const activeVersion = getActiveVersion(data, pathname);
54
+ const activeDoc = activeVersion?.docs.find((doc) => !!(0, router_1.matchPath)(pathname, {
57
55
  path: doc.path,
58
56
  exact: true,
59
57
  strict: false,
@@ -77,12 +75,12 @@ const getActiveDocContext = (data, pathname) => {
77
75
  activeDoc,
78
76
  alternateDocVersions: alternateVersionDocs,
79
77
  };
80
- };
78
+ }
81
79
  exports.getActiveDocContext = getActiveDocContext;
82
- const getDocVersionSuggestions = (data, pathname) => {
80
+ function getDocVersionSuggestions(data, pathname) {
83
81
  const latestVersion = (0, exports.getLatestVersion)(data);
84
- const activeDocContext = (0, exports.getActiveDocContext)(data, pathname);
85
- const latestDocSuggestion = activeDocContext === null || activeDocContext === void 0 ? void 0 : activeDocContext.alternateDocVersions[latestVersion.name];
82
+ const activeDocContext = getActiveDocContext(data, pathname);
83
+ const latestDocSuggestion = activeDocContext?.alternateDocVersions[latestVersion.name];
86
84
  return { latestDocSuggestion, latestVersionSuggestion: latestVersion };
87
- };
85
+ }
88
86
  exports.getDocVersionSuggestions = getDocVersionSuggestions;
@@ -4,16 +4,19 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import type { GlobalPluginData, GlobalVersion, ActivePlugin, ActiveDocContext, DocVersionSuggestions, GetActivePluginOptions } from '@docusaurus/plugin-content-docs/client';
8
- export declare const useAllDocsData: () => Record<string, GlobalPluginData>;
7
+ import type { GlobalPluginData, GlobalVersion, ActivePlugin, ActiveDocContext, DocVersionSuggestions } from '@docusaurus/plugin-content-docs/client';
8
+ import type { UseDataOptions } from '@docusaurus/types';
9
+ export declare const useAllDocsData: () => {
10
+ [pluginId: string]: GlobalPluginData;
11
+ };
9
12
  export declare const useDocsData: (pluginId: string | undefined) => GlobalPluginData;
10
- export declare const useActivePlugin: (options?: GetActivePluginOptions) => ActivePlugin | undefined;
11
- export declare const useActivePluginAndVersion: (options?: GetActivePluginOptions) => {
13
+ export declare function useActivePlugin(options?: UseDataOptions): ActivePlugin | undefined;
14
+ export declare function useActivePluginAndVersion(options?: UseDataOptions): {
12
15
  activePlugin: ActivePlugin;
13
16
  activeVersion: GlobalVersion | undefined;
14
17
  } | undefined;
15
- export declare const useVersions: (pluginId: string | undefined) => GlobalVersion[];
16
- export declare const useLatestVersion: (pluginId: string | undefined) => GlobalVersion;
17
- export declare const useActiveVersion: (pluginId: string | undefined) => GlobalVersion | undefined;
18
- export declare const useActiveDocContext: (pluginId: string | undefined) => ActiveDocContext;
19
- export declare const useDocVersionSuggestions: (pluginId: string | undefined) => DocVersionSuggestions;
18
+ export declare function useVersions(pluginId: string | undefined): GlobalVersion[];
19
+ export declare function useLatestVersion(pluginId: string | undefined): GlobalVersion;
20
+ export declare function useActiveVersion(pluginId: string | undefined): GlobalVersion | undefined;
21
+ export declare function useActiveDocContext(pluginId: string | undefined): ActiveDocContext;
22
+ export declare function useDocVersionSuggestions(pluginId: string | undefined): DocVersionSuggestions;
@@ -7,69 +7,66 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
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
10
  const router_1 = require("@docusaurus/router");
12
- const useGlobalData_1 = (0, tslib_1.__importStar)(require("@docusaurus/useGlobalData"));
11
+ const useGlobalData_1 = require("@docusaurus/useGlobalData");
13
12
  const docsClientUtils_1 = require("./docsClientUtils");
14
13
  // Important to use a constant object to avoid React useEffect executions etc.
15
14
  // see https://github.com/facebook/docusaurus/issues/5089
16
15
  const StableEmptyObject = {};
17
- // Not using useAllPluginInstancesData() because in blog-only mode, docs hooks
18
- // are still used by the theme. We need a fail-safe fallback when the docs
19
- // plugin is not in use
20
- const useAllDocsData = () => { var _a; return (_a = (0, useGlobalData_1.default)()['docusaurus-plugin-content-docs']) !== null && _a !== void 0 ? _a : StableEmptyObject; };
16
+ // In blog-only mode, docs hooks are still used by the theme. We need a fail-
17
+ // safe fallback when the docs plugin is not in use
18
+ const useAllDocsData = () => (0, useGlobalData_1.useAllPluginInstancesData)('docusaurus-plugin-content-docs') ??
19
+ StableEmptyObject;
21
20
  exports.useAllDocsData = useAllDocsData;
22
- const useDocsData = (pluginId) => (0, useGlobalData_1.usePluginData)('docusaurus-plugin-content-docs', pluginId);
21
+ const useDocsData = (pluginId) => (0, useGlobalData_1.usePluginData)('docusaurus-plugin-content-docs', pluginId, {
22
+ failfast: true,
23
+ });
23
24
  exports.useDocsData = useDocsData;
24
25
  // TODO this feature should be provided by docusaurus core
25
- const useActivePlugin = (options = {}) => {
26
+ function useActivePlugin(options = {}) {
26
27
  const data = (0, exports.useAllDocsData)();
27
28
  const { pathname } = (0, router_1.useLocation)();
28
29
  return (0, docsClientUtils_1.getActivePlugin)(data, pathname, options);
29
- };
30
+ }
30
31
  exports.useActivePlugin = useActivePlugin;
31
- const useActivePluginAndVersion = (options = {}) => {
32
- const activePlugin = (0, exports.useActivePlugin)(options);
32
+ function useActivePluginAndVersion(options = {}) {
33
+ const activePlugin = useActivePlugin(options);
33
34
  const { pathname } = (0, router_1.useLocation)();
34
- if (activePlugin) {
35
- const activeVersion = (0, docsClientUtils_1.getActiveVersion)(activePlugin.pluginData, pathname);
36
- return {
37
- activePlugin,
38
- activeVersion,
39
- };
35
+ if (!activePlugin) {
36
+ return undefined;
40
37
  }
41
- return undefined;
42
- };
38
+ const activeVersion = (0, docsClientUtils_1.getActiveVersion)(activePlugin.pluginData, pathname);
39
+ return {
40
+ activePlugin,
41
+ activeVersion,
42
+ };
43
+ }
43
44
  exports.useActivePluginAndVersion = useActivePluginAndVersion;
44
- // versions are returned ordered (most recent first)
45
- const useVersions = (pluginId) => {
45
+ function useVersions(pluginId) {
46
46
  const data = (0, exports.useDocsData)(pluginId);
47
47
  return data.versions;
48
- };
48
+ }
49
49
  exports.useVersions = useVersions;
50
- const useLatestVersion = (pluginId) => {
50
+ function useLatestVersion(pluginId) {
51
51
  const data = (0, exports.useDocsData)(pluginId);
52
52
  return (0, docsClientUtils_1.getLatestVersion)(data);
53
- };
53
+ }
54
54
  exports.useLatestVersion = useLatestVersion;
55
- // Note: return undefined on doc-unrelated pages,
56
- // because there's no version currently considered as active
57
- const useActiveVersion = (pluginId) => {
55
+ function useActiveVersion(pluginId) {
58
56
  const data = (0, exports.useDocsData)(pluginId);
59
57
  const { pathname } = (0, router_1.useLocation)();
60
58
  return (0, docsClientUtils_1.getActiveVersion)(data, pathname);
61
- };
59
+ }
62
60
  exports.useActiveVersion = useActiveVersion;
63
- const useActiveDocContext = (pluginId) => {
61
+ function useActiveDocContext(pluginId) {
64
62
  const data = (0, exports.useDocsData)(pluginId);
65
63
  const { pathname } = (0, router_1.useLocation)();
66
64
  return (0, docsClientUtils_1.getActiveDocContext)(data, pathname);
67
- };
65
+ }
68
66
  exports.useActiveDocContext = useActiveDocContext;
69
- // Useful to say "hey, you are not on the latest docs version, please switch"
70
- const useDocVersionSuggestions = (pluginId) => {
67
+ function useDocVersionSuggestions(pluginId) {
71
68
  const data = (0, exports.useDocsData)(pluginId);
72
69
  const { pathname } = (0, router_1.useLocation)();
73
70
  return (0, docsClientUtils_1.getDocVersionSuggestions)(data, pathname);
74
- };
71
+ }
75
72
  exports.useDocVersionSuggestions = useDocVersionSuggestions;
@@ -4,7 +4,11 @@
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
+ /** The name of the version that's actively worked on (e.g. `website/docs`) */
7
8
  export declare const CURRENT_VERSION_NAME = "current";
9
+ /** All doc versions are stored here by version names */
8
10
  export declare const VERSIONED_DOCS_DIR = "versioned_docs";
11
+ /** All doc versioned sidebars are stored here by version names */
9
12
  export declare const VERSIONED_SIDEBARS_DIR = "versioned_sidebars";
13
+ /** The version names. Should 1-1 map to the content of versioned docs dir. */
10
14
  export declare const VERSIONS_JSON_FILE = "versions.json";
package/lib/constants.js CHANGED
@@ -7,8 +7,11 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.VERSIONS_JSON_FILE = exports.VERSIONED_SIDEBARS_DIR = exports.VERSIONED_DOCS_DIR = exports.CURRENT_VERSION_NAME = void 0;
10
- // The name of the version at the root of your site (website/docs)
10
+ /** The name of the version that's actively worked on (e.g. `website/docs`) */
11
11
  exports.CURRENT_VERSION_NAME = 'current';
12
+ /** All doc versions are stored here by version names */
12
13
  exports.VERSIONED_DOCS_DIR = 'versioned_docs';
14
+ /** All doc versioned sidebars are stored here by version names */
13
15
  exports.VERSIONED_SIDEBARS_DIR = 'versioned_sidebars';
16
+ /** The version names. Should 1-1 map to the content of versioned docs dir. */
14
17
  exports.VERSIONS_JSON_FILE = 'versions.json';
package/lib/docs.d.ts CHANGED
@@ -5,17 +5,19 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { LoadContext } from '@docusaurus/types';
8
- import type { DocFile, DocMetadataBase, VersionMetadata, LoadedVersion } from './types';
8
+ import type { DocFile } from './types';
9
9
  import type { SidebarsUtils } from './sidebars/utils';
10
- import type { MetadataOptions, PluginOptions, CategoryIndexMatcher, CategoryIndexMatcherParam } from '@docusaurus/plugin-content-docs';
10
+ import type { MetadataOptions, PluginOptions, CategoryIndexMatcher, DocMetadataBase, VersionMetadata, LoadedVersion } from '@docusaurus/plugin-content-docs';
11
11
  declare type LastUpdateOptions = Pick<PluginOptions, 'showLastUpdateAuthor' | 'showLastUpdateTime'>;
12
12
  export declare function readDocFile(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>, source: string, options: LastUpdateOptions): Promise<DocFile>;
13
13
  export declare function readVersionDocs(versionMetadata: VersionMetadata, options: Pick<PluginOptions, 'include' | 'exclude' | 'showLastUpdateAuthor' | 'showLastUpdateTime'>): Promise<DocFile[]>;
14
+ export declare type DocEnv = 'production' | 'development';
14
15
  export declare function processDocMetadata(args: {
15
16
  docFile: DocFile;
16
17
  versionMetadata: VersionMetadata;
17
18
  context: LoadContext;
18
19
  options: MetadataOptions;
20
+ env: DocEnv;
19
21
  }): DocMetadataBase;
20
22
  export declare function addDocNavigation(docsBase: DocMetadataBase[], sidebarsUtils: SidebarsUtils, sidebarFilePath: string): LoadedVersion['docs'];
21
23
  /**
@@ -30,25 +32,16 @@ export declare function getMainDocId({ docs, sidebarsUtils, }: {
30
32
  sidebarsUtils: SidebarsUtils;
31
33
  }): string;
32
34
  export declare const isCategoryIndex: CategoryIndexMatcher;
33
- export declare function toCategoryIndexMatcherParam({ source, sourceDirName, }: Pick<DocMetadataBase, 'source' | 'sourceDirName'>): CategoryIndexMatcherParam;
34
35
  /**
35
36
  * `guides/sidebar/autogenerated.md` ->
36
37
  * `'autogenerated', '.md', ['sidebar', 'guides']`
37
38
  */
38
- export declare function splitPath(str: string): {
39
- /**
40
- * The list of directories, from lowest level to highest.
41
- * If there's no dir name, directories is ['.']
42
- */
43
- directories: string[];
44
- /** The file name, without extension */
45
- fileName: string;
46
- /** The extension, with a leading dot */
47
- extension: string;
48
- };
39
+ export declare function toCategoryIndexMatcherParam({ source, sourceDirName, }: Pick<DocMetadataBase, 'source' | 'sourceDirName'>): Parameters<CategoryIndexMatcher>[0];
49
40
  export declare function getDocIds(doc: DocMetadataBase): [string, string];
50
41
  export declare function createDocsByIdIndex<Doc extends {
51
42
  id: string;
52
43
  unversionedId: string;
53
- }>(docs: Doc[]): Record<string, Doc>;
44
+ }>(docs: Doc[]): {
45
+ [docId: string]: Doc;
46
+ };
54
47
  export {};