@docusaurus/plugin-content-docs 2.0.0-beta.18 → 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 (76) hide show
  1. package/lib/categoryGeneratedIndex.d.ts +1 -1
  2. package/lib/categoryGeneratedIndex.js +4 -2
  3. package/lib/cli.d.ts +3 -2
  4. package/lib/cli.js +45 -35
  5. package/lib/client/docsClientUtils.d.ts +6 -5
  6. package/lib/client/docsClientUtils.js +8 -10
  7. package/lib/client/index.d.ts +9 -8
  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 +5 -3
  12. package/lib/docs.js +18 -13
  13. package/lib/frontMatter.d.ts +1 -1
  14. package/lib/frontMatter.js +3 -0
  15. package/lib/globalData.d.ts +2 -2
  16. package/lib/globalData.js +6 -6
  17. package/lib/index.d.ts +1 -2
  18. package/lib/index.js +31 -23
  19. package/lib/markdown/linkify.js +1 -2
  20. package/lib/props.d.ts +3 -3
  21. package/lib/props.js +7 -6
  22. package/lib/routes.d.ts +5 -4
  23. package/lib/routes.js +9 -23
  24. package/lib/server-export.d.ts +2 -1
  25. package/lib/server-export.js +3 -4
  26. package/lib/sidebars/generator.js +3 -3
  27. package/lib/sidebars/index.js +0 -2
  28. package/lib/sidebars/normalization.js +1 -1
  29. package/lib/sidebars/postProcessor.js +2 -2
  30. package/lib/sidebars/processor.js +14 -3
  31. package/lib/sidebars/types.d.ts +18 -14
  32. package/lib/sidebars/utils.d.ts +3 -3
  33. package/lib/slug.d.ts +1 -2
  34. package/lib/tags.d.ts +2 -1
  35. package/lib/tags.js +1 -1
  36. package/lib/translations.d.ts +3 -3
  37. package/lib/translations.js +3 -53
  38. package/lib/types.d.ts +8 -96
  39. package/lib/versions/files.d.ts +44 -0
  40. package/lib/versions/files.js +142 -0
  41. package/lib/versions/index.d.ts +36 -0
  42. package/lib/versions/index.js +155 -0
  43. package/lib/versions/validation.d.ts +17 -0
  44. package/lib/versions/validation.js +71 -0
  45. package/package.json +14 -12
  46. package/src/categoryGeneratedIndex.ts +8 -3
  47. package/src/cli.ts +62 -65
  48. package/src/client/docsClientUtils.ts +11 -13
  49. package/src/client/index.ts +41 -42
  50. package/src/constants.ts +4 -2
  51. package/src/docs.ts +41 -26
  52. package/src/frontMatter.ts +6 -3
  53. package/src/globalData.ts +10 -10
  54. package/src/index.ts +44 -38
  55. package/src/markdown/linkify.ts +2 -3
  56. package/src/plugin-content-docs.d.ts +447 -113
  57. package/src/props.ts +12 -9
  58. package/src/routes.ts +13 -39
  59. package/src/server-export.ts +1 -3
  60. package/src/sidebars/generator.ts +4 -4
  61. package/src/sidebars/index.ts +0 -2
  62. package/src/sidebars/normalization.ts +1 -1
  63. package/src/sidebars/postProcessor.ts +2 -2
  64. package/src/sidebars/processor.ts +24 -5
  65. package/src/sidebars/types.ts +20 -19
  66. package/src/sidebars/utils.ts +6 -3
  67. package/src/slug.ts +4 -2
  68. package/src/tags.ts +3 -2
  69. package/src/translations.ts +10 -61
  70. package/src/types.ts +13 -106
  71. package/src/versions/files.ts +220 -0
  72. package/src/versions/index.ts +247 -0
  73. package/src/versions/validation.ts +113 -0
  74. package/lib/versions.d.ts +0 -41
  75. package/lib/versions.js +0 -324
  76. 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;
