@docusaurus/plugin-content-docs 0.0.0-4904 → 0.0.0-4913

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.
@@ -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
  }
@@ -47,7 +46,7 @@ function toGlobalDataVersion(version) {
47
46
  label: version.label,
48
47
  isLast: version.isLast,
49
48
  path: version.path,
50
- mainDocId: version.mainDocId,
49
+ mainDocId: (0, docs_1.getMainDocId)(version),
51
50
  docs: version.docs
52
51
  .map(toGlobalDataDoc)
53
52
  .concat(version.categoryGeneratedIndices.map(toGlobalDataGeneratedIndex)),
package/lib/index.js CHANGED
@@ -18,12 +18,12 @@ const cli_1 = require("./cli");
18
18
  const constants_1 = require("./constants");
19
19
  const globalData_1 = require("./globalData");
20
20
  const props_1 = require("./props");
21
+ const categoryGeneratedIndex_1 = require("./categoryGeneratedIndex");
21
22
  const translations_1 = require("./translations");
22
23
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
23
24
  const tags_1 = require("./tags");
24
25
  const routes_1 = require("./routes");
25
26
  const utils_2 = require("./sidebars/utils");
26
- const categoryGeneratedIndex_1 = require("./categoryGeneratedIndex");
27
27
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
28
28
  async function pluginContentDocs(context, options) {
29
29
  const { siteDir, generatedFilesDir, baseUrl, siteConfig } = context;
@@ -108,11 +108,6 @@ async function pluginContentDocs(context, options) {
108
108
  docs: (0, docs_1.addDocNavigation)(docs, sidebarsUtils, versionMetadata.sidebarFilePath),
109
109
  drafts,
110
110
  sidebars,
111
- mainDocId: (0, docs_1.getMainDocId)({ docs, sidebarsUtils }),
112
- categoryGeneratedIndices: (0, categoryGeneratedIndex_1.getCategoryGeneratedIndexMetadataList)({
113
- docs,
114
- sidebarsUtils,
115
- }),
116
111
  };
117
112
  }
118
113
  async function loadVersion(versionMetadata) {
@@ -135,6 +130,17 @@ async function pluginContentDocs(context, options) {
135
130
  const { loadedVersions } = content;
136
131
  const { docLayoutComponent, docItemComponent, docCategoryGeneratedIndexComponent, breadcrumbs, } = options;
137
132
  const { addRoute, createData, setGlobalData } = actions;
133
+ const versions = loadedVersions.map((version) => {
134
+ const sidebarsUtils = (0, utils_2.createSidebarsUtils)(version.sidebars);
135
+ return {
136
+ ...version,
137
+ sidebarsUtils,
138
+ categoryGeneratedIndices: (0, categoryGeneratedIndex_1.getCategoryGeneratedIndexMetadataList)({
139
+ docs: version.docs,
140
+ sidebarsUtils,
141
+ }),
142
+ };
143
+ });
138
144
  async function createVersionTagsRoutes(version) {
139
145
  const versionTags = (0, tags_1.getVersionTags)(version.docs);
140
146
  // TODO tags should be a sub route of the version route
@@ -177,8 +183,8 @@ async function pluginContentDocs(context, options) {
177
183
  await createTagsListPage();
178
184
  await Promise.all(Object.values(versionTags).map(createTagDocListPage));
179
185
  }
180
- await Promise.all(loadedVersions.map((loadedVersion) => (0, routes_1.createVersionRoutes)({
181
- loadedVersion,
186
+ await Promise.all(versions.map((version) => (0, routes_1.createVersionRoutes)({
187
+ version,
182
188
  docItemComponent,
183
189
  docLayoutComponent,
184
190
  docCategoryGeneratedIndexComponent,
@@ -187,10 +193,10 @@ async function pluginContentDocs(context, options) {
187
193
  actions,
188
194
  })));
189
195
  // TODO tags should be a sub route of the version route
190
- await Promise.all(loadedVersions.map(createVersionTagsRoutes));
196
+ await Promise.all(versions.map(createVersionTagsRoutes));
191
197
  setGlobalData({
192
198
  path: (0, utils_1.normalizeUrl)([baseUrl, options.routeBasePath]),
193
- versions: loadedVersions.map(globalData_1.toGlobalDataVersion),
199
+ versions: versions.map(globalData_1.toGlobalDataVersion),
194
200
  breadcrumbs,
195
201
  });
196
202
  },
package/lib/routes.d.ts CHANGED
@@ -5,10 +5,10 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { PluginContentLoadedActions, RouteConfig } from '@docusaurus/types';
8
- import type { LoadedVersion } from './types';
8
+ import type { FullVersion } from './types';
9
9
  import type { DocMetadata } from '@docusaurus/plugin-content-docs';
10
10
  export declare function createCategoryGeneratedIndexRoutes({ version, actions, docCategoryGeneratedIndexComponent, aliasedSource, }: {
11
- version: LoadedVersion;
11
+ version: FullVersion;
12
12
  actions: PluginContentLoadedActions;
13
13
  docCategoryGeneratedIndexComponent: string;
14
14
  aliasedSource: (str: string) => string;
@@ -18,8 +18,8 @@ export declare function createDocRoutes({ docs, actions, docItemComponent, }: {
18
18
  actions: PluginContentLoadedActions;
19
19
  docItemComponent: string;
20
20
  }): Promise<RouteConfig[]>;
21
- export declare function createVersionRoutes({ loadedVersion, actions, docItemComponent, docLayoutComponent, docCategoryGeneratedIndexComponent, pluginId, aliasedSource, }: {
22
- loadedVersion: LoadedVersion;
21
+ export declare function createVersionRoutes({ version, actions, docItemComponent, docLayoutComponent, docCategoryGeneratedIndexComponent, pluginId, aliasedSource, }: {
22
+ version: FullVersion;
23
23
  actions: PluginContentLoadedActions;
24
24
  docLayoutComponent: string;
25
25
  docItemComponent: string;
package/lib/routes.js CHANGED
@@ -56,8 +56,8 @@ async function createDocRoutes({ docs, actions, docItemComponent, }) {
56
56
  }));
57
57
  }
58
58
  exports.createDocRoutes = createDocRoutes;
59
- async function createVersionRoutes({ loadedVersion, actions, docItemComponent, docLayoutComponent, docCategoryGeneratedIndexComponent, pluginId, aliasedSource, }) {
60
- async function doCreateVersionRoutes(version) {
59
+ async function createVersionRoutes({ version, actions, docItemComponent, docLayoutComponent, docCategoryGeneratedIndexComponent, pluginId, aliasedSource, }) {
60
+ async function doCreateVersionRoutes() {
61
61
  const versionMetadata = (0, props_1.toVersionMetadataProp)(pluginId, version);
62
62
  const versionMetadataPropPath = await actions.createData(`${(0, utils_1.docuHash)(`version-${version.versionName}-metadata-prop`)}.json`, JSON.stringify(versionMetadata, null, 2));
63
63
  async function createVersionSubRoutes() {
@@ -86,10 +86,10 @@ async function createVersionRoutes({ loadedVersion, actions, docItemComponent, d
86
86
  });
87
87
  }
88
88
  try {
89
- return await doCreateVersionRoutes(loadedVersion);
89
+ return await doCreateVersionRoutes();
90
90
  }
91
91
  catch (err) {
92
- logger_1.default.error `Can't create version routes for version name=${loadedVersion.versionName}`;
92
+ logger_1.default.error `Can't create version routes for version name=${version.versionName}`;
93
93
  throw err;
94
94
  }
95
95
  }
package/lib/types.d.ts CHANGED
@@ -8,6 +8,7 @@ import type { Sidebars } from './sidebars/types';
8
8
  import type { BrokenMarkdownLink } from '@docusaurus/utils';
9
9
  import type { VersionMetadata, LastUpdateData, DocMetadata, CategoryGeneratedIndexMetadata } from '@docusaurus/plugin-content-docs';
10
10
  import type { Tag } from '@docusaurus/types';
11
+ import type { SidebarsUtils } from './sidebars/utils';
11
12
  export declare type DocFile = {
12
13
  contentPath: string;
13
14
  filePath: string;
@@ -26,15 +27,17 @@ export declare type VersionTags = {
26
27
  [permalink: string]: VersionTag;
27
28
  };
28
29
  export declare type LoadedVersion = VersionMetadata & {
29
- mainDocId: string;
30
30
  docs: DocMetadata[];
31
31
  drafts: DocMetadata[];
32
32
  sidebars: Sidebars;
33
- categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
34
33
  };
35
34
  export declare type LoadedContent = {
36
35
  loadedVersions: LoadedVersion[];
37
36
  };
37
+ export declare type FullVersion = LoadedVersion & {
38
+ sidebarsUtils: SidebarsUtils;
39
+ categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
40
+ };
38
41
  export declare type DocBrokenMarkdownLink = BrokenMarkdownLink<VersionMetadata>;
39
42
  export declare type DocsMarkdownOption = {
40
43
  versionsMetadata: VersionMetadata[];
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-4904",
3
+ "version": "0.0.0-4913",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": false,
7
7
  "exports": {
8
+ "./src/*": "./src/*",
8
9
  "./client": "./lib/client/index.js",
9
10
  "./server": "./lib/server-export.js",
10
11
  ".": "./lib/index.js"
@@ -24,11 +25,11 @@
24
25
  },
25
26
  "license": "MIT",
26
27
  "dependencies": {
27
- "@docusaurus/core": "0.0.0-4904",
28
- "@docusaurus/logger": "0.0.0-4904",
29
- "@docusaurus/mdx-loader": "0.0.0-4904",
30
- "@docusaurus/utils": "0.0.0-4904",
31
- "@docusaurus/utils-validation": "0.0.0-4904",
28
+ "@docusaurus/core": "0.0.0-4913",
29
+ "@docusaurus/logger": "0.0.0-4913",
30
+ "@docusaurus/mdx-loader": "0.0.0-4913",
31
+ "@docusaurus/utils": "0.0.0-4913",
32
+ "@docusaurus/utils-validation": "0.0.0-4913",
32
33
  "combine-promises": "^1.1.0",
33
34
  "fs-extra": "^10.1.0",
34
35
  "import-fresh": "^3.3.0",
@@ -40,8 +41,8 @@
40
41
  "webpack": "^5.72.0"
41
42
  },
42
43
  "devDependencies": {
43
- "@docusaurus/module-type-aliases": "0.0.0-4904",
44
- "@docusaurus/types": "0.0.0-4904",
44
+ "@docusaurus/module-type-aliases": "0.0.0-4913",
45
+ "@docusaurus/types": "0.0.0-4913",
45
46
  "@types/js-yaml": "^4.0.5",
46
47
  "@types/picomatch": "^2.3.0",
47
48
  "commander": "^5.1.0",
@@ -57,5 +58,5 @@
57
58
  "engines": {
58
59
  "node": ">=14"
59
60
  },
60
- "gitHead": "a237dd7794660c64330a78c782cf066fae59355c"
61
+ "gitHead": "1212d635d4fde3ae7f92786802f64a2efdc3e3a0"
61
62
  }
package/src/globalData.ts CHANGED
@@ -7,8 +7,8 @@
7
7
 
8
8
  import _ from 'lodash';
9
9
  import type {Sidebars} from './sidebars/types';
10
- import {createSidebarsUtils} from './sidebars/utils';
11
- import type {LoadedVersion} from './types';
10
+ import {getMainDocId} from './docs';
11
+ import type {FullVersion} from './types';
12
12
  import type {
13
13
  CategoryGeneratedIndexMetadata,
14
14
  DocMetadata,
@@ -39,11 +39,10 @@ function toGlobalDataGeneratedIndex(
39
39
 
40
40
  function toGlobalSidebars(
41
41
  sidebars: Sidebars,
42
- version: LoadedVersion,
42
+ version: FullVersion,
43
43
  ): {[sidebarId: string]: GlobalSidebar} {
44
- const {getFirstLink} = createSidebarsUtils(sidebars);
45
44
  return _.mapValues(sidebars, (sidebar, sidebarId) => {
46
- const firstLink = getFirstLink(sidebarId);
45
+ const firstLink = version.sidebarsUtils.getFirstLink(sidebarId);
47
46
  if (!firstLink) {
48
47
  return {};
49
48
  }
@@ -62,13 +61,13 @@ function toGlobalSidebars(
62
61
  });
63
62
  }
64
63
 
65
- export function toGlobalDataVersion(version: LoadedVersion): GlobalVersion {
64
+ export function toGlobalDataVersion(version: FullVersion): GlobalVersion {
66
65
  return {
67
66
  name: version.versionName,
68
67
  label: version.label,
69
68
  isLast: version.isLast,
70
69
  path: version.path,
71
- mainDocId: version.mainDocId,
70
+ mainDocId: getMainDocId(version),
72
71
  docs: version.docs
73
72
  .map(toGlobalDataDoc)
74
73
  .concat(version.categoryGeneratedIndices.map(toGlobalDataGeneratedIndex)),
package/src/index.ts CHANGED
@@ -23,12 +23,7 @@ import type {LoadContext, Plugin} from '@docusaurus/types';
23
23
  import {loadSidebars, resolveSidebarPathOption} from './sidebars';
24
24
  import {CategoryMetadataFilenamePattern} from './sidebars/generator';
25
25
  import type {DocEnv} from './docs';
26
- import {
27
- readVersionDocs,
28
- processDocMetadata,
29
- addDocNavigation,
30
- getMainDocId,
31
- } from './docs';
26
+ import {readVersionDocs, processDocMetadata, addDocNavigation} from './docs';
32
27
  import {readVersionsMetadata} from './versions';
33
28
  import type {
34
29
  LoadedContent,
@@ -37,12 +32,14 @@ import type {
37
32
  DocFile,
38
33
  DocsMarkdownOption,
39
34
  VersionTag,
35
+ FullVersion,
40
36
  } from './types';
41
37
  import type {RuleSetRule} from 'webpack';
42
38
  import {cliDocsVersionCommand} from './cli';
43
39
  import {VERSIONS_JSON_FILE} from './constants';
44
40
  import {toGlobalDataVersion} from './globalData';
45
41
  import {toTagDocListProp} from './props';
42
+ import {getCategoryGeneratedIndexMetadataList} from './categoryGeneratedIndex';
46
43
  import {
47
44
  translateLoadedContent,
48
45
  getLoadedContentTranslationFiles,
@@ -58,7 +55,6 @@ import type {
58
55
  DocFrontMatter,
59
56
  } from '@docusaurus/plugin-content-docs';
60
57
  import {createSidebarsUtils} from './sidebars/utils';
61
- import {getCategoryGeneratedIndexMetadataList} from './categoryGeneratedIndex';
62
58
  import _ from 'lodash';
63
59
 
64
60
  export default async function pluginContentDocs(
@@ -188,11 +184,6 @@ export default async function pluginContentDocs(
188
184
  ),
189
185
  drafts,
190
186
  sidebars,
191
- mainDocId: getMainDocId({docs, sidebarsUtils}),
192
- categoryGeneratedIndices: getCategoryGeneratedIndexMetadataList({
193
- docs,
194
- sidebarsUtils,
195
- }),
196
187
  };
197
188
  }
198
189
 
@@ -223,8 +214,19 @@ export default async function pluginContentDocs(
223
214
  breadcrumbs,
224
215
  } = options;
225
216
  const {addRoute, createData, setGlobalData} = actions;
217
+ const versions: FullVersion[] = loadedVersions.map((version) => {
218
+ const sidebarsUtils = createSidebarsUtils(version.sidebars);
219
+ return {
220
+ ...version,
221
+ sidebarsUtils,
222
+ categoryGeneratedIndices: getCategoryGeneratedIndexMetadataList({
223
+ docs: version.docs,
224
+ sidebarsUtils,
225
+ }),
226
+ };
227
+ });
226
228
 
227
- async function createVersionTagsRoutes(version: LoadedVersion) {
229
+ async function createVersionTagsRoutes(version: FullVersion) {
228
230
  const versionTags = getVersionTags(version.docs);
229
231
 
230
232
  // TODO tags should be a sub route of the version route
@@ -280,9 +282,9 @@ export default async function pluginContentDocs(
280
282
  }
281
283
 
282
284
  await Promise.all(
283
- loadedVersions.map((loadedVersion) =>
285
+ versions.map((version) =>
284
286
  createVersionRoutes({
285
- loadedVersion,
287
+ version,
286
288
  docItemComponent,
287
289
  docLayoutComponent,
288
290
  docCategoryGeneratedIndexComponent,
@@ -294,11 +296,11 @@ export default async function pluginContentDocs(
294
296
  );
295
297
 
296
298
  // TODO tags should be a sub route of the version route
297
- await Promise.all(loadedVersions.map(createVersionTagsRoutes));
299
+ await Promise.all(versions.map(createVersionTagsRoutes));
298
300
 
299
301
  setGlobalData({
300
302
  path: normalizeUrl([baseUrl, options.routeBasePath]),
301
- versions: loadedVersions.map(toGlobalDataVersion),
303
+ versions: versions.map(toGlobalDataVersion),
302
304
  breadcrumbs,
303
305
  });
304
306
  },
package/src/routes.ts CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  import type {PluginContentLoadedActions, RouteConfig} from '@docusaurus/types';
9
9
  import {docuHash, createSlugger} from '@docusaurus/utils';
10
- import type {LoadedVersion} from './types';
10
+ import type {FullVersion} from './types';
11
11
  import type {
12
12
  CategoryGeneratedIndexMetadata,
13
13
  DocMetadata,
@@ -21,7 +21,7 @@ export async function createCategoryGeneratedIndexRoutes({
21
21
  docCategoryGeneratedIndexComponent,
22
22
  aliasedSource,
23
23
  }: {
24
- version: LoadedVersion;
24
+ version: FullVersion;
25
25
  actions: PluginContentLoadedActions;
26
26
  docCategoryGeneratedIndexComponent: string;
27
27
  aliasedSource: (str: string) => string;
@@ -99,7 +99,7 @@ export async function createDocRoutes({
99
99
  }
100
100
 
101
101
  export async function createVersionRoutes({
102
- loadedVersion,
102
+ version,
103
103
  actions,
104
104
  docItemComponent,
105
105
  docLayoutComponent,
@@ -107,7 +107,7 @@ export async function createVersionRoutes({
107
107
  pluginId,
108
108
  aliasedSource,
109
109
  }: {
110
- loadedVersion: LoadedVersion;
110
+ version: FullVersion;
111
111
  actions: PluginContentLoadedActions;
112
112
  docLayoutComponent: string;
113
113
  docItemComponent: string;
@@ -115,7 +115,7 @@ export async function createVersionRoutes({
115
115
  pluginId: string;
116
116
  aliasedSource: (str: string) => string;
117
117
  }): Promise<void> {
118
- async function doCreateVersionRoutes(version: LoadedVersion): Promise<void> {
118
+ async function doCreateVersionRoutes(): Promise<void> {
119
119
  const versionMetadata = toVersionMetadataProp(pluginId, version);
120
120
  const versionMetadataPropPath = await actions.createData(
121
121
  `${docuHash(`version-${version.versionName}-metadata-prop`)}.json`,
@@ -151,9 +151,9 @@ export async function createVersionRoutes({
151
151
  }
152
152
 
153
153
  try {
154
- return await doCreateVersionRoutes(loadedVersion);
154
+ return await doCreateVersionRoutes();
155
155
  } catch (err) {
156
- logger.error`Can't create version routes for version name=${loadedVersion.versionName}`;
156
+ logger.error`Can't create version routes for version name=${version.versionName}`;
157
157
  throw err;
158
158
  }
159
159
  }
package/src/types.ts CHANGED
@@ -16,6 +16,7 @@ import type {
16
16
  CategoryGeneratedIndexMetadata,
17
17
  } from '@docusaurus/plugin-content-docs';
18
18
  import type {Tag} from '@docusaurus/types';
19
+ import type {SidebarsUtils} from './sidebars/utils';
19
20
 
20
21
  export type DocFile = {
21
22
  contentPath: string; // /!\ may be localized
@@ -38,17 +39,20 @@ export type VersionTags = {
38
39
  };
39
40
 
40
41
  export type LoadedVersion = VersionMetadata & {
41
- mainDocId: string;
42
42
  docs: DocMetadata[];
43
43
  drafts: DocMetadata[];
44
44
  sidebars: Sidebars;
45
- categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
46
45
  };
47
46
 
48
47
  export type LoadedContent = {
49
48
  loadedVersions: LoadedVersion[];
50
49
  };
51
50
 
51
+ export type FullVersion = LoadedVersion & {
52
+ sidebarsUtils: SidebarsUtils;
53
+ categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
54
+ };
55
+
52
56
  export type DocBrokenMarkdownLink = BrokenMarkdownLink<VersionMetadata>;
53
57
 
54
58
  export type DocsMarkdownOption = {