@docusaurus/plugin-content-docs 0.0.0-4360 → 0.0.0-4361
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/globalData.d.ts +3 -1
- package/lib/globalData.js +23 -1
- package/lib/sidebars/utils.d.ts +9 -0
- package/lib/sidebars/utils.js +37 -0
- package/lib/types.d.ts +8 -0
- package/package.json +9 -9
- package/src/globalData.ts +31 -0
- package/src/plugin-content-docs.d.ts +2 -1
- package/src/sidebars/utils.ts +57 -0
- package/src/types.ts +11 -0
package/lib/globalData.d.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
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 {
|
|
7
|
+
import type { Sidebars } from './sidebars/types';
|
|
8
|
+
import type { DocMetadata, GlobalDoc, LoadedVersion, GlobalVersion, GlobalSidebar } from './types';
|
|
8
9
|
export declare function toGlobalDataDoc(doc: DocMetadata): GlobalDoc;
|
|
10
|
+
export declare function toGlobalSidebars(sidebars: Sidebars, version: LoadedVersion): Record<string, GlobalSidebar>;
|
|
9
11
|
export declare function toGlobalDataVersion(version: LoadedVersion): GlobalVersion;
|
package/lib/globalData.js
CHANGED
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.toGlobalDataVersion = exports.toGlobalDataDoc = void 0;
|
|
9
|
+
exports.toGlobalDataVersion = exports.toGlobalSidebars = exports.toGlobalDataDoc = void 0;
|
|
10
|
+
const lodash_1 = require("lodash");
|
|
11
|
+
const utils_1 = require("@docusaurus/utils");
|
|
12
|
+
const utils_2 = require("./sidebars/utils");
|
|
10
13
|
function toGlobalDataDoc(doc) {
|
|
11
14
|
return {
|
|
12
15
|
id: doc.unversionedId,
|
|
@@ -15,6 +18,24 @@ function toGlobalDataDoc(doc) {
|
|
|
15
18
|
};
|
|
16
19
|
}
|
|
17
20
|
exports.toGlobalDataDoc = toGlobalDataDoc;
|
|
21
|
+
function toGlobalSidebars(sidebars, version) {
|
|
22
|
+
const { getFirstLink } = (0, utils_2.createSidebarsUtils)(sidebars);
|
|
23
|
+
return (0, lodash_1.mapValues)(sidebars, (sidebar, sidebarId) => {
|
|
24
|
+
const firstLink = getFirstLink(sidebarId);
|
|
25
|
+
if (!firstLink) {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
link: {
|
|
30
|
+
path: firstLink.type === 'generated-index'
|
|
31
|
+
? (0, utils_1.normalizeUrl)([version.versionPath, firstLink.slug])
|
|
32
|
+
: version.docs.find((doc) => doc.id === firstLink.id || doc.unversionedId === firstLink.id).permalink,
|
|
33
|
+
label: firstLink.label,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
exports.toGlobalSidebars = toGlobalSidebars;
|
|
18
39
|
function toGlobalDataVersion(version) {
|
|
19
40
|
return {
|
|
20
41
|
name: version.versionName,
|
|
@@ -23,6 +44,7 @@ function toGlobalDataVersion(version) {
|
|
|
23
44
|
path: version.versionPath,
|
|
24
45
|
mainDocId: version.mainDocId,
|
|
25
46
|
docs: version.docs.map(toGlobalDataDoc),
|
|
47
|
+
sidebars: toGlobalSidebars(version.sidebars, version),
|
|
26
48
|
};
|
|
27
49
|
}
|
|
28
50
|
exports.toGlobalDataVersion = toGlobalDataVersion;
|
package/lib/sidebars/utils.d.ts
CHANGED
|
@@ -27,6 +27,15 @@ export declare type SidebarsUtils = {
|
|
|
27
27
|
getDocNavigation: (unversionedId: string, versionedId: string) => SidebarNavigation;
|
|
28
28
|
getCategoryGeneratedIndexList: () => SidebarItemCategoryWithGeneratedIndex[];
|
|
29
29
|
getCategoryGeneratedIndexNavigation: (categoryGeneratedIndexPermalink: string) => SidebarNavigation;
|
|
30
|
+
getFirstLink: (sidebarId: string) => {
|
|
31
|
+
type: 'doc';
|
|
32
|
+
id: string;
|
|
33
|
+
label: string;
|
|
34
|
+
} | {
|
|
35
|
+
type: 'generated-index';
|
|
36
|
+
slug: string;
|
|
37
|
+
label: string;
|
|
38
|
+
} | undefined;
|
|
30
39
|
checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
|
|
31
40
|
};
|
|
32
41
|
export declare function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils;
|
package/lib/sidebars/utils.js
CHANGED
|
@@ -173,6 +173,42 @@ Available document ids are:
|
|
|
173
173
|
- ${(0, lodash_1.uniq)(validDocIds).sort().join('\n- ')}`);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
+
function getFirstLink(sidebar) {
|
|
177
|
+
var _a, _b, _c;
|
|
178
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
179
|
+
for (const item of sidebar) {
|
|
180
|
+
if (item.type === 'doc') {
|
|
181
|
+
return {
|
|
182
|
+
type: 'doc',
|
|
183
|
+
id: item.id,
|
|
184
|
+
label: (_a = item.label) !== null && _a !== void 0 ? _a : item.id,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
else if (item.type === 'category') {
|
|
188
|
+
if (((_b = item.link) === null || _b === void 0 ? void 0 : _b.type) === 'doc') {
|
|
189
|
+
return {
|
|
190
|
+
type: 'doc',
|
|
191
|
+
id: item.link.id,
|
|
192
|
+
label: item.label,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
else if (((_c = item.link) === null || _c === void 0 ? void 0 : _c.type) === 'generated-index') {
|
|
196
|
+
return {
|
|
197
|
+
type: 'generated-index',
|
|
198
|
+
slug: item.link.slug,
|
|
199
|
+
label: item.label,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
const firstSubItem = getFirstLink(item.items);
|
|
204
|
+
if (firstSubItem) {
|
|
205
|
+
return firstSubItem;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
176
212
|
return {
|
|
177
213
|
sidebars,
|
|
178
214
|
getFirstDocIdOfFirstSidebar,
|
|
@@ -181,6 +217,7 @@ Available document ids are:
|
|
|
181
217
|
getCategoryGeneratedIndexList,
|
|
182
218
|
getCategoryGeneratedIndexNavigation,
|
|
183
219
|
checkSidebarsDocIds,
|
|
220
|
+
getFirstLink: (id) => getFirstLink(sidebars[id]),
|
|
184
221
|
};
|
|
185
222
|
}
|
|
186
223
|
exports.createSidebarsUtils = createSidebarsUtils;
|
package/lib/types.d.ts
CHANGED
|
@@ -180,6 +180,14 @@ export declare type GlobalVersion = {
|
|
|
180
180
|
path: string;
|
|
181
181
|
mainDocId: string;
|
|
182
182
|
docs: GlobalDoc[];
|
|
183
|
+
sidebars?: Record<string, GlobalSidebar>;
|
|
184
|
+
};
|
|
185
|
+
export declare type GlobalSidebarLink = {
|
|
186
|
+
label: string;
|
|
187
|
+
path: string;
|
|
188
|
+
};
|
|
189
|
+
export declare type GlobalSidebar = {
|
|
190
|
+
link?: GlobalSidebarLink;
|
|
183
191
|
};
|
|
184
192
|
export declare type GlobalPluginData = {
|
|
185
193
|
path: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4361",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-content-docs.d.ts",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/core": "0.0.0-
|
|
22
|
-
"@docusaurus/logger": "0.0.0-
|
|
23
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
24
|
-
"@docusaurus/utils": "0.0.0-
|
|
25
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
21
|
+
"@docusaurus/core": "0.0.0-4361",
|
|
22
|
+
"@docusaurus/logger": "0.0.0-4361",
|
|
23
|
+
"@docusaurus/mdx-loader": "0.0.0-4361",
|
|
24
|
+
"@docusaurus/utils": "0.0.0-4361",
|
|
25
|
+
"@docusaurus/utils-validation": "0.0.0-4361",
|
|
26
26
|
"combine-promises": "^1.1.0",
|
|
27
27
|
"escape-string-regexp": "^4.0.0",
|
|
28
28
|
"fs-extra": "^10.0.0",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"webpack": "^5.61.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
42
|
-
"@docusaurus/types": "0.0.0-
|
|
41
|
+
"@docusaurus/module-type-aliases": "0.0.0-4361",
|
|
42
|
+
"@docusaurus/types": "0.0.0-4361",
|
|
43
43
|
"@types/js-yaml": "^4.0.0",
|
|
44
44
|
"@types/picomatch": "^2.2.1",
|
|
45
45
|
"commander": "^5.1.0",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=14"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "1bf29811c8ead0651a1e56a5c8e15dd3232056e5"
|
|
57
57
|
}
|
package/src/globalData.ts
CHANGED
|
@@ -5,11 +5,16 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import {mapValues} from 'lodash';
|
|
9
|
+
import {normalizeUrl} from '@docusaurus/utils';
|
|
10
|
+
import type {Sidebars} from './sidebars/types';
|
|
11
|
+
import {createSidebarsUtils} from './sidebars/utils';
|
|
8
12
|
import type {
|
|
9
13
|
DocMetadata,
|
|
10
14
|
GlobalDoc,
|
|
11
15
|
LoadedVersion,
|
|
12
16
|
GlobalVersion,
|
|
17
|
+
GlobalSidebar,
|
|
13
18
|
} from './types';
|
|
14
19
|
|
|
15
20
|
export function toGlobalDataDoc(doc: DocMetadata): GlobalDoc {
|
|
@@ -20,6 +25,31 @@ export function toGlobalDataDoc(doc: DocMetadata): GlobalDoc {
|
|
|
20
25
|
};
|
|
21
26
|
}
|
|
22
27
|
|
|
28
|
+
export function toGlobalSidebars(
|
|
29
|
+
sidebars: Sidebars,
|
|
30
|
+
version: LoadedVersion,
|
|
31
|
+
): Record<string, GlobalSidebar> {
|
|
32
|
+
const {getFirstLink} = createSidebarsUtils(sidebars);
|
|
33
|
+
return mapValues(sidebars, (sidebar, sidebarId) => {
|
|
34
|
+
const firstLink = getFirstLink(sidebarId);
|
|
35
|
+
if (!firstLink) {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
link: {
|
|
40
|
+
path:
|
|
41
|
+
firstLink.type === 'generated-index'
|
|
42
|
+
? normalizeUrl([version.versionPath, firstLink.slug])
|
|
43
|
+
: version.docs.find(
|
|
44
|
+
(doc) =>
|
|
45
|
+
doc.id === firstLink.id || doc.unversionedId === firstLink.id,
|
|
46
|
+
)!.permalink,
|
|
47
|
+
label: firstLink.label,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
23
53
|
export function toGlobalDataVersion(version: LoadedVersion): GlobalVersion {
|
|
24
54
|
return {
|
|
25
55
|
name: version.versionName,
|
|
@@ -28,5 +58,6 @@ export function toGlobalDataVersion(version: LoadedVersion): GlobalVersion {
|
|
|
28
58
|
path: version.versionPath,
|
|
29
59
|
mainDocId: version.mainDocId,
|
|
30
60
|
docs: version.docs.map(toGlobalDataDoc),
|
|
61
|
+
sidebars: toGlobalSidebars(version.sidebars, version),
|
|
31
62
|
};
|
|
32
63
|
}
|
|
@@ -11,9 +11,10 @@ declare module '@docusaurus/plugin-content-docs' {
|
|
|
11
11
|
export type VersionBanner = import('./types').VersionBanner;
|
|
12
12
|
type GlobalDataVersion = import('./types').GlobalVersion;
|
|
13
13
|
type GlobalDataDoc = import('./types').GlobalDoc;
|
|
14
|
+
type GlobalDataSidebar = import('./types').GlobalSidebar;
|
|
14
15
|
type VersionTag = import('./types').VersionTag;
|
|
15
16
|
|
|
16
|
-
export type {GlobalDataVersion, GlobalDataDoc};
|
|
17
|
+
export type {GlobalDataVersion, GlobalDataDoc, GlobalDataSidebar};
|
|
17
18
|
|
|
18
19
|
export type PropNavigationLink = {
|
|
19
20
|
readonly title: string;
|
package/src/sidebars/utils.ts
CHANGED
|
@@ -136,6 +136,18 @@ export type SidebarsUtils = {
|
|
|
136
136
|
getCategoryGeneratedIndexNavigation: (
|
|
137
137
|
categoryGeneratedIndexPermalink: string,
|
|
138
138
|
) => SidebarNavigation;
|
|
139
|
+
getFirstLink: (sidebarId: string) =>
|
|
140
|
+
| {
|
|
141
|
+
type: 'doc';
|
|
142
|
+
id: string;
|
|
143
|
+
label: string;
|
|
144
|
+
}
|
|
145
|
+
| {
|
|
146
|
+
type: 'generated-index';
|
|
147
|
+
slug: string;
|
|
148
|
+
label: string;
|
|
149
|
+
}
|
|
150
|
+
| undefined;
|
|
139
151
|
|
|
140
152
|
checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
|
|
141
153
|
};
|
|
@@ -264,6 +276,50 @@ Available document ids are:
|
|
|
264
276
|
}
|
|
265
277
|
}
|
|
266
278
|
|
|
279
|
+
function getFirstLink(sidebar: Sidebar):
|
|
280
|
+
| {
|
|
281
|
+
type: 'doc';
|
|
282
|
+
id: string;
|
|
283
|
+
label: string;
|
|
284
|
+
}
|
|
285
|
+
| {
|
|
286
|
+
type: 'generated-index';
|
|
287
|
+
slug: string;
|
|
288
|
+
label: string;
|
|
289
|
+
}
|
|
290
|
+
| undefined {
|
|
291
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
292
|
+
for (const item of sidebar) {
|
|
293
|
+
if (item.type === 'doc') {
|
|
294
|
+
return {
|
|
295
|
+
type: 'doc',
|
|
296
|
+
id: item.id,
|
|
297
|
+
label: item.label ?? item.id,
|
|
298
|
+
};
|
|
299
|
+
} else if (item.type === 'category') {
|
|
300
|
+
if (item.link?.type === 'doc') {
|
|
301
|
+
return {
|
|
302
|
+
type: 'doc',
|
|
303
|
+
id: item.link.id,
|
|
304
|
+
label: item.label,
|
|
305
|
+
};
|
|
306
|
+
} else if (item.link?.type === 'generated-index') {
|
|
307
|
+
return {
|
|
308
|
+
type: 'generated-index',
|
|
309
|
+
slug: item.link.slug,
|
|
310
|
+
label: item.label,
|
|
311
|
+
};
|
|
312
|
+
} else {
|
|
313
|
+
const firstSubItem = getFirstLink(item.items);
|
|
314
|
+
if (firstSubItem) {
|
|
315
|
+
return firstSubItem;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
|
|
267
323
|
return {
|
|
268
324
|
sidebars,
|
|
269
325
|
getFirstDocIdOfFirstSidebar,
|
|
@@ -272,6 +328,7 @@ Available document ids are:
|
|
|
272
328
|
getCategoryGeneratedIndexList,
|
|
273
329
|
getCategoryGeneratedIndexNavigation,
|
|
274
330
|
checkSidebarsDocIds,
|
|
331
|
+
getFirstLink: (id) => getFirstLink(sidebars[id]),
|
|
275
332
|
};
|
|
276
333
|
}
|
|
277
334
|
|
package/src/types.ts
CHANGED
|
@@ -216,6 +216,17 @@ export type GlobalVersion = {
|
|
|
216
216
|
path: string;
|
|
217
217
|
mainDocId: string; // home doc (if docs homepage configured), or first doc
|
|
218
218
|
docs: GlobalDoc[];
|
|
219
|
+
sidebars?: Record<string, GlobalSidebar>;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export type GlobalSidebarLink = {
|
|
223
|
+
label: string;
|
|
224
|
+
path: string;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
export type GlobalSidebar = {
|
|
228
|
+
link?: GlobalSidebarLink;
|
|
229
|
+
// ... we may add other things here later
|
|
219
230
|
};
|
|
220
231
|
|
|
221
232
|
export type GlobalPluginData = {
|