@docusaurus/plugin-content-docs 2.0.0-beta.15 → 2.0.0-beta.16
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/cli.d.ts +1 -1
- package/lib/cli.js +18 -14
- package/lib/client/docsClientUtils.js +2 -2
- package/lib/client/index.d.ts +13 -1
- package/lib/client/index.js +66 -1
- package/lib/docFrontMatter.js +1 -0
- package/lib/docs.d.ts +2 -1
- package/lib/docs.js +23 -22
- package/lib/globalData.js +3 -2
- package/lib/index.js +11 -6
- package/lib/lastUpdate.js +14 -27
- package/lib/numberPrefix.js +7 -6
- package/lib/options.js +5 -2
- package/lib/props.js +15 -10
- package/lib/routes.js +6 -4
- package/lib/server-export.d.ts +8 -0
- package/lib/server-export.js +23 -0
- package/lib/sidebars/generator.d.ts +1 -9
- package/lib/sidebars/generator.js +26 -50
- package/lib/sidebars/index.d.ts +2 -5
- package/lib/sidebars/index.js +35 -20
- package/lib/sidebars/normalization.d.ts +2 -3
- package/lib/sidebars/normalization.js +17 -39
- package/lib/sidebars/postProcessor.d.ts +8 -0
- package/lib/sidebars/postProcessor.js +72 -0
- package/lib/sidebars/processor.d.ts +2 -13
- package/lib/sidebars/processor.js +25 -33
- package/lib/sidebars/types.d.ts +44 -10
- package/lib/sidebars/utils.js +53 -61
- package/lib/sidebars/validation.d.ts +2 -3
- package/lib/sidebars/validation.js +25 -30
- package/lib/slug.js +6 -8
- package/lib/tags.js +3 -2
- package/lib/translations.js +18 -17
- package/lib/types.d.ts +3 -6
- package/lib/versions.d.ts +25 -1
- package/lib/versions.js +25 -29
- package/package.json +19 -18
- package/src/cli.ts +25 -16
- package/src/client/docsClientUtils.ts +2 -2
- package/src/client/index.ts +97 -1
- package/src/docFrontMatter.ts +1 -0
- package/src/docs.ts +25 -20
- package/src/globalData.ts +2 -2
- package/src/index.ts +17 -7
- package/src/lastUpdate.ts +12 -33
- package/src/numberPrefix.ts +7 -6
- package/src/options.ts +5 -2
- package/src/plugin-content-docs.d.ts +16 -60
- package/src/props.ts +17 -12
- package/src/routes.ts +6 -4
- package/src/server-export.ts +24 -0
- package/src/sidebars/README.md +9 -0
- package/src/sidebars/generator.ts +50 -94
- package/src/sidebars/index.ts +50 -32
- package/src/sidebars/normalization.ts +22 -50
- package/src/sidebars/postProcessor.ts +94 -0
- package/src/sidebars/processor.ts +37 -66
- package/src/sidebars/types.ts +68 -10
- package/src/sidebars/utils.ts +63 -68
- package/src/sidebars/validation.ts +53 -53
- package/src/slug.ts +9 -10
- package/src/tags.ts +2 -2
- package/src/translations.ts +19 -16
- package/src/types.ts +3 -10
- package/src/versions.ts +30 -34
- package/lib/client/globalDataHooks.d.ts +0 -19
- package/lib/client/globalDataHooks.js +0 -76
- package/src/client/globalDataHooks.ts +0 -107
package/src/sidebars/utils.ts
CHANGED
|
@@ -16,18 +16,17 @@ import type {
|
|
|
16
16
|
SidebarCategoriesShorthand,
|
|
17
17
|
SidebarItemConfig,
|
|
18
18
|
SidebarItemCategoryWithGeneratedIndex,
|
|
19
|
-
SidebarItemCategoryWithLink,
|
|
20
19
|
SidebarNavigationItem,
|
|
21
20
|
} from './types';
|
|
22
21
|
|
|
23
|
-
import
|
|
22
|
+
import _ from 'lodash';
|
|
24
23
|
import {getElementsAround, toMessageRelativeFilePath} from '@docusaurus/utils';
|
|
25
24
|
import type {DocMetadataBase, DocNavLink} from '../types';
|
|
26
25
|
|
|
27
26
|
export function isCategoriesShorthand(
|
|
28
27
|
item: SidebarItemConfig,
|
|
29
28
|
): item is SidebarCategoriesShorthand {
|
|
30
|
-
return typeof item
|
|
29
|
+
return typeof item === 'object' && !item.type;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
export function transformSidebarItems(
|
|
@@ -46,8 +45,11 @@ export function transformSidebarItems(
|
|
|
46
45
|
return sidebar.map(transformRecursive);
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Flatten sidebar items into a single flat array (containing categories/docs on
|
|
50
|
+
* the same level). Order matters (useful for next/prev nav), top categories
|
|
51
|
+
* appear before their child elements
|
|
52
|
+
*/
|
|
51
53
|
function flattenSidebarItems(items: SidebarItem[]): SidebarItem[] {
|
|
52
54
|
function flattenRecursive(item: SidebarItem): SidebarItem[] {
|
|
53
55
|
return item.type === 'category'
|
|
@@ -108,13 +110,13 @@ export function collectSidebarNavigation(
|
|
|
108
110
|
export function collectSidebarsDocIds(
|
|
109
111
|
sidebars: Sidebars,
|
|
110
112
|
): Record<string, string[]> {
|
|
111
|
-
return mapValues(sidebars, collectSidebarDocIds);
|
|
113
|
+
return _.mapValues(sidebars, collectSidebarDocIds);
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
export function collectSidebarsNavigations(
|
|
115
117
|
sidebars: Sidebars,
|
|
116
118
|
): Record<string, SidebarNavigationItem[]> {
|
|
117
|
-
return mapValues(sidebars, collectSidebarNavigation);
|
|
119
|
+
return _.mapValues(sidebars, collectSidebarNavigation);
|
|
118
120
|
}
|
|
119
121
|
|
|
120
122
|
export type SidebarNavigation = {
|
|
@@ -196,34 +198,33 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
|
|
|
196
198
|
sidebarName = getSidebarNameByDocId(docId);
|
|
197
199
|
}
|
|
198
200
|
|
|
199
|
-
if (sidebarName) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
201
|
+
if (!sidebarName) {
|
|
202
|
+
return emptySidebarNavigation();
|
|
203
|
+
}
|
|
204
|
+
if (!sidebarNameToNavigationItems[sidebarName]) {
|
|
205
|
+
throw new Error(
|
|
206
|
+
`Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`,
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
210
|
+
const currentItemIndex = navigationItems.findIndex((item) => {
|
|
211
|
+
if (item.type === 'doc') {
|
|
212
|
+
return item.id === docId;
|
|
204
213
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (item.type === 'doc') {
|
|
208
|
-
return item.id === docId;
|
|
209
|
-
}
|
|
210
|
-
if (item.type === 'category' && item.link.type === 'doc') {
|
|
211
|
-
return item.link.id === docId;
|
|
212
|
-
}
|
|
213
|
-
return false;
|
|
214
|
-
});
|
|
215
|
-
if (currentItemIndex === -1) {
|
|
216
|
-
return {sidebarName, next: undefined, previous: undefined};
|
|
214
|
+
if (item.type === 'category' && item.link.type === 'doc') {
|
|
215
|
+
return item.link.id === docId;
|
|
217
216
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
);
|
|
223
|
-
return {sidebarName, previous, next};
|
|
224
|
-
} else {
|
|
225
|
-
return emptySidebarNavigation();
|
|
217
|
+
return false;
|
|
218
|
+
});
|
|
219
|
+
if (currentItemIndex === -1) {
|
|
220
|
+
return {sidebarName, next: undefined, previous: undefined};
|
|
226
221
|
}
|
|
222
|
+
|
|
223
|
+
const {previous, next} = getElementsAround(
|
|
224
|
+
navigationItems,
|
|
225
|
+
currentItemIndex,
|
|
226
|
+
);
|
|
227
|
+
return {sidebarName, previous, next};
|
|
227
228
|
}
|
|
228
229
|
|
|
229
230
|
function getCategoryGeneratedIndexList(): SidebarItemCategoryWithGeneratedIndex[] {
|
|
@@ -237,8 +238,10 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
|
|
|
237
238
|
});
|
|
238
239
|
}
|
|
239
240
|
|
|
240
|
-
|
|
241
|
-
|
|
241
|
+
/**
|
|
242
|
+
* We identity the category generated index by its permalink (should be
|
|
243
|
+
* unique). More reliable than using object identity
|
|
244
|
+
*/
|
|
242
245
|
function getCategoryGeneratedIndexNavigation(
|
|
243
246
|
categoryGeneratedIndexPermalink: string,
|
|
244
247
|
): SidebarNavigation {
|
|
@@ -257,24 +260,23 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
|
|
|
257
260
|
navigationItems.find(isCurrentCategoryGeneratedIndexItem),
|
|
258
261
|
)?.[0];
|
|
259
262
|
|
|
260
|
-
if (sidebarName) {
|
|
261
|
-
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
262
|
-
const currentItemIndex = navigationItems.findIndex(
|
|
263
|
-
isCurrentCategoryGeneratedIndexItem,
|
|
264
|
-
);
|
|
265
|
-
const {previous, next} = getElementsAround(
|
|
266
|
-
navigationItems,
|
|
267
|
-
currentItemIndex,
|
|
268
|
-
);
|
|
269
|
-
return {sidebarName, previous, next};
|
|
270
|
-
} else {
|
|
263
|
+
if (!sidebarName) {
|
|
271
264
|
return emptySidebarNavigation();
|
|
272
265
|
}
|
|
266
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
267
|
+
const currentItemIndex = navigationItems.findIndex(
|
|
268
|
+
isCurrentCategoryGeneratedIndexItem,
|
|
269
|
+
);
|
|
270
|
+
const {previous, next} = getElementsAround(
|
|
271
|
+
navigationItems,
|
|
272
|
+
currentItemIndex,
|
|
273
|
+
);
|
|
274
|
+
return {sidebarName, previous, next};
|
|
273
275
|
}
|
|
274
276
|
|
|
275
277
|
function checkSidebarsDocIds(validDocIds: string[], sidebarFilePath: string) {
|
|
276
278
|
const allSidebarDocIds = Object.values(sidebarNameToDocIds).flat();
|
|
277
|
-
const invalidSidebarDocIds = difference(allSidebarDocIds, validDocIds);
|
|
279
|
+
const invalidSidebarDocIds = _.difference(allSidebarDocIds, validDocIds);
|
|
278
280
|
if (invalidSidebarDocIds.length > 0) {
|
|
279
281
|
throw new Error(
|
|
280
282
|
`Invalid sidebar file at "${toMessageRelativeFilePath(
|
|
@@ -284,7 +286,7 @@ These sidebar document ids do not exist:
|
|
|
284
286
|
- ${invalidSidebarDocIds.sort().join('\n- ')}
|
|
285
287
|
|
|
286
288
|
Available document ids are:
|
|
287
|
-
- ${uniq(validDocIds).sort().join('\n- ')}`,
|
|
289
|
+
- ${_.uniq(validDocIds).sort().join('\n- ')}`,
|
|
288
290
|
);
|
|
289
291
|
}
|
|
290
292
|
}
|
|
@@ -301,7 +303,6 @@ Available document ids are:
|
|
|
301
303
|
label: string;
|
|
302
304
|
}
|
|
303
305
|
| undefined {
|
|
304
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
305
306
|
for (const item of sidebar) {
|
|
306
307
|
if (item.type === 'doc') {
|
|
307
308
|
return {
|
|
@@ -322,11 +323,10 @@ Available document ids are:
|
|
|
322
323
|
slug: item.link.slug,
|
|
323
324
|
label: item.label,
|
|
324
325
|
};
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
326
|
+
}
|
|
327
|
+
const firstSubItem = getFirstLink(item.items);
|
|
328
|
+
if (firstSubItem) {
|
|
329
|
+
return firstSubItem;
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
332
|
}
|
|
@@ -371,18 +371,6 @@ export function toNavigationLink(
|
|
|
371
371
|
return doc;
|
|
372
372
|
}
|
|
373
373
|
|
|
374
|
-
function handleCategory(category: SidebarItemCategoryWithLink): DocNavLink {
|
|
375
|
-
if (category.link.type === 'doc') {
|
|
376
|
-
return toDocNavigationLink(getDocById(category.link.id));
|
|
377
|
-
} else if (category.link.type === 'generated-index') {
|
|
378
|
-
return {
|
|
379
|
-
title: category.label,
|
|
380
|
-
permalink: category.link.permalink,
|
|
381
|
-
};
|
|
382
|
-
} else {
|
|
383
|
-
throw new Error('unexpected category link type');
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
374
|
if (!navigationItem) {
|
|
387
375
|
return undefined;
|
|
388
376
|
}
|
|
@@ -390,8 +378,15 @@ export function toNavigationLink(
|
|
|
390
378
|
if (navigationItem.type === 'doc') {
|
|
391
379
|
return toDocNavigationLink(getDocById(navigationItem.id));
|
|
392
380
|
} else if (navigationItem.type === 'category') {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
381
|
+
if (navigationItem.link.type === 'doc') {
|
|
382
|
+
return toDocNavigationLink(getDocById(navigationItem.link.id));
|
|
383
|
+
} else if (navigationItem.link.type === 'generated-index') {
|
|
384
|
+
return {
|
|
385
|
+
title: navigationItem.label,
|
|
386
|
+
permalink: navigationItem.link.permalink,
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
throw new Error('unexpected category link type');
|
|
396
390
|
}
|
|
391
|
+
throw new Error('unexpected navigation item');
|
|
397
392
|
}
|
|
@@ -8,22 +8,24 @@
|
|
|
8
8
|
import {Joi, URISchema} from '@docusaurus/utils-validation';
|
|
9
9
|
import type {
|
|
10
10
|
SidebarItemConfig,
|
|
11
|
-
SidebarCategoriesShorthand,
|
|
12
11
|
SidebarItemBase,
|
|
13
12
|
SidebarItemAutogenerated,
|
|
14
13
|
SidebarItemDoc,
|
|
14
|
+
SidebarItemHtml,
|
|
15
15
|
SidebarItemLink,
|
|
16
16
|
SidebarItemCategoryConfig,
|
|
17
17
|
SidebarItemCategoryLink,
|
|
18
|
-
SidebarsConfig,
|
|
19
18
|
SidebarItemCategoryLinkDoc,
|
|
20
19
|
SidebarItemCategoryLinkGeneratedIndex,
|
|
20
|
+
NormalizedSidebars,
|
|
21
|
+
NormalizedSidebarItem,
|
|
22
|
+
NormalizedSidebarItemCategory,
|
|
23
|
+
CategoryMetadataFile,
|
|
21
24
|
} from './types';
|
|
22
|
-
import {isCategoriesShorthand} from './utils';
|
|
23
|
-
import type {CategoryMetadataFile} from './generator';
|
|
24
25
|
|
|
25
26
|
// NOTE: we don't add any default values during validation on purpose!
|
|
26
|
-
// Config types are exposed to users for typechecking and we use the same type
|
|
27
|
+
// Config types are exposed to users for typechecking and we use the same type
|
|
28
|
+
// in normalization
|
|
27
29
|
|
|
28
30
|
const sidebarItemBaseSchema = Joi.object<SidebarItemBase>({
|
|
29
31
|
className: Joi.string(),
|
|
@@ -35,7 +37,7 @@ const sidebarItemAutogeneratedSchema =
|
|
|
35
37
|
type: 'autogenerated',
|
|
36
38
|
dirName: Joi.string()
|
|
37
39
|
.required()
|
|
38
|
-
.pattern(/^[^/](
|
|
40
|
+
.pattern(/^[^/](?:.*[^/])?$/)
|
|
39
41
|
.message(
|
|
40
42
|
'"dirName" must be a dir path relative to the docs folder root, and should not start or end with slash',
|
|
41
43
|
),
|
|
@@ -47,6 +49,12 @@ const sidebarItemDocSchema = sidebarItemBaseSchema.append<SidebarItemDoc>({
|
|
|
47
49
|
label: Joi.string(),
|
|
48
50
|
});
|
|
49
51
|
|
|
52
|
+
const sidebarItemHtmlSchema = sidebarItemBaseSchema.append<SidebarItemHtml>({
|
|
53
|
+
type: 'html',
|
|
54
|
+
value: Joi.string().required(),
|
|
55
|
+
defaultStyle: Joi.boolean(),
|
|
56
|
+
});
|
|
57
|
+
|
|
50
58
|
const sidebarItemLinkSchema = sidebarItemBaseSchema.append<SidebarItemLink>({
|
|
51
59
|
type: 'link',
|
|
52
60
|
href: URISchema.required(),
|
|
@@ -56,6 +64,7 @@ const sidebarItemLinkSchema = sidebarItemBaseSchema.append<SidebarItemLink>({
|
|
|
56
64
|
});
|
|
57
65
|
|
|
58
66
|
const sidebarItemCategoryLinkSchema = Joi.object<SidebarItemCategoryLink>()
|
|
67
|
+
.allow(null)
|
|
59
68
|
.when('.type', {
|
|
60
69
|
switch: [
|
|
61
70
|
{
|
|
@@ -70,7 +79,8 @@ const sidebarItemCategoryLinkSchema = Joi.object<SidebarItemCategoryLink>()
|
|
|
70
79
|
then: Joi.object<SidebarItemCategoryLinkGeneratedIndex>({
|
|
71
80
|
type: 'generated-index',
|
|
72
81
|
slug: Joi.string().optional(),
|
|
73
|
-
//
|
|
82
|
+
// This one is not in the user config, only in the normalized version
|
|
83
|
+
// permalink: Joi.string().optional(),
|
|
74
84
|
title: Joi.string().optional(),
|
|
75
85
|
description: Joi.string().optional(),
|
|
76
86
|
image: Joi.string().optional(),
|
|
@@ -78,14 +88,13 @@ const sidebarItemCategoryLinkSchema = Joi.object<SidebarItemCategoryLink>()
|
|
|
78
88
|
}),
|
|
79
89
|
},
|
|
80
90
|
{
|
|
81
|
-
is: Joi.
|
|
91
|
+
is: Joi.required(),
|
|
82
92
|
then: Joi.forbidden().messages({
|
|
83
93
|
'any.unknown': 'Unknown sidebar category link type "{.type}".',
|
|
84
94
|
}),
|
|
85
95
|
},
|
|
86
96
|
],
|
|
87
|
-
})
|
|
88
|
-
.id('sidebarCategoryLinkSchema');
|
|
97
|
+
});
|
|
89
98
|
|
|
90
99
|
const sidebarItemCategorySchema =
|
|
91
100
|
sidebarItemBaseSchema.append<SidebarItemCategoryConfig>({
|
|
@@ -93,10 +102,11 @@ const sidebarItemCategorySchema =
|
|
|
93
102
|
label: Joi.string()
|
|
94
103
|
.required()
|
|
95
104
|
.messages({'any.unknown': '"label" must be a string'}),
|
|
96
|
-
// TODO: Joi doesn't allow mutual recursion. See https://github.com/sideway/joi/issues/2611
|
|
97
105
|
items: Joi.array()
|
|
98
106
|
.required()
|
|
99
|
-
.messages({'any.unknown': '"items" must be an array'}),
|
|
107
|
+
.messages({'any.unknown': '"items" must be an array'}),
|
|
108
|
+
// TODO: Joi doesn't allow mutual recursion. See https://github.com/sideway/joi/issues/2611
|
|
109
|
+
// .items(Joi.link('#sidebarItemSchema')),
|
|
100
110
|
link: sidebarItemCategoryLinkSchema,
|
|
101
111
|
collapsed: Joi.boolean().messages({
|
|
102
112
|
'any.unknown': '"collapsed" must be a boolean',
|
|
@@ -106,54 +116,44 @@ const sidebarItemCategorySchema =
|
|
|
106
116
|
}),
|
|
107
117
|
});
|
|
108
118
|
|
|
109
|
-
const sidebarItemSchema
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
119
|
+
const sidebarItemSchema = Joi.object<SidebarItemConfig>().when('.type', {
|
|
120
|
+
switch: [
|
|
121
|
+
{is: 'link', then: sidebarItemLinkSchema},
|
|
122
|
+
{
|
|
123
|
+
is: Joi.string().valid('doc', 'ref').required(),
|
|
124
|
+
then: sidebarItemDocSchema,
|
|
125
|
+
},
|
|
126
|
+
{is: 'html', then: sidebarItemHtmlSchema},
|
|
127
|
+
{is: 'autogenerated', then: sidebarItemAutogeneratedSchema},
|
|
128
|
+
{is: 'category', then: sidebarItemCategorySchema},
|
|
129
|
+
{
|
|
130
|
+
is: Joi.any().required(),
|
|
131
|
+
then: Joi.forbidden().messages({
|
|
132
|
+
'any.unknown': 'Unknown sidebar item type "{.type}".',
|
|
133
|
+
}),
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
});
|
|
137
|
+
// .id('sidebarItemSchema');
|
|
128
138
|
|
|
129
|
-
function validateSidebarItem(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
139
|
+
function validateSidebarItem(
|
|
140
|
+
item: unknown,
|
|
141
|
+
): asserts item is NormalizedSidebarItem {
|
|
133
142
|
// TODO: remove once with proper Joi support
|
|
134
|
-
// Because we can't use Joi to validate nested items (see above), we do it
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
category.forEach(validateSidebarItem),
|
|
138
|
-
);
|
|
139
|
-
} else {
|
|
140
|
-
Joi.assert(item, sidebarItemSchema);
|
|
143
|
+
// Because we can't use Joi to validate nested items (see above), we do it
|
|
144
|
+
// manually
|
|
145
|
+
Joi.assert(item, sidebarItemSchema);
|
|
141
146
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
147
|
+
if ((item as NormalizedSidebarItemCategory).type === 'category') {
|
|
148
|
+
(item as NormalizedSidebarItemCategory).items.forEach(validateSidebarItem);
|
|
145
149
|
}
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
export function validateSidebars(
|
|
149
|
-
sidebars: unknown
|
|
150
|
-
): asserts sidebars is
|
|
151
|
-
Object.values(sidebars as
|
|
152
|
-
|
|
153
|
-
sidebar.forEach(validateSidebarItem);
|
|
154
|
-
} else {
|
|
155
|
-
validateSidebarItem(sidebar);
|
|
156
|
-
}
|
|
153
|
+
sidebars: Record<string, unknown>,
|
|
154
|
+
): asserts sidebars is NormalizedSidebars {
|
|
155
|
+
Object.values(sidebars as NormalizedSidebars).forEach((sidebar) => {
|
|
156
|
+
sidebar.forEach(validateSidebarItem);
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
|
package/src/slug.ts
CHANGED
|
@@ -48,17 +48,16 @@ export default function getSlug({
|
|
|
48
48
|
function computeSlug(): string {
|
|
49
49
|
if (frontMatterSlug?.startsWith('/')) {
|
|
50
50
|
return frontMatterSlug;
|
|
51
|
-
} else {
|
|
52
|
-
const dirNameSlug = getDirNameSlug();
|
|
53
|
-
if (
|
|
54
|
-
!frontMatterSlug &&
|
|
55
|
-
isCategoryIndex(toCategoryIndexMatcherParam({source, sourceDirName}))
|
|
56
|
-
) {
|
|
57
|
-
return dirNameSlug;
|
|
58
|
-
}
|
|
59
|
-
const baseSlug = frontMatterSlug || baseID;
|
|
60
|
-
return resolvePathname(baseSlug, getDirNameSlug());
|
|
61
51
|
}
|
|
52
|
+
const dirNameSlug = getDirNameSlug();
|
|
53
|
+
if (
|
|
54
|
+
!frontMatterSlug &&
|
|
55
|
+
isCategoryIndex(toCategoryIndexMatcherParam({source, sourceDirName}))
|
|
56
|
+
) {
|
|
57
|
+
return dirNameSlug;
|
|
58
|
+
}
|
|
59
|
+
const baseSlug = frontMatterSlug || baseID;
|
|
60
|
+
return resolvePathname(baseSlug, getDirNameSlug());
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
function ensureValidSlug(slug: string): string {
|
package/src/tags.ts
CHANGED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
import {groupTaggedItems} from '@docusaurus/utils';
|
|
9
9
|
import type {VersionTags, DocMetadata} from './types';
|
|
10
|
-
import
|
|
10
|
+
import _ from 'lodash';
|
|
11
11
|
|
|
12
12
|
export function getVersionTags(docs: DocMetadata[]): VersionTags {
|
|
13
13
|
const groups = groupTaggedItems(docs, (doc) => doc.tags);
|
|
14
|
-
return mapValues(groups, (group) => ({
|
|
14
|
+
return _.mapValues(groups, (group) => ({
|
|
15
15
|
name: group.tag.label,
|
|
16
16
|
docIds: group.items.map((item) => item.id),
|
|
17
17
|
permalink: group.tag.permalink,
|
package/src/translations.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type {
|
|
|
13
13
|
Sidebars,
|
|
14
14
|
} from './sidebars/types';
|
|
15
15
|
|
|
16
|
-
import
|
|
16
|
+
import _ from 'lodash';
|
|
17
17
|
import {
|
|
18
18
|
collectSidebarCategories,
|
|
19
19
|
transformSidebarItems,
|
|
@@ -31,11 +31,10 @@ import {CURRENT_VERSION_NAME} from './constants';
|
|
|
31
31
|
function getVersionFileName(versionName: string): string {
|
|
32
32
|
if (versionName === CURRENT_VERSION_NAME) {
|
|
33
33
|
return versionName;
|
|
34
|
-
} else {
|
|
35
|
-
// I don't like this "version-" prefix,
|
|
36
|
-
// but it's for consistency with site/versioned_docs
|
|
37
|
-
return `version-${versionName}`;
|
|
38
34
|
}
|
|
35
|
+
// I don't like this "version-" prefix,
|
|
36
|
+
// but it's for consistency with site/versioned_docs
|
|
37
|
+
return `version-${versionName}`;
|
|
39
38
|
}
|
|
40
39
|
|
|
41
40
|
// TODO legacy, the sidebar name is like "version-2.0.0-alpha.66/docs"
|
|
@@ -68,7 +67,8 @@ function getDocTranslations(doc: DocMetadata): TranslationFileContent {
|
|
|
68
67
|
? {
|
|
69
68
|
[`${doc.unversionedId}.sidebar_label`]: {
|
|
70
69
|
message: doc.sidebar_label,
|
|
71
|
-
description:
|
|
70
|
+
description:
|
|
71
|
+
`The sidebar label for doc with id=${doc.unversionedId}`,
|
|
72
72
|
},
|
|
73
73
|
}
|
|
74
74
|
: undefined),
|
|
@@ -146,13 +146,15 @@ function getSidebarTranslationFileContent(
|
|
|
146
146
|
);
|
|
147
147
|
|
|
148
148
|
const links = collectSidebarLinks(sidebar);
|
|
149
|
-
const linksContent: TranslationFileContent =
|
|
150
|
-
.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
149
|
+
const linksContent: TranslationFileContent = Object.fromEntries(
|
|
150
|
+
links.map((link) => [
|
|
151
|
+
`sidebar.${sidebarName}.link.${link.label}`,
|
|
152
|
+
{
|
|
153
|
+
message: link.label,
|
|
154
|
+
description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
|
|
155
|
+
},
|
|
156
|
+
]),
|
|
157
|
+
);
|
|
156
158
|
|
|
157
159
|
return mergeTranslations([categoryContent, linksContent]);
|
|
158
160
|
}
|
|
@@ -230,7 +232,7 @@ function translateSidebars(
|
|
|
230
232
|
version: LoadedVersion,
|
|
231
233
|
sidebarsTranslations: TranslationFileContent,
|
|
232
234
|
): Sidebars {
|
|
233
|
-
return mapValues(version.sidebars, (sidebar, sidebarName) =>
|
|
235
|
+
return _.mapValues(version.sidebars, (sidebar, sidebarName) =>
|
|
234
236
|
translateSidebar({
|
|
235
237
|
sidebar,
|
|
236
238
|
sidebarName: getNormalizedSidebarName({
|
|
@@ -253,7 +255,8 @@ function getVersionTranslationFiles(version: LoadedVersion): TranslationFiles {
|
|
|
253
255
|
const sidebarsTranslations: TranslationFileContent =
|
|
254
256
|
getSidebarsTranslations(version);
|
|
255
257
|
|
|
256
|
-
// const docsTranslations: TranslationFileContent =
|
|
258
|
+
// const docsTranslations: TranslationFileContent =
|
|
259
|
+
// getDocsTranslations(version);
|
|
257
260
|
|
|
258
261
|
return [
|
|
259
262
|
{
|
|
@@ -301,7 +304,7 @@ export function translateLoadedContent(
|
|
|
301
304
|
loadedContent: LoadedContent,
|
|
302
305
|
translationFiles: TranslationFile[],
|
|
303
306
|
): LoadedContent {
|
|
304
|
-
const translationFilesMap: Record<string, TranslationFile> = keyBy(
|
|
307
|
+
const translationFilesMap: Record<string, TranslationFile> = _.keyBy(
|
|
305
308
|
translationFiles,
|
|
306
309
|
(f) => f.path,
|
|
307
310
|
);
|
package/src/types.ts
CHANGED
|
@@ -8,15 +8,12 @@
|
|
|
8
8
|
/// <reference types="@docusaurus/module-type-aliases" />
|
|
9
9
|
|
|
10
10
|
import type {Sidebars} from './sidebars/types';
|
|
11
|
-
import type {Tag, FrontMatterTag
|
|
11
|
+
import type {Tag, FrontMatterTag} from '@docusaurus/utils';
|
|
12
12
|
import type {
|
|
13
13
|
BrokenMarkdownLink as IBrokenMarkdownLink,
|
|
14
14
|
ContentPaths,
|
|
15
15
|
} from '@docusaurus/utils/lib/markdownLinks';
|
|
16
|
-
import type {
|
|
17
|
-
VersionBanner,
|
|
18
|
-
SidebarOptions,
|
|
19
|
-
} from '@docusaurus/plugin-content-docs';
|
|
16
|
+
import type {VersionBanner} from '@docusaurus/plugin-content-docs';
|
|
20
17
|
|
|
21
18
|
export type DocFile = {
|
|
22
19
|
contentPath: string; // /!\ may be localized
|
|
@@ -41,11 +38,6 @@ export type VersionMetadata = ContentPaths & {
|
|
|
41
38
|
routePriority: number | undefined; // -1 for the latest docs
|
|
42
39
|
};
|
|
43
40
|
|
|
44
|
-
export type NormalizeSidebarsParams = SidebarOptions & {
|
|
45
|
-
version: VersionMetadata;
|
|
46
|
-
categoryLabelSlugger: Slugger;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
41
|
export type LastUpdateData = {
|
|
50
42
|
lastUpdatedAt?: number;
|
|
51
43
|
formattedLastUpdatedAt?: string;
|
|
@@ -66,6 +58,7 @@ export type DocFrontMatter = {
|
|
|
66
58
|
sidebar_label?: string;
|
|
67
59
|
sidebar_position?: number;
|
|
68
60
|
sidebar_class_name?: string;
|
|
61
|
+
sidebar_custom_props?: Record<string, unknown>;
|
|
69
62
|
displayed_sidebar?: string | null;
|
|
70
63
|
pagination_label?: string;
|
|
71
64
|
custom_edit_url?: string | null;
|