@docusaurus/plugin-content-docs 3.8.0 → 3.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -11,22 +11,20 @@ exports.default = pluginContentDocs;
11
11
  const tslib_1 = require("tslib");
12
12
  const path_1 = tslib_1.__importDefault(require("path"));
13
13
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
14
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
15
14
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
16
15
  const utils_1 = require("@docusaurus/utils");
17
16
  const utils_validation_1 = require("@docusaurus/utils-validation");
18
17
  const mdx_loader_1 = require("@docusaurus/mdx-loader");
19
18
  const sidebars_1 = require("./sidebars");
20
19
  const generator_1 = require("./sidebars/generator");
21
- const docs_1 = require("./docs");
22
- const versions_1 = require("./versions");
20
+ const version_1 = require("./versions/version");
23
21
  const cli_1 = tslib_1.__importDefault(require("./cli"));
24
22
  const constants_1 = require("./constants");
25
23
  const globalData_1 = require("./globalData");
26
24
  const translations_1 = require("./translations");
27
25
  const routes_1 = require("./routes");
28
- const utils_2 = require("./sidebars/utils");
29
26
  const contentHelpers_1 = require("./contentHelpers");
27
+ const loadVersion_1 = require("./versions/loadVersion");
30
28
  // MDX loader is not 100% deterministic, leading to cache invalidation issue
31
29
  // This permits to invalidate the MDX loader cache entries when content changes
32
30
  // Problem documented here: https://github.com/facebook/docusaurus/pull/10934
@@ -46,7 +44,7 @@ async function pluginContentDocs(context, options) {
46
44
  const { siteDir, generatedFilesDir, baseUrl, siteConfig } = context;
47
45
  // Mutate options to resolve sidebar path according to siteDir
48
46
  options.sidebarPath = (0, sidebars_1.resolveSidebarPathOption)(siteDir, options.sidebarPath);
49
- const versionsMetadata = await (0, versions_1.readVersionsMetadata)({ context, options });
47
+ const versionsMetadata = await (0, version_1.readVersionsMetadata)({ context, options });
50
48
  const pluginId = options.id;
51
49
  const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-docs');
52
50
  const dataDir = path_1.default.join(pluginDataDirRoot, pluginId);
@@ -95,7 +93,7 @@ async function pluginContentDocs(context, options) {
95
93
  }),
96
94
  markdownConfig: siteConfig.markdown,
