@docusaurus/plugin-content-docs 3.8.1-canary-6342 → 3.8.1-canary-6345

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.
@@ -7,9 +7,11 @@
7
7
  import { type DocEnv } from '../docs';
8
8
  import type { LoadedVersion, PluginOptions, VersionMetadata } from '@docusaurus/plugin-content-docs';
9
9
  import type { LoadContext } from '@docusaurus/types';
10
- export declare function loadVersion({ context, options, versionMetadata, env, }: {
10
+ type LoadVersionParams = {
11
11
  context: LoadContext;
12
12
  options: PluginOptions;
13
13
  versionMetadata: VersionMetadata;
14
14
  env: DocEnv;
15
- }): Promise<LoadedVersion>;
15
+ };
16
+ export declare function loadVersion(params: LoadVersionParams): Promise<LoadedVersion>;
17
+ export {};
@@ -16,74 +16,105 @@ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
16
16
  const docs_1 = require("../docs");
17
17
  const sidebars_1 = require("../sidebars");
18
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));
19
+ function ensureNoDuplicateDocId(docs) {
20
+ const duplicatesById = lodash_1.default.chain(docs)
21
+ .groupBy((d) => d.id)
22
+ .pickBy((group) => group.length > 1)
23
+ .value();
24
+ const duplicateIdEntries = Object.entries(duplicatesById);
25
+ if (duplicateIdEntries.length) {
26
+ const idMessages = duplicateIdEntries
27
+ .map(([id, duplicateDocs]) => {
28
+ return logger_1.default.interpolate `- code=${id} found in number=${duplicateDocs.length} docs:
29
+ - ${duplicateDocs
30
+ .map((d) => (0, utils_1.aliasedSitePathToRelativePath)(d.source))
31
+ .join('\n - ')}`;
32
+ })
33
+ .join('\n\n');
34
+ const message = `The docs plugin found docs sharing the same id:
35
+ \n${idMessages}\n
36
+ Docs should have distinct ids.
37
+ In case of conflict, you can rename the docs file, or use the ${logger_1.default.code('id')} front matter to assign an explicit distinct id to each doc.
38
+ `;
39
+ throw new Error(message);
37
40
  }
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,
41
+ }
42
+ async function loadVersionDocsBase({ tagsFile, context, options, versionMetadata, env, }) {
43
+ const docFiles = await (0, docs_1.readVersionDocs)(versionMetadata, options);
44
+ if (docFiles.length === 0) {
45
+ throw new Error(`Docs version "${versionMetadata.versionName}" has no docs! At least one doc should exist at "${path_1.default.relative(context.siteDir, versionMetadata.contentPath)}".`);
46
+ }
47
+ function processVersionDoc(docFile) {
48
+ return (0, docs_1.processDocMetadata)({
49
+ docFile,
70
50
  versionMetadata,
51
+ context,
52
+ options,
53
+ env,
54
+ tagsFile,
71
55
  });
72
- return {
73
- ...versionMetadata,
74
- docs: (0, docs_1.addDocNavigation)({
75
- docs,
76
- sidebarsUtils,
77
- }),
78
- drafts,
79
- sidebars,
80
- };
81
56
  }
57
+ const docs = await Promise.all(docFiles.map(processVersionDoc));
58
+ ensureNoDuplicateDocId(docs);
59
+ return docs;
60
+ }
61
+ async function doLoadVersion({ context, options, versionMetadata, env, }) {
62
+ const tagsFile = await (0, utils_validation_1.getTagsFile)({
63
+ contentPaths: versionMetadata,
64
+ tags: options.tags,
65
+ });
66
+ const docsBase = await loadVersionDocsBase({
67
+ tagsFile,
68
+ context,
69
+ options,
70
+ versionMetadata,
71
+ env,
72
+ });
73
+ // TODO we only ever need draftIds in further code, not full draft items
74
+ // To simplify and prevent mistakes, avoid exposing draft
75
+ // replace draft=>draftIds in content loaded
76
+ const [drafts, docs] = lodash_1.default.partition(docsBase, (doc) => doc.draft);
77
+ const sidebars = await (0, sidebars_1.loadSidebars)(versionMetadata.sidebarFilePath, {
78
+ sidebarItemsGenerator: options.sidebarItemsGenerator,
79
+ numberPrefixParser: options.numberPrefixParser,
80
+ docs,
81
+ drafts,
82
+ version: versionMetadata,
83
+ sidebarOptions: {
84
+ sidebarCollapsed: options.sidebarCollapsed,
85
+ sidebarCollapsible: options.sidebarCollapsible,
86
+ },
87
+ categoryLabelSlugger: (0, utils_1.createSlugger)(),
88
+ });
89
+ const sidebarsUtils = (0, utils_2.createSidebarsUtils)(sidebars);
90
+ const docsById = (0, docs_1.createDocsByIdIndex)(docs);
91
+ const allDocIds = Object.keys(docsById);
92
+ sidebarsUtils.checkLegacyVersionedSidebarNames({
93
+ sidebarFilePath: versionMetadata.sidebarFilePath,
94
+ versionMetadata,
95
+ });
96
+ sidebarsUtils.checkSidebarsDocIds({
97
+ allDocIds,
98
+ sidebarFilePath: versionMetadata.sidebarFilePath,
99
+ versionMetadata,
100
+ });
101
+ return {
102
+ ...versionMetadata,
103
+ docs: (0, docs_1.addDocNavigation)({
104
+ docs,
105
+ sidebarsUtils,
106
+ }),
107
+ drafts,
108
+ sidebars,
109
+ };
110
+ }
111
+ async function loadVersion(params) {
82
112
  try {
83
- return await doLoadVersion();
113
+ return await doLoadVersion(params);
84
114
  }
85
115
  catch (err) {
86
- logger_1.default.error `Loading of version failed for version name=${versionMetadata.versionName}`;
116
+ // TODO use error cause (but need to refactor many tests)
117
+ logger_1.default.error `Loading of version failed for version name=${params.versionMetadata.versionName}`;
87
118
  throw err;
88
119
  }
89
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "3.8.1-canary-6342",
3
+ "version": "3.8.1-canary-6345",
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.1-canary-6342",
39
- "@docusaurus/logger": "3.8.1-canary-6342",
40
- "@docusaurus/mdx-loader": "3.8.1-canary-6342",
41
- "@docusaurus/module-type-aliases": "3.8.1-canary-6342",
42
- "@docusaurus/theme-common": "3.8.1-canary-6342",
43
- "@docusaurus/types": "3.8.1-canary-6342",
44
- "@docusaurus/utils": "3.8.1-canary-6342",
45
- "@docusaurus/utils-common": "3.8.1-canary-6342",
46
- "@docusaurus/utils-validation": "3.8.1-canary-6342",
38
+ "@docusaurus/core": "3.8.1-canary-6345",
39
+ "@docusaurus/logger": "3.8.1-canary-6345",
40
+ "@docusaurus/mdx-loader": "3.8.1-canary-6345",
41
+ "@docusaurus/module-type-aliases": "3.8.1-canary-6345",
42
+ "@docusaurus/theme-common": "3.8.1-canary-6345",
43
+ "@docusaurus/types": "3.8.1-canary-6345",
44
+ "@docusaurus/utils": "3.8.1-canary-6345",
45
+ "@docusaurus/utils-common": "3.8.1-canary-6345",
46
+ "@docusaurus/utils-validation": "3.8.1-canary-6345",
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": "42b5935e8d58a11d95a3fe89b28504bb63b1d6a5"
70
+ "gitHead": "3e07b014298c3b0936d84a6544eff9fa5d0966df"
71
71
  }
