@docusaurus/plugin-content-docs 0.0.0-4543 → 0.0.0-4548
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.js +2 -1
- package/lib/sidebars/generator.js +6 -7
- package/lib/sidebars/index.d.ts +3 -6
- package/lib/sidebars/index.js +8 -18
- package/lib/sidebars/normalization.d.ts +2 -3
- package/lib/sidebars/normalization.js +12 -32
- package/lib/sidebars/postProcessor.d.ts +8 -0
- package/lib/sidebars/postProcessor.js +71 -0
- package/lib/sidebars/processor.d.ts +2 -14
- package/lib/sidebars/processor.js +17 -55
- package/lib/sidebars/types.d.ts +22 -4
- package/lib/sidebars/validation.d.ts +2 -2
- package/lib/sidebars/validation.js +12 -27
- package/lib/types.d.ts +2 -6
- package/package.json +9 -9
- package/src/cli.ts +3 -2
- package/src/sidebars/README.md +9 -0
- package/src/sidebars/generator.ts +25 -22
- package/src/sidebars/index.ts +15 -31
- package/src/sidebars/normalization.ts +12 -46
- package/src/sidebars/postProcessor.ts +94 -0
- package/src/sidebars/processor.ts +26 -90
- package/src/sidebars/types.ts +30 -6
- package/src/sidebars/validation.ts +38 -50
- package/src/types.ts +2 -10
package/src/sidebars/types.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
SidebarOptions,
|
|
13
13
|
CategoryIndexMatcher,
|
|
14
14
|
} from '@docusaurus/plugin-content-docs';
|
|
15
|
+
import type {Slugger} from '@docusaurus/utils';
|
|
15
16
|
|
|
16
17
|
// Makes all properties visible when hovering over the type
|
|
17
18
|
type Expand<T extends Record<string, unknown>> = {[P in keyof T]: T[P]};
|
|
@@ -107,9 +108,9 @@ export type SidebarsConfig = {
|
|
|
107
108
|
|
|
108
109
|
// Normalized but still has 'autogenerated', which will be handled in processing
|
|
109
110
|
export type NormalizedSidebarItemCategory = Expand<
|
|
110
|
-
SidebarItemCategoryBase & {
|
|
111
|
+
Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
111
112
|
items: NormalizedSidebarItem[];
|
|
112
|
-
link?:
|
|
113
|
+
link?: SidebarItemCategoryLinkConfig;
|
|
113
114
|
}
|
|
114
115
|
>;
|
|
115
116
|
|
|
@@ -125,6 +126,22 @@ export type NormalizedSidebars = {
|
|
|
125
126
|
[sidebarId: string]: NormalizedSidebar;
|
|
126
127
|
};
|
|
127
128
|
|
|
129
|
+
export type ProcessedSidebarItemCategory = Expand<
|
|
130
|
+
Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
131
|
+
items: ProcessedSidebarItem[];
|
|
132
|
+
link?: SidebarItemCategoryLinkConfig;
|
|
133
|
+
}
|
|
134
|
+
>;
|
|
135
|
+
export type ProcessedSidebarItem =
|
|
136
|
+
| SidebarItemDoc
|
|
137
|
+
| SidebarItemHtml
|
|
138
|
+
| SidebarItemLink
|
|
139
|
+
| ProcessedSidebarItemCategory;
|
|
140
|
+
export type ProcessedSidebar = ProcessedSidebarItem[];
|
|
141
|
+
export type ProcessedSidebars = {
|
|
142
|
+
[sidebarId: string]: ProcessedSidebar;
|
|
143
|
+
};
|
|
144
|
+
|
|
128
145
|
export type SidebarItemCategory = Expand<
|
|
129
146
|
SidebarItemCategoryBase & {
|
|
130
147
|
items: SidebarItem[];
|
|
@@ -230,9 +247,7 @@ export type SidebarItemsGeneratorArgs = {
|
|
|
230
247
|
};
|
|
231
248
|
export type SidebarItemsGenerator = (
|
|
232
249
|
generatorArgs: SidebarItemsGeneratorArgs,
|
|
233
|
-
) =>
|
|
234
|
-
Promise<SidebarItem[]>;
|
|
235
|
-
// Promise<SidebarItemConfig[]>;
|
|
250
|
+
) => Promise<NormalizedSidebar>;
|
|
236
251
|
|
|
237
252
|
// Also inject the default generator to conveniently wrap/enhance/sort the
|
|
238
253
|
// default sidebar gen logic
|
|
@@ -242,4 +257,13 @@ export type SidebarItemsGeneratorOptionArgs = {
|
|
|
242
257
|
} & SidebarItemsGeneratorArgs;
|
|
243
258
|
export type SidebarItemsGeneratorOption = (
|
|
244
259
|
generatorArgs: SidebarItemsGeneratorOptionArgs,
|
|
245
|
-
) => Promise<
|
|
260
|
+
) => Promise<NormalizedSidebarItem[]>;
|
|
261
|
+
|
|
262
|
+
export type SidebarProcessorParams = {
|
|
263
|
+
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
264
|
+
numberPrefixParser: NumberPrefixParser;
|
|
265
|
+
docs: DocMetadataBase[];
|
|
266
|
+
version: VersionMetadata;
|
|
267
|
+
categoryLabelSlugger: Slugger;
|
|
268
|
+
sidebarOptions: SidebarOptions;
|
|
269
|
+
};
|
|
@@ -8,7 +8,6 @@
|
|
|
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,
|
|
@@ -16,12 +15,13 @@ import type {
|
|
|
16
15
|
SidebarItemLink,
|
|
17
16
|
SidebarItemCategoryConfig,
|
|
18
17
|
SidebarItemCategoryLink,
|
|
19
|
-
SidebarsConfig,
|
|
20
18
|
SidebarItemCategoryLinkDoc,
|
|
21
19
|
SidebarItemCategoryLinkGeneratedIndex,
|
|
20
|
+
NormalizedSidebars,
|
|
21
|
+
NormalizedSidebarItem,
|
|
22
|
+
NormalizedSidebarItemCategory,
|
|
22
23
|
CategoryMetadataFile,
|
|
23
24
|
} from './types';
|
|
24
|
-
import {isCategoriesShorthand} from './utils';
|
|
25
25
|
|
|
26
26
|
// NOTE: we don't add any default values during validation on purpose!
|
|
27
27
|
// Config types are exposed to users for typechecking and we use the same type
|
|
@@ -52,7 +52,7 @@ const sidebarItemDocSchema = sidebarItemBaseSchema.append<SidebarItemDoc>({
|
|
|
52
52
|
const sidebarItemHtmlSchema = sidebarItemBaseSchema.append<SidebarItemHtml>({
|
|
53
53
|
type: 'html',
|
|
54
54
|
value: Joi.string().required(),
|
|
55
|
-
defaultStyle: Joi.boolean()
|
|
55
|
+
defaultStyle: Joi.boolean(),
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
const sidebarItemLinkSchema = sidebarItemBaseSchema.append<SidebarItemLink>({
|
|
@@ -88,14 +88,13 @@ const sidebarItemCategoryLinkSchema = Joi.object<SidebarItemCategoryLink>()
|
|
|
88
88
|
}),
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
|
-
is: Joi.
|
|
91
|
+
is: Joi.required(),
|
|
92
92
|
then: Joi.forbidden().messages({
|
|
93
93
|
'any.unknown': 'Unknown sidebar category link type "{.type}".',
|
|
94
94
|
}),
|
|
95
95
|
},
|
|
96
96
|
],
|
|
97
|
-
})
|
|
98
|
-
.id('sidebarCategoryLinkSchema');
|
|
97
|
+
});
|
|
99
98
|
|
|
100
99
|
const sidebarItemCategorySchema =
|
|
101
100
|
sidebarItemBaseSchema.append<SidebarItemCategoryConfig>({
|
|
@@ -103,10 +102,11 @@ const sidebarItemCategorySchema =
|
|
|
103
102
|
label: Joi.string()
|
|
104
103
|
.required()
|
|
105
104
|
.messages({'any.unknown': '"label" must be a string'}),
|
|
106
|
-
// TODO: Joi doesn't allow mutual recursion. See https://github.com/sideway/joi/issues/2611
|
|
107
105
|
items: Joi.array()
|
|
108
106
|
.required()
|
|
109
|
-
.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')),
|
|
110
110
|
link: sidebarItemCategoryLinkSchema,
|
|
111
111
|
collapsed: Joi.boolean().messages({
|
|
112
112
|
'any.unknown': '"collapsed" must be a boolean',
|
|
@@ -116,56 +116,44 @@ const sidebarItemCategorySchema =
|
|
|
116
116
|
}),
|
|
117
117
|
});
|
|
118
118
|
|
|
119
|
-
const sidebarItemSchema
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
.id('sidebarItemSchema');
|
|
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');
|
|
139
138
|
|
|
140
|
-
function validateSidebarItem(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
139
|
+
function validateSidebarItem(
|
|
140
|
+
item: unknown,
|
|
141
|
+
): asserts item is NormalizedSidebarItem {
|
|
144
142
|
// TODO: remove once with proper Joi support
|
|
145
143
|
// Because we can't use Joi to validate nested items (see above), we do it
|
|
146
144
|
// manually
|
|
147
|
-
|
|
148
|
-
Object.values(item as SidebarCategoriesShorthand).forEach((category) =>
|
|
149
|
-
category.forEach(validateSidebarItem),
|
|
150
|
-
);
|
|
151
|
-
} else {
|
|
152
|
-
Joi.assert(item, sidebarItemSchema);
|
|
145
|
+
Joi.assert(item, sidebarItemSchema);
|
|
153
146
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
147
|
+
if ((item as NormalizedSidebarItemCategory).type === 'category') {
|
|
148
|
+
(item as NormalizedSidebarItemCategory).items.forEach(validateSidebarItem);
|
|
157
149
|
}
|
|
158
150
|
}
|
|
159
151
|
|
|
160
152
|
export function validateSidebars(
|
|
161
|
-
sidebars: unknown
|
|
162
|
-
): asserts sidebars is
|
|
163
|
-
Object.values(sidebars as
|
|
164
|
-
|
|
165
|
-
sidebar.forEach(validateSidebarItem);
|
|
166
|
-
} else {
|
|
167
|
-
validateSidebarItem(sidebar);
|
|
168
|
-
}
|
|
153
|
+
sidebars: Record<string, unknown>,
|
|
154
|
+
): asserts sidebars is NormalizedSidebars {
|
|
155
|
+
Object.values(sidebars as NormalizedSidebars).forEach((sidebar) => {
|
|
156
|
+
sidebar.forEach(validateSidebarItem);
|
|
169
157
|
});
|
|
170
158
|
}
|
|
171
159
|
|
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;
|