97
95
  resolveMarkdownLink: ({ linkPathname, sourceFilePath }) => {
98
- const version = (0, versions_1.getVersionFromSourceFilePath)(sourceFilePath, versionsMetadata);
96
+ const version = (0, version_1.getVersionFromSourceFilePath)(sourceFilePath, versionsMetadata);
99
97
  const permalink = (0, utils_1.resolveMarkdownLinkPathname)(linkPathname, {
100
98
  sourceFilePath,
101
99
  sourceToPermalink: contentHelpers.sourceToPermalink,
@@ -150,78 +148,13 @@ async function pluginContentDocs(context, options) {
150
148
  return versionsMetadata.flatMap(getVersionPathsToWatch);
151
149
  },
152
150
  async loadContent() {
153
- async function loadVersionDocsBase(versionMetadata, tagsFile) {
154
- const docFiles = await (0, docs_1.readVersionDocs)(versionMetadata, options);
155
- if (docFiles.length === 0) {
156
- throw new Error(`Docs version "${versionMetadata.versionName}" has no docs! At least one doc should exist at "${path_1.default.relative(siteDir, versionMetadata.contentPath)}".`);
157
- }
158
- function processVersionDoc(docFile) {
159
- return (0, docs_1.processDocMetadata)({
160
- docFile,
161
- versionMetadata,
162
- context,
163
- options,
164
- env,
165
- tagsFile,
166
- });
167
- }
168
- return Promise.all(docFiles.map(processVersionDoc));
169
- }
170
- async function doLoadVersion(versionMetadata) {
171
- const tagsFile = await (0, utils_validation_1.getTagsFile)({
172
- contentPaths: versionMetadata,
173
- tags: options.tags,
174
- });
175
- const docsBase = await loadVersionDocsBase(versionMetadata, tagsFile);
176
- // TODO we only ever need draftIds in further code, not full draft items
177
- // To simplify and prevent mistakes, avoid exposing draft
178
- // replace draft=>draftIds in content loaded
179
- const [drafts, docs] = lodash_1.default.partition(docsBase, (doc) => doc.draft);
180
- const sidebars = await (0, sidebars_1.loadSidebars)(versionMetadata.sidebarFilePath, {
181
- sidebarItemsGenerator: options.sidebarItemsGenerator,
182
- numberPrefixParser: options.numberPrefixParser,
183
- docs,
184
- drafts,
185
- version: versionMetadata,
186
- sidebarOptions: {
187
- sidebarCollapsed: options.sidebarCollapsed,
188
- sidebarCollapsible: options.sidebarCollapsible,
189
- },
190
- categoryLabelSlugger: (0, utils_1.createSlugger)(),
191
- });
192
- const sidebarsUtils = (0, utils_2.createSidebarsUtils)(sidebars);
193
- const docsById = (0, docs_1.createDocsByIdIndex)(docs);
194
- const allDocIds = Object.keys(docsById);
195
- sidebarsUtils.checkLegacyVersionedSidebarNames({
196
- sidebarFilePath: versionMetadata.sidebarFilePath,
197
- versionMetadata,
198
- });
199
- sidebarsUtils.checkSidebarsDocIds({
200
- allDocIds,
201
- sidebarFilePath: versionMetadata.sidebarFilePath,
202
- versionMetadata,
203
- });
204
- return {
205
- ...versionMetadata,
206
- docs: (0, docs_1.addDocNavigation)({
207
- docs,
208
- sidebarsUtils,
209
- }),
210
- drafts,
211
- sidebars,
212
- };
213
- }
214
- async function loadVersion(versionMetadata) {
215
- try {
216
- return await doLoadVersion(versionMetadata);
217
- }
218
- catch (err) {
219
- logger_1.default.error `Loading of version failed for version name=${versionMetadata.versionName}`;
220
- throw err;
221
- }
222
- }
223
151
  return {
224
- loadedVersions: await Promise.all(versionsMetadata.map(loadVersion)),
152
+ loadedVersions: await Promise.all(versionsMetadata.map((versionMetadata) => (0, loadVersion_1.loadVersion)({
153
+ context,
154
+ options,
155
+ env,
156
+ versionMetadata,
157
+ }))),
225
158
  };
226
159
  },
227
160
  translateContent({ content, translationFiles }) {
@@ -229,7 +162,7 @@ async function pluginContentDocs(context, options) {
229
162
  },
230
163
  async contentLoaded({ content, actions }) {
231
164
  contentHelpers.updateContent(content);
232
- const versions = content.loadedVersions.map(versions_1.toFullVersion);
165
+ const versions = content.loadedVersions.map(version_1.toFullVersion);
233
166
  await (0, routes_1.createAllRoutes)({
234
167
  baseUrl,
235
168
  versions,
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  export { CURRENT_VERSION_NAME, VERSIONED_DOCS_DIR, VERSIONED_SIDEBARS_DIR, VERSIONS_JSON_FILE, } from './constants';
8
- export { filterVersions, getDefaultVersionBanner, getVersionBadge, getVersionBanner, } from './versions';
8
+ export { filterVersions, getDefaultVersionBanner, getVersionBadge, getVersionBanner, } from './versions/version';
9
9
  export { readVersionNames } from './versions/files';
@@ -16,10 +16,10 @@ Object.defineProperty(exports, "CURRENT_VERSION_NAME", { enumerable: true, get:
16
16
  Object.defineProperty(exports, "VERSIONED_DOCS_DIR", { enumerable: true, get: function () { return constants_1.VERSIONED_DOCS_DIR; } });
17
17
  Object.defineProperty(exports, "VERSIONED_SIDEBARS_DIR", { enumerable: true, get: function () { return constants_1.VERSIONED_SIDEBARS_DIR; } });
18
18
  Object.defineProperty(exports, "VERSIONS_JSON_FILE", { enumerable: true, get: function () { return constants_1.VERSIONS_JSON_FILE; } });
19
- var versions_1 = require("./versions");
20
- Object.defineProperty(exports, "filterVersions", { enumerable: true, get: function () { return versions_1.filterVersions; } });
21
- Object.defineProperty(exports, "getDefaultVersionBanner", { enumerable: true, get: function () { return versions_1.getDefaultVersionBanner; } });
22
- Object.defineProperty(exports, "getVersionBadge", { enumerable: true, get: function () { return versions_1.getVersionBadge; } });
23
- Object.defineProperty(exports, "getVersionBanner", { enumerable: true, get: function () { return versions_1.getVersionBanner; } });
19
+ var version_1 = require("./versions/version");
20
+ Object.defineProperty(exports, "filterVersions", { enumerable: true, get: function () { return version_1.filterVersions; } });
21
+ Object.defineProperty(exports, "getDefaultVersionBanner", { enumerable: true, get: function () { return version_1.getDefaultVersionBanner; } });
22
+ Object.defineProperty(exports, "getVersionBadge", { enumerable: true, get: function () { return version_1.getVersionBadge; } });
23
+ Object.defineProperty(exports, "getVersionBanner", { enumerable: true, get: function () { return version_1.getVersionBanner; } });
24
24
  var files_1 = require("./versions/files");
25
25
  Object.defineProperty(exports, "readVersionNames", { enumerable: true, get: function () { return files_1.readVersionNames; } });
@@ -62,7 +62,7 @@ export type SidebarsUtils = {
62
62
  };
63
63
  export declare function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils;
64
64
  export declare function toDocNavigationLink(doc: DocMetadataBase, options?: {
65
- sidebarItemLabel?: string | undefined;
65
+ sidebarItemLabel?: string;
66
66
  }): PropNavigationLink;
67
67
  export declare function toNavigationLink(navigationItem: SidebarNavigationItem | undefined, docsById: {
68
68
  [docId: string]: DocMetadataBase;
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { PluginOptions, VersionMetadata } from '@docusaurus/plugin-content-docs';
8
- import type { VersionContext } from './index';
8
+ import type { VersionContext } from './version';
9
9
  /** `[siteDir]/community_versioned_docs/version-1.0.0` */
10
10
  export declare function getVersionDocsDirPath(siteDir: string, pluginId: string, versionName: string): string;
11
11
  /** `[siteDir]/community_versioned_sidebars/version-1.0.0-sidebars.json` */
@@ -0,0 +1,15 @@
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 DocEnv } from '../docs';
8
+ import type { LoadedVersion, PluginOptions, VersionMetadata } from '@docusaurus/plugin-content-docs';
9
+ import type { LoadContext } from '@docusaurus/types';
10
+ export declare function loadVersion({ context, options, versionMetadata, env, }: {
11
+ context: LoadContext;
12
+ options: PluginOptions;
13
+ versionMetadata: VersionMetadata;
14
+ env: DocEnv;
15
+ }): Promise<LoadedVersion>;
@@ -0,0 +1,89 @@
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.loadVersion = loadVersion;
10
+ const tslib_1 = require("tslib");
11
+ const path_1 = tslib_1.__importDefault(require("path"));
12
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
+ const utils_1 = require("@docusaurus/utils");
14
+ const utils_validation_1 = require("@docusaurus/utils-validation");
15
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
16
+ const docs_1 = require("../docs");
17
+ const sidebars_1 = require("../sidebars");
18
+ const utils_2 = require("../sidebars/utils");
19
+ async function loadVersion({ context, options, versionMetadata, env, }) {
20
+ const { siteDir } = context;
21
+ async function loadVersionDocsBase(tagsFile) {
22
+ const docFiles = await (0, docs_1.readVersionDocs)(versionMetadata, options);
23
+ if (docFiles.length === 0) {
24
+ throw new Error(`Docs version "${versionMetadata.versionName}" has no docs! At least one doc should exist at "${path_1.default.relative(siteDir, versionMetadata.contentPath)}".`);
25
+ }
26
+ function processVersionDoc(docFile) {
27
+ return (0, docs_1.processDocMetadata)({
28
+ docFile,
29
+ versionMetadata,
30
+ context,
31
+ options,
32
+ env,
33
+ tagsFile,
34
+ });
35
+ }
36
+ return Promise.all(docFiles.map(processVersionDoc));
37
+ }
38
+ async function doLoadVersion() {
39
+ const tagsFile = await (0, utils_validation_1.getTagsFile)({
40
+ contentPaths: versionMetadata,
41
+ tags: options.tags,
42
+ });
43
+ const docsBase = await loadVersionDocsBase(tagsFile);
44
+ // TODO we only ever need draftIds in further code, not full draft items
45
+ // To simplify and prevent mistakes, avoid exposing draft
46
+ // replace draft=>draftIds in content loaded
47
+ const [drafts, docs] = lodash_1.default.partition(docsBase, (doc) => doc.draft);
48
+ const sidebars = await (0, sidebars_1.loadSidebars)(versionMetadata.sidebarFilePath, {
49
+ sidebarItemsGenerator: options.sidebarItemsGenerator,
50
+ numberPrefixParser: options.numberPrefixParser,
51
+ docs,
52
+ drafts,
53
+ version: versionMetadata,
54
+ sidebarOptions: {
55
+ sidebarCollapsed: options.sidebarCollapsed,
56
+ sidebarCollapsible: options.sidebarCollapsible,
57
+ },
58
+ categoryLabelSlugger: (0, utils_1.createSlugger)(),
59
+ });
60
+ const sidebarsUtils = (0, utils_2.createSidebarsUtils)(sidebars);
61
+ const docsById = (0, docs_1.createDocsByIdIndex)(docs);
62
+ const allDocIds = Object.keys(docsById);
63
+ sidebarsUtils.checkLegacyVersionedSidebarNames({
64
+ sidebarFilePath: versionMetadata.sidebarFilePath,
65
+ versionMetadata,
66
+ });
67
+ sidebarsUtils.checkSidebarsDocIds({
68
+ allDocIds,
69
+ sidebarFilePath: versionMetadata.sidebarFilePath,
70
+ versionMetadata,
71
+ });
72
+ return {
73
+ ...versionMetadata,
74
+ docs: (0, docs_1.addDocNavigation)({
75
+ docs,
76
+ sidebarsUtils,
77
+ }),
78
+ drafts,
79
+ sidebars,
80
+ };
81
+ }
82
+ try {
83
+ return await doLoadVersion();
84
+ }
85
+ catch (err) {
86
+ logger_1.default.error `Loading of version failed for version name=${versionMetadata.versionName}`;
87
+ throw err;
88
+ }
89
+ }
@@ -151,14 +151,13 @@ async function readVersionsMetadata({ context, options, }) {
151
151
  (0, validation_1.validateVersionsOptions)(allVersionNames, options);
152
152
  const versionNames = filterVersions(allVersionNames, options);
153
153
  const lastVersionName = getLastVersionName({ versionNames, options });
154
- const versionsMetadata = await Promise.all(versionNames.map((versionName) => createVersionMetadata({
154
+ return Promise.all(versionNames.map((versionName) => createVersionMetadata({
155
155
  versionName,
156
156
  versionNames,
157
157
  lastVersionName,
158
158
  context,
159
159
  options,
160
160
  })));
161
- return versionsMetadata;
162
161
  }
163
162
  function toFullVersion(version) {
164
163
  const sidebarsUtils = (0, utils_2.createSidebarsUtils)(version.sidebars);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "3.8.0",
3
+ "version": "3.8.1",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": false,
@@ -35,15 +35,15 @@
35
35
  },
36
36
  "license": "MIT",
37
37
  "dependencies": {
38
- "@docusaurus/core": "3.8.0",
39
- "@docusaurus/logger": "3.8.0",
40
- "@docusaurus/mdx-loader": "3.8.0",
41
- "@docusaurus/module-type-aliases": "3.8.0",
42
- "@docusaurus/theme-common": "3.8.0",
43
- "@docusaurus/types": "3.8.0",
44
- "@docusaurus/utils": "3.8.0",
45
- "@docusaurus/utils-common": "3.8.0",
46
- "@docusaurus/utils-validation": "3.8.0",
38
+ "@docusaurus/core": "3.8.1",
39
+ "@docusaurus/logger": "3.8.1",
40
+ "@docusaurus/mdx-loader": "3.8.1",
41
+ "@docusaurus/module-type-aliases": "3.8.1",
42
+ "@docusaurus/theme-common": "3.8.1",
43
+ "@docusaurus/types": "3.8.1",
44
+ "@docusaurus/utils": "3.8.1",
45
+ "@docusaurus/utils-common": "3.8.1",
46
+ "@docusaurus/utils-validation": "3.8.1",
47
47
  "@types/react-router-config": "^5.0.7",
48
48
  "combine-promises": "^1.1.0",
49
49
  "fs-extra": "^11.1.1",
@@ -67,5 +67,5 @@
67
67
  "engines": {
68
68
  "node": ">=18.0"
69
69
  },
70
- "gitHead": "948d63c42fad0ba24b7b531a9deb6167e64dc845"
70
+ "gitHead": "fa8ae13e668fcbc0481ce10c0a734e2a5b397293"
71
71
  }
package/src/index.ts CHANGED
@@ -7,7 +7,6 @@
7
7
 
8
8
  import path from 'path';
9
9
  import fs from 'fs-extra';
10
- import _ from 'lodash';
11
10
  import logger from '@docusaurus/logger';
12
11
  import {
13
12
  normalizeUrl,
@@ -17,30 +16,19 @@ import {
17
16
  posixPath,
18
17
  addTrailingPathSeparator,
19
18
  createAbsoluteFilePathMatcher,
20
- createSlugger,
21
19
  resolveMarkdownLinkPathname,
22
20
  DEFAULT_PLUGIN_ID,
23
- type TagsFile,
24
21
  } from '@docusaurus/utils';
25
- import {
26
- getTagsFile,
27
- getTagsFilePathsToWatch,
28
- } from '@docusaurus/utils-validation';
22
+ import {getTagsFilePathsToWatch} from '@docusaurus/utils-validation';
29
23
  import {createMDXLoaderRule} from '@docusaurus/mdx-loader';
30
- import {loadSidebars, resolveSidebarPathOption} from './sidebars';
24
+ import {resolveSidebarPathOption} from './sidebars';
31
25
  import {CategoryMetadataFilenamePattern} from './sidebars/generator';
32
- import {
33
- readVersionDocs,
34
- processDocMetadata,
35
- addDocNavigation,
36
- type DocEnv,
37
- createDocsByIdIndex,
38
- } from './docs';
26
+ import {type DocEnv} from './docs';
39
27
  import {
40
28
  getVersionFromSourceFilePath,
41
29
  readVersionsMetadata,
42
30
  toFullVersion,
43
- } from './versions';
31
+ } from './versions/version';
44
32
  import cliDocs from './cli';
45
33
  import {VERSIONS_JSON_FILE} from './constants';
46
34
  import {toGlobalDataVersion} from './globalData';
@@ -49,19 +37,17 @@ import {
49
37
  getLoadedContentTranslationFiles,
50
38
  } from './translations';
51
39
  import {createAllRoutes} from './routes';
52
- import {createSidebarsUtils} from './sidebars/utils';
53
40
 
54
41
  import {createContentHelpers} from './contentHelpers';
42
+ import {loadVersion} from './versions/loadVersion';
55
43
  import type {
56
44
  PluginOptions,
57
- DocMetadataBase,
58
45
  VersionMetadata,
59
46
  DocFrontMatter,
60
47
  LoadedContent,
61
- LoadedVersion,
62
48
  } from '@docusaurus/plugin-content-docs';
63
49
  import type {LoadContext, Plugin} from '@docusaurus/types';
64
- import type {DocFile, FullVersion} from './types';
50
+ import type {FullVersion} from './types';
65
51
  import type {RuleSetRule} from 'webpack';
66
52
 
67
53
  // MDX loader is not 100% deterministic, leading to cache invalidation issue
@@ -243,102 +229,17 @@ export default async function pluginContentDocs(
243
229
  },
244
230
 
245
231
  async loadContent() {
246
- async function loadVersionDocsBase(
247
- versionMetadata: VersionMetadata,
248
- tagsFile: TagsFile | null,
249
- ): Promise<DocMetadataBase[]> {
250
- const docFiles = await readVersionDocs(versionMetadata, options);
251
- if (docFiles.length === 0) {
252
- throw new Error(
253
- `Docs version "${
254
- versionMetadata.versionName
255
- }" has no docs! At least one doc should exist at "${path.relative(
256
- siteDir,
257
- versionMetadata.contentPath,
258
- )}".`,
259
- );
260
- }
261
- function processVersionDoc(docFile: DocFile) {
262
- return processDocMetadata({
263
- docFile,
264
- versionMetadata,
265
- context,
266
- options,
267
- env,
268
- tagsFile,
269
- });
270
- }
271
- return Promise.all(docFiles.map(processVersionDoc));
272
- }
273
-
274
- async function doLoadVersion(
275
- versionMetadata: VersionMetadata,
276
- ): Promise<LoadedVersion> {
277
- const tagsFile = await getTagsFile({
278
- contentPaths: versionMetadata,
279
- tags: options.tags,
280
- });
281
-
282
- const docsBase: DocMetadataBase[] = await loadVersionDocsBase(
283
- versionMetadata,
284
- tagsFile,
285
- );
286
-
287
- // TODO we only ever need draftIds in further code, not full draft items
288
- // To simplify and prevent mistakes, avoid exposing draft
289
- // replace draft=>draftIds in content loaded
290
- const [drafts, docs] = _.partition(docsBase, (doc) => doc.draft);
291
-
292
- const sidebars = await loadSidebars(versionMetadata.sidebarFilePath, {
293
- sidebarItemsGenerator: options.sidebarItemsGenerator,
294
- numberPrefixParser: options.numberPrefixParser,
295
- docs,
296
- drafts,
297
- version: versionMetadata,
298
- sidebarOptions: {
299
- sidebarCollapsed: options.sidebarCollapsed,
300
- sidebarCollapsible: options.sidebarCollapsible,
301
- },
302
- categoryLabelSlugger: createSlugger(),
303
- });
304
-
305
- const sidebarsUtils = createSidebarsUtils(sidebars);
306
-
307
- const docsById = createDocsByIdIndex(docs);
308
- const allDocIds = Object.keys(docsById);
309
-
310
- sidebarsUtils.checkLegacyVersionedSidebarNames({
311
- sidebarFilePath: versionMetadata.sidebarFilePath as string,
312
- versionMetadata,
313
- });
314
- sidebarsUtils.checkSidebarsDocIds({
315
- allDocIds,
316
- sidebarFilePath: versionMetadata.sidebarFilePath as string,
317
- versionMetadata,
318
- });
319
-
320
- return {
321
- ...versionMetadata,
322
- docs: addDocNavigation({
323
- docs,
324
- sidebarsUtils,
325
- }),
326
- drafts,
327
- sidebars,
328
- };
329
- }
330
-
331
- async function loadVersion(versionMetadata: VersionMetadata) {
332
- try {
333
- return await doLoadVersion(versionMetadata);
334
- } catch (err) {
335
- logger.error`Loading of version failed for version name=${versionMetadata.versionName}`;
336
- throw err;
337
- }
338
- }
339
-
340
232
  return {
341
- loadedVersions: await Promise.all(versionsMetadata.map(loadVersion)),
233
+ loadedVersions: await Promise.all(
234
+ versionsMetadata.map((versionMetadata) =>
235
+ loadVersion({
236
+ context,
237
+ options,
238
+ env,
239
+ versionMetadata,
240
+ }),
241
+ ),
242
+ ),
342
243
  };
343
244
  },
344
245
 
@@ -22,5 +22,5 @@ export {
22
22
  getDefaultVersionBanner,
23
23
  getVersionBadge,
24
24
  getVersionBanner,
25
- } from './versions';
25
+ } from './versions/version';
26
26
  export {readVersionNames} from './versions/files';
@@ -480,7 +480,7 @@ Available document ids are:
480
480
 
481
481
  export function toDocNavigationLink(
482
482
  doc: DocMetadataBase,
483
- options?: {sidebarItemLabel?: string | undefined},
483
+ options?: {sidebarItemLabel?: string},
484
484
  ): PropNavigationLink {
485
485
  const {
486
486
  title,
@@ -19,7 +19,7 @@ import type {
19
19
  PluginOptions,
20
20
  VersionMetadata,
21
21
  } from '@docusaurus/plugin-content-docs';
22
- import type {VersionContext} from './index';
22
+ import type {VersionContext} from './version';
23
23
 
24
24
  /** Add a prefix like `community_version-1.0.0`. No-op for default instance. */
25
25
  function addPluginIdPrefix(fileOrDir: string, pluginId: string): string {
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import path from 'path';
9
+ import _ from 'lodash';
10
+ import {createSlugger} from '@docusaurus/utils';
11
+ import {getTagsFile} from '@docusaurus/utils-validation';
12
+ import logger from '@docusaurus/logger';
13
+ import {
14
+ addDocNavigation,
15
+ createDocsByIdIndex,
16
+ type DocEnv,
17
+ processDocMetadata,
18
+ readVersionDocs,
19
+ } from '../docs';
20
+ import {loadSidebars} from '../sidebars';
21
+ import {createSidebarsUtils} from '../sidebars/utils';
22
+ import type {TagsFile} from '@docusaurus/utils';
23
+ import type {
24
+ DocMetadataBase,
25
+ LoadedVersion,
26
+ PluginOptions,
27
+ VersionMetadata,
28
+ } from '@docusaurus/plugin-content-docs';
29
+ import type {DocFile} from '../types';
30
+ import type {LoadContext} from '@docusaurus/types';
31
+
32
+ export async function loadVersion({
33
+ context,
34
+ options,
35
+ versionMetadata,
36
+ env,
37
+ }: {
38
+ context: LoadContext;
39
+ options: PluginOptions;
40
+ versionMetadata: VersionMetadata;
41
+ env: DocEnv;
42
+ }): Promise<LoadedVersion> {
43
+ const {siteDir} = context;
44
+
45
+ async function loadVersionDocsBase(
46
+ tagsFile: TagsFile | null,
47
+ ): Promise<DocMetadataBase[]> {
48
+ const docFiles = await readVersionDocs(versionMetadata, options);
49
+ if (docFiles.length === 0) {
50
+ throw new Error(
51
+ `Docs version "${
52
+ versionMetadata.versionName
53
+ }" has no docs! At least one doc should exist at "${path.relative(
54
+ siteDir,
55
+ versionMetadata.contentPath,
56
+ )}".`,
57
+ );
58
+ }
59
+ function processVersionDoc(docFile: DocFile) {
60
+ return processDocMetadata({
61
+ docFile,
62
+ versionMetadata,
63
+ context,
64
+ options,
65
+ env,
66
+ tagsFile,
67
+ });
68
+ }
69
+ return Promise.all(docFiles.map(processVersionDoc));
70
+ }
71
+
72
+ async function doLoadVersion(): Promise<LoadedVersion> {
73
+ const tagsFile = await getTagsFile({
74
+ contentPaths: versionMetadata,
75
+ tags: options.tags,
76
+ });
77
+
78
+ const docsBase: DocMetadataBase[] = await loadVersionDocsBase(tagsFile);
79
+
80
+ // TODO we only ever need draftIds in further code, not full draft items
81
+ // To simplify and prevent mistakes, avoid exposing draft
82
+ // replace draft=>draftIds in content loaded
83
+ const [drafts, docs] = _.partition(docsBase, (doc) => doc.draft);
84
+
85
+ const sidebars = await loadSidebars(versionMetadata.sidebarFilePath, {
86
+ sidebarItemsGenerator: options.sidebarItemsGenerator,
87
+ numberPrefixParser: options.numberPrefixParser,
88
+ docs,
89
+ drafts,
90
+ version: versionMetadata,
91
+ sidebarOptions: {
92
+ sidebarCollapsed: options.sidebarCollapsed,
93
+ sidebarCollapsible: options.sidebarCollapsible,
94
+ },
95
+ categoryLabelSlugger: createSlugger(),
96
+ });
97
+
98
+ const sidebarsUtils = createSidebarsUtils(sidebars);
99
+
100
+ const docsById = createDocsByIdIndex(docs);
101
+ const allDocIds = Object.keys(docsById);
102
+
103
+ sidebarsUtils.checkLegacyVersionedSidebarNames({
104
+ sidebarFilePath: versionMetadata.sidebarFilePath as string,
105
+ versionMetadata,
106
+ });
107
+ sidebarsUtils.checkSidebarsDocIds({
108
+ allDocIds,
109
+ sidebarFilePath: versionMetadata.sidebarFilePath as string,
110
+ versionMetadata,
111
+ });
112
+
113
+ return {
114
+ ...versionMetadata,
115
+ docs: addDocNavigation({
116
+ docs,
117
+ sidebarsUtils,
118
+ }),
119
+ drafts,
120
+ sidebars,
121
+ };
122
+ }
123
+
124
+ try {
125
+ return await doLoadVersion();
126
+ } catch (err) {
127
+ logger.error`Loading of version failed for version name=${versionMetadata.versionName}`;
128
+ throw err;
129
+ }
130
+ }
@@ -243,7 +243,7 @@ export async function readVersionsMetadata({
243
243
  validateVersionsOptions(allVersionNames, options);
244
244
  const versionNames = filterVersions(allVersionNames, options);
245
245
  const lastVersionName = getLastVersionName({versionNames, options});
246
- const versionsMetadata = await Promise.all(
246
+ return Promise.all(
247
247
  versionNames.map((versionName) =>
248
248
  createVersionMetadata({
249
249
  versionName,
@@ -254,7 +254,6 @@ export async function readVersionsMetadata({
254
254
  }),
255
255
  ),
256
256
  );
257
- return versionsMetadata;
258
257
  }
259
258
 
260
259
  export function toFullVersion(version: LoadedVersion): FullVersion {
File without changes