@@ -7,7 +7,7 @@
7
7
 
8
8
  import path from 'path';
9
9
  import _ from 'lodash';
10
- import {createSlugger} from '@docusaurus/utils';
10
+ import {aliasedSitePathToRelativePath, createSlugger} from '@docusaurus/utils';
11
11
  import {getTagsFile} from '@docusaurus/utils-validation';
12
12
  import logger from '@docusaurus/logger';
13
13
  import {
@@ -29,102 +29,151 @@ import type {
29
29
  import type {DocFile} from '../types';
30
30
  import type {LoadContext} from '@docusaurus/types';
31
31
 
32
- export async function loadVersion({
33
- context,
34
- options,
35
- versionMetadata,
36
- env,
37
- }: {
32
+ type LoadVersionParams = {
38
33
  context: LoadContext;
39
34
  options: PluginOptions;
40
35
  versionMetadata: VersionMetadata;
41
36
  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));
37
+ };
38
+
39
+ function ensureNoDuplicateDocId(docs: DocMetadataBase[]): void {
40
+ const duplicatesById = _.chain(docs)
41
+ .groupBy((d) => d.id)
42
+ .pickBy((group) => group.length > 1)
43
+ .value();
44
+
45
+ const duplicateIdEntries = Object.entries(duplicatesById);
46
+
47
+ if (duplicateIdEntries.length) {
48
+ const idMessages = duplicateIdEntries
49
+ .map(([id, duplicateDocs]) => {
50
+ return logger.interpolate`- code=${id} found in number=${
51
+ duplicateDocs.length
52
+ } docs:
53
+ - ${duplicateDocs
54
+ .map((d) => aliasedSitePathToRelativePath(d.source))
55
+ .join('\n - ')}`;
56
+ })
57
+ .join('\n\n');
58
+
59
+ const message = `The docs plugin found docs sharing the same id:
60
+ \n${idMessages}\n
61
+ Docs should have distinct ids.
62
+ In case of conflict, you can rename the docs file, or use the ${logger.code(
63
+ 'id',
64
+ )} front matter to assign an explicit distinct id to each doc.
65
+ `;
66
+
67
+ throw new Error(message);
70
68
  }
69
+ }
71
70
 
72
- async function doLoadVersion(): Promise<LoadedVersion> {
73
- const tagsFile = await getTagsFile({
74
- contentPaths: versionMetadata,
75
- tags: options.tags,
71
+ async function loadVersionDocsBase({
72
+ tagsFile,
73
+ context,
74
+ options,
75
+ versionMetadata,
76
+ env,
77
+ }: LoadVersionParams & {
78
+ tagsFile: TagsFile | null;
79
+ }): Promise<DocMetadataBase[]> {
80
+ const docFiles = await readVersionDocs(versionMetadata, options);
81
+ if (docFiles.length === 0) {
82
+ throw new Error(
83
+ `Docs version "${
84
+ versionMetadata.versionName
85
+ }" has no docs! At least one doc should exist at "${path.relative(
86
+ context.siteDir,
87
+ versionMetadata.contentPath,
88
+ )}".`,
89
+ );
90
+ }
91
+ function processVersionDoc(docFile: DocFile) {
92
+ return processDocMetadata({
93
+ docFile,
94
+ versionMetadata,
95
+ context,
96
+ options,
97
+ env,
98
+ tagsFile,
76
99
  });
100
+ }
101
+ const docs = await Promise.all(docFiles.map(processVersionDoc));
102
+ ensureNoDuplicateDocId(docs);
103
+ return docs;
104
+ }
77
105
 
78
- const docsBase: DocMetadataBase[] = await loadVersionDocsBase(tagsFile);
106
+ async function doLoadVersion({
107
+ context,
108
+ options,
109
+ versionMetadata,
110
+ env,
111
+ }: LoadVersionParams): Promise<LoadedVersion> {
112
+ const tagsFile = await getTagsFile({
113
+ contentPaths: versionMetadata,
114
+ tags: options.tags,
115
+ });
79
116
 
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);
117
+ const docsBase: DocMetadataBase[] = await loadVersionDocsBase({
118
+ tagsFile,
119
+ context,
120
+ options,
121
+ versionMetadata,
122
+ env,
123
+ });
84
124
 
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
- });
125
+ // TODO we only ever need draftIds in further code, not full draft items
126
+ // To simplify and prevent mistakes, avoid exposing draft
127
+ // replace draft=>draftIds in content loaded
128
+ const [drafts, docs] = _.partition(docsBase, (doc) => doc.draft);
97
129
 
98
- const sidebarsUtils = createSidebarsUtils(sidebars);
130
+ const sidebars = await loadSidebars(versionMetadata.sidebarFilePath, {
131
+ sidebarItemsGenerator: options.sidebarItemsGenerator,
132
+ numberPrefixParser: options.numberPrefixParser,
133
+ docs,
134
+ drafts,
135
+ version: versionMetadata,
136
+ sidebarOptions: {
137
+ sidebarCollapsed: options.sidebarCollapsed,
138
+ sidebarCollapsible: options.sidebarCollapsible,
139
+ },
140
+ categoryLabelSlugger: createSlugger(),
141
+ });
99
142
 
100
- const docsById = createDocsByIdIndex(docs);
101
- const allDocIds = Object.keys(docsById);
143
+ const sidebarsUtils = createSidebarsUtils(sidebars);
102
144
 
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
- });
145
+ const docsById = createDocsByIdIndex(docs);
146
+ const allDocIds = Object.keys(docsById);
112
147
 
113
- return {
114
- ...versionMetadata,
115
- docs: addDocNavigation({
116
- docs,
117
- sidebarsUtils,
118
- }),
119
- drafts,
120
- sidebars,
121
- };
122
- }
148
+ sidebarsUtils.checkLegacyVersionedSidebarNames({
149
+ sidebarFilePath: versionMetadata.sidebarFilePath as string,
150
+ versionMetadata,
151
+ });
152
+ sidebarsUtils.checkSidebarsDocIds({
153
+ allDocIds,
154
+ sidebarFilePath: versionMetadata.sidebarFilePath as string,
155
+ versionMetadata,
156
+ });
157
+
158
+ return {
159
+ ...versionMetadata,
160
+ docs: addDocNavigation({
161
+ docs,
162
+ sidebarsUtils,
163
+ }),
164
+ drafts,
165
+ sidebars,
166
+ };
167
+ }
123
168
 
169
+ export async function loadVersion(
170
+ params: LoadVersionParams,
171
+ ): Promise<LoadedVersion> {
124
172
  try {
125
- return await doLoadVersion();
173
+ return await doLoadVersion(params);
126
174
  } catch (err) {
127
- logger.error`Loading of version failed for version name=${versionMetadata.versionName}`;
175
+ // TODO use error cause (but need to refactor many tests)
176
+ logger.error`Loading of version failed for version name=${params.versionMetadata.versionName}`;
128
177
  throw err;
129
178
  }
130
179
  }