@@ -19,8 +19,10 @@ function getCategoryGeneratedIndexMetadata({ category, sidebarsUtils, docsById,
19
19
  slug: category.link.slug,
20
20
  permalink: category.link.permalink,
21
21
  sidebar: sidebarName,
22
- previous: (0, utils_1.toNavigationLink)(previous, docsById),
23
- 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
+ },
24
26
  };
25
27
  }
26
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,10 +8,12 @@
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");
11
+ const files_1 = require("./versions/files");
12
+ const validation_1 = require("./versions/validation");
12
13
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
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
18
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
17
19
  async function createVersionedSidebarFile({ siteDir, pluginId, sidebarPath, version, }) {
@@ -24,61 +26,69 @@ 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.outputFile(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');
30
30
  }
31
31
  }
32
32
  // Tests depend on non-default export for mocking.
33
- async function cliDocsVersionCommand(version, siteDir, pluginId, options) {
33
+ async function cliDocsVersionCommand(version, { id: pluginId, path: docsPath, sidebarPath }, { siteDir, i18n }) {
34
34
  // It wouldn't be very user-friendly to show a [default] log prefix,
35
35
  // so we use [docs] instead of [default]
36
36
  const pluginIdLogPrefix = pluginId === utils_1.DEFAULT_PLUGIN_ID ? '[docs]' : `[${pluginId}]`;
37
- if (!version) {
38
- 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);
39
39
  }
40
- if (version.includes('/') || version.includes('\\')) {
41
- throw new Error(`${pluginIdLogPrefix}: invalid version tag specified! Do not include slash (/) or backslash (\\). Try something like: 1.0.0.`);
42
- }
43
- if (version.length > 32) {
44
- throw new Error(`${pluginIdLogPrefix}: invalid version tag specified! Length cannot exceed 32 characters. Try something like: 1.0.0.`);
45
- }
46
- // Since we are going to create `version-${version}` folder, we need to make
47
- // sure it's a valid pathname.
48
- // eslint-disable-next-line no-control-regex
49
- if (/[<>:"|?*\x00-\x1F]/.test(version)) {
50
- throw new Error(`${pluginIdLogPrefix}: invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0.`);
51
- }
52
- if (/^\.\.?$/.test(version)) {
53
- 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;
54
43
  }
55
44
  // Load existing versions.
56
45
  let versions = [];
57
- const versionsJSONFile = (0, versions_1.getVersionsFilePath)(siteDir, pluginId);
46
+ const versionsJSONFile = (0, files_1.getVersionsFilePath)(siteDir, pluginId);
58
47
  if (await fs_extra_1.default.pathExists(versionsJSONFile)) {
59
- versions = JSON.parse(await fs_extra_1.default.readFile(versionsJSONFile, 'utf8'));
48
+ versions = await fs_extra_1.default.readJSON(versionsJSONFile);
60
49
  }
61
50
  // Check if version already exists.
62
51
  if (versions.includes(version)) {
63
52
  throw new Error(`${pluginIdLogPrefix}: this version already exists! Use a version tag that does not already exist.`);
64
53
  }
65
- const { path: docsPath, sidebarPath } = options;
66
- // Copy docs files.
67
- const docsDir = path_1.default.join(siteDir, docsPath);
68
- if ((await fs_extra_1.default.pathExists(docsDir)) &&
69
- (await fs_extra_1.default.readdir(docsDir)).length > 0) {
70
- const versionedDir = (0, versions_1.getVersionedDocsDirPath)(siteDir, pluginId);
71
- const newVersionDir = path_1.default.join(versionedDir, `version-${version}`);
72
- await fs_extra_1.default.copy(docsDir, newVersionDir);
73
- }
74
- else {
75
- 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}`;
76
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
+ }));
77
87
  await createVersionedSidebarFile({
78
88
  siteDir,
79
89
  pluginId,
80
90
  version,
81
- sidebarPath: (0, sidebars_1.resolveSidebarPathOption)(siteDir, sidebarPath),
91
+ sidebarPath,
82
92
  });
83
93
  // Update versions.json file.
84
94
  versions.unshift(version);
@@ -4,11 +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';
7
+ import type { GlobalPluginData, GlobalVersion, ActivePlugin, ActiveDocContext, DocVersionSuggestions } from '@docusaurus/plugin-content-docs/client';
8
+ import type { UseDataOptions } from '@docusaurus/types';
8
9
  export declare function getActivePlugin(allPluginData: {
9
10
  [pluginId: string]: GlobalPluginData;
10
- }, pathname: string, options?: GetActivePluginOptions): ActivePlugin | undefined;
11
+ }, pathname: string, options?: UseDataOptions): ActivePlugin | undefined;
11
12
  export declare const getLatestVersion: (data: GlobalPluginData) => GlobalVersion;
12
- export declare const getActiveVersion: (data: GlobalPluginData, pathname: string) => GlobalVersion | undefined;
13
- export declare const getActiveDocContext: (data: GlobalPluginData, pathname: string) => ActiveDocContext;
14
- 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;
@@ -34,9 +34,7 @@ function getActivePlugin(allPluginData, 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,10 +47,10 @@ 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);
52
+ function getActiveDocContext(data, pathname) {
53
+ const activeVersion = getActiveVersion(data, pathname);
56
54
  const activeDoc = activeVersion?.docs.find((doc) => !!(0, router_1.matchPath)(pathname, {
57
55
  path: doc.path,
58
56
  exact: true,
@@ -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);
82
+ const activeDocContext = getActiveDocContext(data, pathname);
85
83
  const latestDocSuggestion = activeDocContext?.alternateDocVersions[latestVersion.name];
86
84
  return { latestDocSuggestion, latestVersionSuggestion: latestVersion };
87
- };
85
+ }
88
86
  exports.getDocVersionSuggestions = getDocVersionSuggestions;
@@ -4,18 +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';
7
+ import type { GlobalPluginData, GlobalVersion, ActivePlugin, ActiveDocContext, DocVersionSuggestions } from '@docusaurus/plugin-content-docs/client';
8
+ import type { UseDataOptions } from '@docusaurus/types';
8
9
  export declare const useAllDocsData: () => {
9
10
  [pluginId: string]: GlobalPluginData;
10
11
  };
11
12
  export declare const useDocsData: (pluginId: string | undefined) => GlobalPluginData;
12
- export declare const useActivePlugin: (options?: GetActivePluginOptions) => ActivePlugin | undefined;
13
- export declare const useActivePluginAndVersion: (options?: GetActivePluginOptions) => {
13
+ export declare function useActivePlugin(options?: UseDataOptions): ActivePlugin | undefined;
14
+ export declare function useActivePluginAndVersion(options?: UseDataOptions): {
14
15
  activePlugin: ActivePlugin;
15
16
  activeVersion: GlobalVersion | undefined;
16
17
  } | undefined;
17
- export declare const useVersions: (pluginId: string | undefined) => GlobalVersion[];
18
- export declare const useLatestVersion: (pluginId: string | undefined) => GlobalVersion;
19
- export declare const useActiveVersion: (pluginId: string | undefined) => GlobalVersion | undefined;
20
- export declare const useActiveDocContext: (pluginId: string | undefined) => ActiveDocContext;
21
- 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 = 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 = () => (0, useGlobalData_1.default)()['docusaurus-plugin-content-docs'] ?? 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
  /**
@@ -34,7 +36,7 @@ export declare const isCategoryIndex: CategoryIndexMatcher;
34
36
  * `guides/sidebar/autogenerated.md` ->
35
37
  * `'autogenerated', '.md', ['sidebar', 'guides']`
36
38
  */
37
- export declare function toCategoryIndexMatcherParam({ source, sourceDirName, }: Pick<DocMetadataBase, 'source' | 'sourceDirName'>): CategoryIndexMatcherParam;
39
+ export declare function toCategoryIndexMatcherParam({ source, sourceDirName, }: Pick<DocMetadataBase, 'source' | 'sourceDirName'>): Parameters<CategoryIndexMatcher>[0];
38
40
  export declare function getDocIds(doc: DocMetadataBase): [string, string];
39
41
  export declare function createDocsByIdIndex<Doc extends {
40
42
  id: string;
package/lib/docs.js CHANGED
@@ -15,7 +15,6 @@ const utils_1 = require("@docusaurus/utils");
15
15
  const lastUpdate_1 = require("./lastUpdate");
16
16
  const slug_1 = tslib_1.__importDefault(require("./slug"));
17
17
  const constants_1 = require("./constants");
18
- const versions_1 = require("./versions");
19
18
  const numberPrefix_1 = require("./numberPrefix");
20
19
  const frontMatter_1 = require("./frontMatter");
21
20
  const utils_2 = require("./sidebars/utils");
@@ -40,7 +39,7 @@ async function readLastUpdateData(filePath, options) {
40
39
  return {};
41
40
  }
42
41
  async function readDocFile(versionMetadata, source, options) {
43
- const contentPath = await (0, utils_1.getFolderContainingFile)((0, versions_1.getDocsDirPaths)(versionMetadata), source);
42
+ const contentPath = await (0, utils_1.getFolderContainingFile)((0, utils_1.getContentPathList)(versionMetadata), source);
44
43
  const filePath = path_1.default.join(contentPath, source);
45
44
  const [content, lastUpdate] = await Promise.all([
46
45
  fs_extra_1.default.readFile(filePath, 'utf-8'),
@@ -57,7 +56,11 @@ async function readVersionDocs(versionMetadata, options) {
57
56
  return Promise.all(sources.map((source) => readDocFile(versionMetadata, source, options)));
58
57
  }
59
58
  exports.readVersionDocs = readVersionDocs;
60
- function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
59
+ /** Docs with draft front matter are only considered draft in production. */
60
+ function isDraftForEnvironment({ env, frontMatter, }) {
61
+ return (env === 'production' && frontMatter.draft) ?? false;
62
+ }
63
+ function doProcessDocMetadata({ docFile, versionMetadata, context, options, env, }) {
61
64
  const { source, content, lastUpdate, contentPath, filePath } = docFile;
62
65
  const { siteDir, i18n } = context;
63
66
  const { frontMatter: unsafeFrontMatter, contentTitle, excerpt, } = (0, utils_1.parseMarkdownString)(content);
@@ -67,11 +70,9 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
67
70
  // (01-MyFolder/01-MyDoc.md => MyFolder/MyDoc)
68
71
  // but allow to disable this behavior with front matter
69
72
  parse_number_prefixes: parseNumberPrefixes = true, } = frontMatter;
70
- // ex: api/plugins/myDoc -> myDoc
71
- // ex: myDoc -> myDoc
73
+ // E.g. api/plugins/myDoc -> myDoc; myDoc -> myDoc
72
74
  const sourceFileNameWithoutExtension = path_1.default.basename(source, path_1.default.extname(source));
73
- // ex: api/plugins/myDoc -> api/plugins
74
- // ex: myDoc -> .
75
+ // E.g. api/plugins/myDoc -> api/plugins; myDoc -> .
75
76
  const sourceDirName = path_1.default.dirname(source);
76
77
  const { filename: unprefixedFileName, numberPrefix } = parseNumberPrefixes
77
78
  ? options.numberPrefixParser(sourceFileNameWithoutExtension)
@@ -119,7 +120,7 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
119
120
  // contentTitle (because it can contain markdown/JSX syntax)
120
121
  const title = frontMatter.title ?? contentTitle ?? baseID;
121
122
  const description = frontMatter.description ?? excerpt ?? '';
122
- const permalink = (0, utils_1.normalizeUrl)([versionMetadata.versionPath, docSlug]);
123
+ const permalink = (0, utils_1.normalizeUrl)([versionMetadata.path, docSlug]);
123
124
  function getDocEditUrl() {
124
125
  const relativeFilePath = path_1.default.relative(contentPath, filePath);
125
126
  if (typeof options.editUrl === 'function') {
@@ -134,12 +135,13 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
134
135
  else if (typeof options.editUrl === 'string') {
135
136
  const isLocalized = contentPath === versionMetadata.contentPathLocalized;
136
137
  const baseVersionEditUrl = isLocalized && options.editLocalizedFiles
137
- ? versionMetadata.versionEditUrlLocalized
138
- : versionMetadata.versionEditUrl;
138
+ ? versionMetadata.editUrlLocalized
139
+ : versionMetadata.editUrl;
139
140
  return (0, utils_1.getEditUrl)(relativeFilePath, baseVersionEditUrl);
140
141
  }
141
142
  return undefined;
142
143
  }
144
+ const draft = isDraftForEnvironment({ env, frontMatter });
143
145
  // Assign all of object properties during instantiation (if possible) for
144
146
  // NodeJS optimization.
145
147
  // Adding properties to object after instantiation will cause hidden
@@ -153,13 +155,16 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
153
155
  sourceDirName,
154
156
  slug: docSlug,
155
157
  permalink,
158
+ draft,
156
159
  editUrl: customEditURL !== undefined ? customEditURL : getDocEditUrl(),
157
160
  tags: (0, utils_1.normalizeFrontMatterTags)(versionMetadata.tagsPath, frontMatter.tags),
158
161
  version: versionMetadata.versionName,
159
162
  lastUpdatedBy: lastUpdate.lastUpdatedBy,
160
163
  lastUpdatedAt: lastUpdate.lastUpdatedAt,
161
164
  formattedLastUpdatedAt: lastUpdate.lastUpdatedAt
162
- ? new Intl.DateTimeFormat(i18n.currentLocale).format(lastUpdate.lastUpdatedAt * 1000)
165
+ ? new Intl.DateTimeFormat(i18n.currentLocale, {
166
+ calendar: i18n.localeConfigs[i18n.currentLocale].calendar,
167
+ }).format(lastUpdate.lastUpdatedAt * 1000)
163
168
  : undefined,
164
169
  sidebarPosition,
165
170
  frontMatter,
@@ -201,7 +206,7 @@ function addDocNavigation(docsBase, sidebarsUtils, sidebarFilePath) {
201
206
  return { ...doc, sidebar: navigation.sidebarName, previous, next };
202
207
  }
203
208
  const docsWithNavigation = docsBase.map(addNavData);
204
- // sort to ensure consistent output for tests
209
+ // Sort to ensure consistent output for tests
205
210
  docsWithNavigation.sort((a, b) => a.id.localeCompare(b.id));
206
211
  return docsWithNavigation;
207
212
  }
@@ -269,7 +274,7 @@ function getDocIds(doc) {
269
274
  return [doc.unversionedId, doc.id];
270
275
  }
271
276
  exports.getDocIds = getDocIds;
272
- // docs are indexed by both versioned and unversioned ids at the same time
277
+ // Docs are indexed by both versioned and unversioned ids at the same time
273
278
  // TODO legacy retro-compatibility due to old versioned sidebars using
274
279
  // versioned doc ids ("id" should be removed & "versionedId" should be renamed
275
280
  // to "id")
@@ -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 { DocFrontMatter } from './types';
7
+ import type { DocFrontMatter } from '@docusaurus/plugin-content-docs';
8
8
  export declare function validateDocFrontMatter(frontMatter: {
9
9
  [key: string]: unknown;
10
10
  }): DocFrontMatter;
@@ -14,11 +14,13 @@ const utils_validation_1 = require("@docusaurus/utils-validation");
14
14
  // We use default values in code instead
15
15
  const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
16
16
  id: utils_validation_1.JoiFrontMatter.string(),
17
+ // See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
17
18
  title: utils_validation_1.JoiFrontMatter.string().allow(''),
18
19
  hide_title: utils_validation_1.JoiFrontMatter.boolean(),
19
20
  hide_table_of_contents: utils_validation_1.JoiFrontMatter.boolean(),
20
21
  keywords: utils_validation_1.JoiFrontMatter.array().items(utils_validation_1.JoiFrontMatter.string().required()),
21
22
  image: utils_validation_1.URISchema,
23
+ // See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
22
24
  description: utils_validation_1.JoiFrontMatter.string().allow(''),
23
25
  slug: utils_validation_1.JoiFrontMatter.string(),
24
26
  sidebar_label: utils_validation_1.JoiFrontMatter.string(),
@@ -32,6 +34,7 @@ const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
32
34
  parse_number_prefixes: utils_validation_1.JoiFrontMatter.boolean(),
33
35
  pagination_next: utils_validation_1.JoiFrontMatter.string().allow(null),
34
36
  pagination_prev: utils_validation_1.JoiFrontMatter.string().allow(null),
37
+ draft: utils_validation_1.JoiFrontMatter.boolean(),
35
38
  ...utils_validation_1.FrontMatterTOCHeadingLevels,
36
39
  }).unknown();
37
40
  function validateDocFrontMatter(frontMatter) {
@@ -4,6 +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 { LoadedVersion } from './types';
7
+ import type { FullVersion } from './types';
8
8
  import type { GlobalVersion } from '@docusaurus/plugin-content-docs/client';
9
- export declare function toGlobalDataVersion(version: LoadedVersion): GlobalVersion;
9
+ export declare function toGlobalDataVersion(version: FullVersion): GlobalVersion;
package/lib/globalData.js CHANGED
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.toGlobalDataVersion = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
- const utils_1 = require("./sidebars/utils");
12
+ const docs_1 = require("./docs");
13
13
  function toGlobalDataDoc(doc) {
14
14
  return {
15
15
  id: doc.unversionedId,
@@ -25,9 +25,8 @@ function toGlobalDataGeneratedIndex(doc) {
25
25
  };
26
26
  }
27
27
  function toGlobalSidebars(sidebars, version) {
28
- const { getFirstLink } = (0, utils_1.createSidebarsUtils)(sidebars);
29
28
  return lodash_1.default.mapValues(sidebars, (sidebar, sidebarId) => {
30
- const firstLink = getFirstLink(sidebarId);
29
+ const firstLink = version.sidebarsUtils.getFirstLink(sidebarId);
31
30
  if (!firstLink) {
32
31
  return {};
33
32
  }
@@ -44,13 +43,14 @@ function toGlobalSidebars(sidebars, version) {
44
43
  function toGlobalDataVersion(version) {
45
44
  return {
46
45
  name: version.versionName,
47
- label: version.versionLabel,
46
+ label: version.label,
48
47
  isLast: version.isLast,
49
- path: version.versionPath,
50
- mainDocId: version.mainDocId,
48
+ path: version.path,
49
+ mainDocId: (0, docs_1.getMainDocId)(version),
51
50
  docs: version.docs
52
51
  .map(toGlobalDataDoc)
53
52
  .concat(version.categoryGeneratedIndices.map(toGlobalDataGeneratedIndex)),
53
+ draftIds: version.drafts.map((doc) => doc.unversionedId),
54
54
  sidebars: toGlobalSidebars(version.sidebars, version),
55
55
  };
56
56
  }
package/lib/index.d.ts CHANGED
@@ -5,7 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { LoadContext, Plugin } from '@docusaurus/types';
8
- import type { LoadedContent } from './types';
9
- import type { PluginOptions } from '@docusaurus/plugin-content-docs';
8
+ import type { PluginOptions, LoadedContent } from '@docusaurus/plugin-content-docs';
10
9
  export default function pluginContentDocs(context: LoadContext, options: PluginOptions): Promise<Plugin<LoadedContent>>;
11
10
  export { validateOptions } from './options';