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