@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/lib/sidebars/types.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import type { Optional, Required } from 'utility-types';
|
|
8
8
|
import type { DocMetadataBase, VersionMetadata } from '../types';
|
|
9
9
|
import type { NumberPrefixParser, SidebarOptions, CategoryIndexMatcher } from '@docusaurus/plugin-content-docs';
|
|
10
|
+
import type { Slugger } from '@docusaurus/utils';
|
|
10
11
|
declare type Expand<T extends Record<string, unknown>> = {
|
|
11
12
|
[P in keyof T]: T[P];
|
|
12
13
|
};
|
|
@@ -19,6 +20,11 @@ export declare type SidebarItemDoc = SidebarItemBase & {
|
|
|
19
20
|
label?: string;
|
|
20
21
|
id: string;
|
|
21
22
|
};
|
|
23
|
+
export declare type SidebarItemHtml = SidebarItemBase & {
|
|
24
|
+
type: 'html';
|
|
25
|
+
value: string;
|
|
26
|
+
defaultStyle?: boolean;
|
|
27
|
+
};
|
|
22
28
|
export declare type SidebarItemLink = SidebarItemBase & {
|
|
23
29
|
type: 'link';
|
|
24
30
|
href: string;
|
|
@@ -58,26 +64,35 @@ export declare type SidebarItemCategoryLinkGeneratedIndex = {
|
|
|
58
64
|
export declare type SidebarItemCategoryLinkConfig = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndexConfig;
|
|
59
65
|
export declare type SidebarItemCategoryLink = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndex;
|
|
60
66
|
export declare type SidebarItemCategoryConfig = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
61
|
-
items: SidebarItemConfig[];
|
|
67
|
+
items: SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
62
68
|
link?: SidebarItemCategoryLinkConfig;
|
|
63
69
|
}>;
|
|
64
70
|
export declare type SidebarCategoriesShorthand = {
|
|
65
|
-
[sidebarCategory: string]: SidebarItemConfig[];
|
|
71
|
+
[sidebarCategory: string]: SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
66
72
|
};
|
|
67
|
-
export declare type SidebarItemConfig = SidebarItemDoc | SidebarItemLink | SidebarItemAutogenerated | SidebarItemCategoryConfig | string | SidebarCategoriesShorthand;
|
|
73
|
+
export declare type SidebarItemConfig = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | SidebarItemAutogenerated | SidebarItemCategoryConfig | string | SidebarCategoriesShorthand;
|
|
68
74
|
export declare type SidebarConfig = SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
69
75
|
export declare type SidebarsConfig = {
|
|
70
76
|
[sidebarId: string]: SidebarConfig;
|
|
71
77
|
};
|
|
72
|
-
export declare type NormalizedSidebarItemCategory = Expand<SidebarItemCategoryBase & {
|
|
78
|
+
export declare type NormalizedSidebarItemCategory = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
73
79
|
items: NormalizedSidebarItem[];
|
|
74
|
-
link?:
|
|
80
|
+
link?: SidebarItemCategoryLinkConfig;
|
|
75
81
|
}>;
|
|
76
|
-
export declare type NormalizedSidebarItem = SidebarItemDoc | SidebarItemLink | NormalizedSidebarItemCategory | SidebarItemAutogenerated;
|
|
82
|
+
export declare type NormalizedSidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | NormalizedSidebarItemCategory | SidebarItemAutogenerated;
|
|
77
83
|
export declare type NormalizedSidebar = NormalizedSidebarItem[];
|
|
78
84
|
export declare type NormalizedSidebars = {
|
|
79
85
|
[sidebarId: string]: NormalizedSidebar;
|
|
80
86
|
};
|
|
87
|
+
export declare type ProcessedSidebarItemCategory = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
88
|
+
items: ProcessedSidebarItem[];
|
|
89
|
+
link?: SidebarItemCategoryLinkConfig;
|
|
90
|
+
}>;
|
|
91
|
+
export declare type ProcessedSidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | ProcessedSidebarItemCategory;
|
|
92
|
+
export declare type ProcessedSidebar = ProcessedSidebarItem[];
|
|
93
|
+
export declare type ProcessedSidebars = {
|
|
94
|
+
[sidebarId: string]: ProcessedSidebar;
|
|
95
|
+
};
|
|
81
96
|
export declare type SidebarItemCategory = Expand<SidebarItemCategoryBase & {
|
|
82
97
|
items: SidebarItem[];
|
|
83
98
|
link?: SidebarItemCategoryLink;
|
|
@@ -86,7 +101,7 @@ export declare type SidebarItemCategoryWithLink = Required<SidebarItemCategory,
|
|
|
86
101
|
export declare type SidebarItemCategoryWithGeneratedIndex = SidebarItemCategoryWithLink & {
|
|
87
102
|
link: SidebarItemCategoryLinkGeneratedIndex;
|
|
88
103
|
};
|
|
89
|
-
export declare type SidebarItem = SidebarItemDoc | SidebarItemLink | SidebarItemCategory;
|
|
104
|
+
export declare type SidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | SidebarItemCategory;
|
|
90
105
|
export declare type SidebarNavigationItem = SidebarItemDoc | SidebarItemCategoryWithLink;
|
|
91
106
|
export declare type Sidebar = SidebarItem[];
|
|
92
107
|
export declare type SidebarItemType = SidebarItem['type'];
|
|
@@ -100,11 +115,13 @@ export declare type PropSidebarItemCategory = Expand<SidebarItemCategoryBase & {
|
|
|
100
115
|
export declare type PropSidebarItemLink = SidebarItemLink & {
|
|
101
116
|
docId?: string;
|
|
102
117
|
};
|
|
103
|
-
export declare type
|
|
118
|
+
export declare type PropSidebarItemHtml = SidebarItemHtml;
|
|
119
|
+
export declare type PropSidebarItem = PropSidebarItemLink | PropSidebarItemCategory | PropSidebarItemHtml;
|
|
104
120
|
export declare type PropSidebar = PropSidebarItem[];
|
|
105
121
|
export declare type PropSidebars = {
|
|
106
122
|
[sidebarId: string]: PropSidebar;
|
|
107
123
|
};
|
|
124
|
+
export declare type PropSidebarBreadcrumbsItem = PropSidebarItemLink | PropSidebarItemCategory;
|
|
108
125
|
export declare type PropVersionDoc = {
|
|
109
126
|
id: string;
|
|
110
127
|
title: string;
|
|
@@ -114,6 +131,14 @@ export declare type PropVersionDoc = {
|
|
|
114
131
|
export declare type PropVersionDocs = {
|
|
115
132
|
[docId: string]: PropVersionDoc;
|
|
116
133
|
};
|
|
134
|
+
export declare type CategoryMetadataFile = {
|
|
135
|
+
label?: string;
|
|
136
|
+
position?: number;
|
|
137
|
+
collapsed?: boolean;
|
|
138
|
+
collapsible?: boolean;
|
|
139
|
+
className?: string;
|
|
140
|
+
link?: SidebarItemCategoryLinkConfig | null;
|
|
141
|
+
};
|
|
117
142
|
export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'unversionedId' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
|
|
118
143
|
export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
|
|
119
144
|
export declare type SidebarItemsGeneratorArgs = {
|
|
@@ -122,11 +147,20 @@ export declare type SidebarItemsGeneratorArgs = {
|
|
|
122
147
|
docs: SidebarItemsGeneratorDoc[];
|
|
123
148
|
numberPrefixParser: NumberPrefixParser;
|
|
124
149
|
isCategoryIndex: CategoryIndexMatcher;
|
|
150
|
+
categoriesMetadata: Record<string, CategoryMetadataFile>;
|
|
125
151
|
options: SidebarOptions;
|
|
126
152
|
};
|
|
127
|
-
export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<
|
|
153
|
+
export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<NormalizedSidebar>;
|
|
128
154
|
export declare type SidebarItemsGeneratorOptionArgs = {
|
|
129
155
|
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
130
156
|
} & SidebarItemsGeneratorArgs;
|
|
131
|
-
export declare type SidebarItemsGeneratorOption = (generatorArgs: SidebarItemsGeneratorOptionArgs) => Promise<
|
|
157
|
+
export declare type SidebarItemsGeneratorOption = (generatorArgs: SidebarItemsGeneratorOptionArgs) => Promise<NormalizedSidebarItem[]>;
|
|
158
|
+
export declare type SidebarProcessorParams = {
|
|
159
|
+
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
160
|
+
numberPrefixParser: NumberPrefixParser;
|
|
161
|
+
docs: DocMetadataBase[];
|
|
162
|
+
version: VersionMetadata;
|
|
163
|
+
categoryLabelSlugger: Slugger;
|
|
164
|
+
sidebarOptions: SidebarOptions;
|
|
165
|
+
};
|
|
132
166
|
export {};
|
package/lib/sidebars/utils.js
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.toNavigationLink = exports.toDocNavigationLink = exports.createSidebarsUtils = exports.collectSidebarsNavigations = exports.collectSidebarsDocIds = exports.collectSidebarNavigation = exports.collectSidebarDocIds = exports.collectSidebarLinks = exports.collectSidebarCategories = exports.collectSidebarDocItems = exports.transformSidebarItems = exports.isCategoriesShorthand = void 0;
|
|
10
|
-
const
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
11
12
|
const utils_1 = require("@docusaurus/utils");
|
|
12
13
|
function isCategoriesShorthand(item) {
|
|
13
|
-
return typeof item
|
|
14
|
+
return typeof item === 'object' && !item.type;
|
|
14
15
|
}
|
|
15
16
|
exports.isCategoriesShorthand = isCategoriesShorthand;
|
|
16
17
|
function transformSidebarItems(sidebar, updateFn) {
|
|
@@ -26,8 +27,11 @@ function transformSidebarItems(sidebar, updateFn) {
|
|
|
26
27
|
return sidebar.map(transformRecursive);
|
|
27
28
|
}
|
|
28
29
|
exports.transformSidebarItems = transformSidebarItems;
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Flatten sidebar items into a single flat array (containing categories/docs on
|
|
32
|
+
* the same level). Order matters (useful for next/prev nav), top categories
|
|
33
|
+
* appear before their child elements
|
|
34
|
+
*/
|
|
31
35
|
function flattenSidebarItems(items) {
|
|
32
36
|
function flattenRecursive(item) {
|
|
33
37
|
return item.type === 'category'
|
|
@@ -78,11 +82,11 @@ function collectSidebarNavigation(sidebar) {
|
|
|
78
82
|
}
|
|
79
83
|
exports.collectSidebarNavigation = collectSidebarNavigation;
|
|
80
84
|
function collectSidebarsDocIds(sidebars) {
|
|
81
|
-
return
|
|
85
|
+
return lodash_1.default.mapValues(sidebars, collectSidebarDocIds);
|
|
82
86
|
}
|
|
83
87
|
exports.collectSidebarsDocIds = collectSidebarsDocIds;
|
|
84
88
|
function collectSidebarsNavigations(sidebars) {
|
|
85
|
-
return
|
|
89
|
+
return lodash_1.default.mapValues(sidebars, collectSidebarNavigation);
|
|
86
90
|
}
|
|
87
91
|
exports.collectSidebarsNavigations = collectSidebarsNavigations;
|
|
88
92
|
function createSidebarsUtils(sidebars) {
|
|
@@ -114,29 +118,27 @@ function createSidebarsUtils(sidebars) {
|
|
|
114
118
|
docId = versionedId;
|
|
115
119
|
sidebarName = getSidebarNameByDocId(docId);
|
|
116
120
|
}
|
|
117
|
-
if (sidebarName) {
|
|
118
|
-
|
|
119
|
-
|
|
121
|
+
if (!sidebarName) {
|
|
122
|
+
return emptySidebarNavigation();
|
|
123
|
+
}
|
|
124
|
+
if (!sidebarNameToNavigationItems[sidebarName]) {
|
|
125
|
+
throw new Error(`Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`);
|
|
126
|
+
}
|
|
127
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
128
|
+
const currentItemIndex = navigationItems.findIndex((item) => {
|
|
129
|
+
if (item.type === 'doc') {
|
|
130
|
+
return item.id === docId;
|
|
120
131
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (item.type === 'doc') {
|
|
124
|
-
return item.id === docId;
|
|
125
|
-
}
|
|
126
|
-
if (item.type === 'category' && item.link.type === 'doc') {
|
|
127
|
-
return item.link.id === docId;
|
|
128
|
-
}
|
|
129
|
-
return false;
|
|
130
|
-
});
|
|
131
|
-
if (currentItemIndex === -1) {
|
|
132
|
-
return { sidebarName, next: undefined, previous: undefined };
|
|
132
|
+
if (item.type === 'category' && item.link.type === 'doc') {
|
|
133
|
+
return item.link.id === docId;
|
|
133
134
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return emptySidebarNavigation();
|
|
135
|
+
return false;
|
|
136
|
+
});
|
|
137
|
+
if (currentItemIndex === -1) {
|
|
138
|
+
return { sidebarName, next: undefined, previous: undefined };
|
|
139
139
|
}
|
|
140
|
+
const { previous, next } = (0, utils_1.getElementsAround)(navigationItems, currentItemIndex);
|
|
141
|
+
return { sidebarName, previous, next };
|
|
140
142
|
}
|
|
141
143
|
function getCategoryGeneratedIndexList() {
|
|
142
144
|
return Object.values(sidebarNameToNavigationItems)
|
|
@@ -148,8 +150,10 @@ function createSidebarsUtils(sidebars) {
|
|
|
148
150
|
return [];
|
|
149
151
|
});
|
|
150
152
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
+
/**
|
|
154
|
+
* We identity the category generated index by its permalink (should be
|
|
155
|
+
* unique). More reliable than using object identity
|
|
156
|
+
*/
|
|
153
157
|
function getCategoryGeneratedIndexNavigation(categoryGeneratedIndexPermalink) {
|
|
154
158
|
var _a;
|
|
155
159
|
function isCurrentCategoryGeneratedIndexItem(item) {
|
|
@@ -159,31 +163,28 @@ function createSidebarsUtils(sidebars) {
|
|
|
159
163
|
item.link.permalink === categoryGeneratedIndexPermalink);
|
|
160
164
|
}
|
|
161
165
|
const sidebarName = (_a = Object.entries(sidebarNameToNavigationItems).find(([, navigationItems]) => navigationItems.find(isCurrentCategoryGeneratedIndexItem))) === null || _a === void 0 ? void 0 : _a[0];
|
|
162
|
-
if (sidebarName) {
|
|
163
|
-
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
164
|
-
const currentItemIndex = navigationItems.findIndex(isCurrentCategoryGeneratedIndexItem);
|
|
165
|
-
const { previous, next } = (0, utils_1.getElementsAround)(navigationItems, currentItemIndex);
|
|
166
|
-
return { sidebarName, previous, next };
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
166
|
+
if (!sidebarName) {
|
|
169
167
|
return emptySidebarNavigation();
|
|
170
168
|
}
|
|
169
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
170
|
+
const currentItemIndex = navigationItems.findIndex(isCurrentCategoryGeneratedIndexItem);
|
|
171
|
+
const { previous, next } = (0, utils_1.getElementsAround)(navigationItems, currentItemIndex);
|
|
172
|
+
return { sidebarName, previous, next };
|
|
171
173
|
}
|
|
172
174
|
function checkSidebarsDocIds(validDocIds, sidebarFilePath) {
|
|
173
175
|
const allSidebarDocIds = Object.values(sidebarNameToDocIds).flat();
|
|
174
|
-
const invalidSidebarDocIds =
|
|
176
|
+
const invalidSidebarDocIds = lodash_1.default.difference(allSidebarDocIds, validDocIds);
|
|
175
177
|
if (invalidSidebarDocIds.length > 0) {
|
|
176
178
|
throw new Error(`Invalid sidebar file at "${(0, utils_1.toMessageRelativeFilePath)(sidebarFilePath)}".
|
|
177
179
|
These sidebar document ids do not exist:
|
|
178
180
|
- ${invalidSidebarDocIds.sort().join('\n- ')}
|
|
179
181
|
|
|
180
182
|
Available document ids are:
|
|
181
|
-
- ${
|
|
183
|
+
- ${lodash_1.default.uniq(validDocIds).sort().join('\n- ')}`);
|
|
182
184
|
}
|
|
183
185
|
}
|
|
184
186
|
function getFirstLink(sidebar) {
|
|
185
187
|
var _a, _b, _c;
|
|
186
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
187
188
|
for (const item of sidebar) {
|
|
188
189
|
if (item.type === 'doc') {
|
|
189
190
|
return {
|
|
@@ -207,11 +208,9 @@ Available document ids are:
|
|
|
207
208
|
label: item.label,
|
|
208
209
|
};
|
|
209
210
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
return firstSubItem;
|
|
214
|
-
}
|
|
211
|
+
const firstSubItem = getFirstLink(item.items);
|
|
212
|
+
if (firstSubItem) {
|
|
213
|
+
return firstSubItem;
|
|
215
214
|
}
|
|
216
215
|
}
|
|
217
216
|
}
|
|
@@ -243,20 +242,6 @@ function toNavigationLink(navigationItem, docsById) {
|
|
|
243
242
|
}
|
|
244
243
|
return doc;
|
|
245
244
|
}
|
|
246
|
-
function handleCategory(category) {
|
|
247
|
-
if (category.link.type === 'doc') {
|
|
248
|
-
return toDocNavigationLink(getDocById(category.link.id));
|
|
249
|
-
}
|
|
250
|
-
else if (category.link.type === 'generated-index') {
|
|
251
|
-
return {
|
|
252
|
-
title: category.label,
|
|
253
|
-
permalink: category.link.permalink,
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
throw new Error('unexpected category link type');
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
245
|
if (!navigationItem) {
|
|
261
246
|
return undefined;
|
|
262
247
|
}
|
|
@@ -264,10 +249,17 @@ function toNavigationLink(navigationItem, docsById) {
|
|
|
264
249
|
return toDocNavigationLink(getDocById(navigationItem.id));
|
|
265
250
|
}
|
|
266
251
|
else if (navigationItem.type === 'category') {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
252
|
+
if (navigationItem.link.type === 'doc') {
|
|
253
|
+
return toDocNavigationLink(getDocById(navigationItem.link.id));
|
|
254
|
+
}
|
|
255
|
+
else if (navigationItem.link.type === 'generated-index') {
|
|
256
|
+
return {
|
|
257
|
+
title: navigationItem.label,
|
|
258
|
+
permalink: navigationItem.link.permalink,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
throw new Error('unexpected category link type');
|
|
271
262
|
}
|
|
263
|
+
throw new Error('unexpected navigation item');
|
|
272
264
|
}
|
|
273
265
|
exports.toNavigationLink = toNavigationLink;
|
|
@@ -4,7 +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 {
|
|
8
|
-
|
|
9
|
-
export declare function validateSidebars(sidebars: unknown): asserts sidebars is SidebarsConfig;
|
|
7
|
+
import type { NormalizedSidebars, CategoryMetadataFile } from './types';
|
|
8
|
+
export declare function validateSidebars(sidebars: Record<string, unknown>): asserts sidebars is NormalizedSidebars;
|
|
10
9
|
export declare function validateCategoryMetadataFile(unsafeContent: unknown): CategoryMetadataFile;
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.validateCategoryMetadataFile = exports.validateSidebars = void 0;
|
|
10
10
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
|
-
const utils_1 = require("./utils");
|
|
12
11
|
// NOTE: we don't add any default values during validation on purpose!
|
|
13
|
-
// Config types are exposed to users for typechecking and we use the same type
|
|
12
|
+
// Config types are exposed to users for typechecking and we use the same type
|
|
13
|
+
// in normalization
|
|
14
14
|
const sidebarItemBaseSchema = utils_validation_1.Joi.object({
|
|
15
15
|
className: utils_validation_1.Joi.string(),
|
|
16
16
|
customProps: utils_validation_1.Joi.object().unknown(),
|
|
@@ -19,7 +19,7 @@ const sidebarItemAutogeneratedSchema = sidebarItemBaseSchema.append({
|
|
|
19
19
|
type: 'autogenerated',
|
|
20
20
|
dirName: utils_validation_1.Joi.string()
|
|
21
21
|
.required()
|
|
22
|
-
.pattern(/^[^/](
|
|
22
|
+
.pattern(/^[^/](?:.*[^/])?$/)
|
|
23
23
|
.message('"dirName" must be a dir path relative to the docs folder root, and should not start or end with slash'),
|
|
24
24
|
});
|
|
25
25
|
const sidebarItemDocSchema = sidebarItemBaseSchema.append({
|
|
@@ -27,6 +27,11 @@ const sidebarItemDocSchema = sidebarItemBaseSchema.append({
|
|
|
27
27
|
id: utils_validation_1.Joi.string().required(),
|
|
28
28
|
label: utils_validation_1.Joi.string(),
|
|
29
29
|
});
|
|
30
|
+
const sidebarItemHtmlSchema = sidebarItemBaseSchema.append({
|
|
31
|
+
type: 'html',
|
|
32
|
+
value: utils_validation_1.Joi.string().required(),
|
|
33
|
+
defaultStyle: utils_validation_1.Joi.boolean(),
|
|
34
|
+
});
|
|
30
35
|
const sidebarItemLinkSchema = sidebarItemBaseSchema.append({
|
|
31
36
|
type: 'link',
|
|
32
37
|
href: utils_validation_1.URISchema.required(),
|
|
@@ -35,6 +40,7 @@ const sidebarItemLinkSchema = sidebarItemBaseSchema.append({
|
|
|
35
40
|
.messages({ 'any.unknown': '"label" must be a string' }),
|
|
36
41
|
});
|
|
37
42
|
const sidebarItemCategoryLinkSchema = utils_validation_1.Joi.object()
|
|
43
|
+
.allow(null)
|
|
38
44
|
.when('.type', {
|
|
39
45
|
switch: [
|
|
40
46
|
{
|
|
@@ -49,7 +55,8 @@ const sidebarItemCategoryLinkSchema = utils_validation_1.Joi.object()
|
|
|
49
55
|
then: utils_validation_1.Joi.object({
|
|
50
56
|
type: 'generated-index',
|
|
51
57
|
slug: utils_validation_1.Joi.string().optional(),
|
|
52
|
-
//
|
|
58
|
+
// This one is not in the user config, only in the normalized version
|
|
59
|
+
// permalink: Joi.string().optional(),
|
|
53
60
|
title: utils_validation_1.Joi.string().optional(),
|
|
54
61
|
description: utils_validation_1.Joi.string().optional(),
|
|
55
62
|
image: utils_validation_1.Joi.string().optional(),
|
|
@@ -57,23 +64,23 @@ const sidebarItemCategoryLinkSchema = utils_validation_1.Joi.object()
|
|
|
57
64
|
}),
|
|
58
65
|
},
|
|
59
66
|
{
|
|
60
|
-
is: utils_validation_1.Joi.
|
|
67
|
+
is: utils_validation_1.Joi.required(),
|
|
61
68
|
then: utils_validation_1.Joi.forbidden().messages({
|
|
62
69
|
'any.unknown': 'Unknown sidebar category link type "{.type}".',
|
|
63
70
|
}),
|
|
64
71
|
},
|
|
65
72
|
],
|
|
66
|
-
})
|
|
67
|
-
.id('sidebarCategoryLinkSchema');
|
|
73
|
+
});
|
|
68
74
|
const sidebarItemCategorySchema = sidebarItemBaseSchema.append({
|
|
69
75
|
type: 'category',
|
|
70
76
|
label: utils_validation_1.Joi.string()
|
|
71
77
|
.required()
|
|
72
78
|
.messages({ 'any.unknown': '"label" must be a string' }),
|
|
73
|
-
// TODO: Joi doesn't allow mutual recursion. See https://github.com/sideway/joi/issues/2611
|
|
74
79
|
items: utils_validation_1.Joi.array()
|
|
75
80
|
.required()
|
|
76
81
|
.messages({ 'any.unknown': '"items" must be an array' }),
|
|
82
|
+
// TODO: Joi doesn't allow mutual recursion. See https://github.com/sideway/joi/issues/2611
|
|
83
|
+
// .items(Joi.link('#sidebarItemSchema')),
|
|
77
84
|
link: sidebarItemCategoryLinkSchema,
|
|
78
85
|
collapsed: utils_validation_1.Joi.boolean().messages({
|
|
79
86
|
'any.unknown': '"collapsed" must be a boolean',
|
|
@@ -82,14 +89,14 @@ const sidebarItemCategorySchema = sidebarItemBaseSchema.append({
|
|
|
82
89
|
'any.unknown': '"collapsible" must be a boolean',
|
|
83
90
|
}),
|
|
84
91
|
});
|
|
85
|
-
const sidebarItemSchema = utils_validation_1.Joi.object()
|
|
86
|
-
.when('.type', {
|
|
92
|
+
const sidebarItemSchema = utils_validation_1.Joi.object().when('.type', {
|
|
87
93
|
switch: [
|
|
88
94
|
{ is: 'link', then: sidebarItemLinkSchema },
|
|
89
95
|
{
|
|
90
96
|
is: utils_validation_1.Joi.string().valid('doc', 'ref').required(),
|
|
91
97
|
then: sidebarItemDocSchema,
|
|
92
98
|
},
|
|
99
|
+
{ is: 'html', then: sidebarItemHtmlSchema },
|
|
93
100
|
{ is: 'autogenerated', then: sidebarItemAutogeneratedSchema },
|
|
94
101
|
{ is: 'category', then: sidebarItemCategorySchema },
|
|
95
102
|
{
|
|
@@ -99,32 +106,20 @@ const sidebarItemSchema = utils_validation_1.Joi.object()
|
|
|
99
106
|
}),
|
|
100
107
|
},
|
|
101
108
|
],
|
|
102
|
-
})
|
|
103
|
-
|
|
109
|
+
});
|
|
110
|
+
// .id('sidebarItemSchema');
|
|
104
111
|
function validateSidebarItem(item) {
|
|
105
|
-
if (typeof item === 'string') {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
112
|
// TODO: remove once with proper Joi support
|
|
109
|
-
// Because we can't use Joi to validate nested items (see above), we do it
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
utils_validation_1.Joi.assert(item, sidebarItemSchema);
|
|
115
|
-
if (item.type === 'category') {
|
|
116
|
-
item.items.forEach(validateSidebarItem);
|
|
117
|
-
}
|
|
113
|
+
// Because we can't use Joi to validate nested items (see above), we do it
|
|
114
|
+
// manually
|
|
115
|
+
utils_validation_1.Joi.assert(item, sidebarItemSchema);
|
|
116
|
+
if (item.type === 'category') {
|
|
117
|
+
item.items.forEach(validateSidebarItem);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
function validateSidebars(sidebars) {
|
|
121
121
|
Object.values(sidebars).forEach((sidebar) => {
|
|
122
|
-
|
|
123
|
-
sidebar.forEach(validateSidebarItem);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
validateSidebarItem(sidebar);
|
|
127
|
-
}
|
|
122
|
+
sidebar.forEach(validateSidebarItem);
|
|
128
123
|
});
|
|
129
124
|
}
|
|
130
125
|
exports.validateSidebars = validateSidebars;
|
package/lib/slug.js
CHANGED
|
@@ -23,15 +23,13 @@ function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumbe
|
|
|
23
23
|
if (frontMatterSlug === null || frontMatterSlug === void 0 ? void 0 : frontMatterSlug.startsWith('/')) {
|
|
24
24
|
return frontMatterSlug;
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return dirNameSlug;
|
|
31
|
-
}
|
|
32
|
-
const baseSlug = frontMatterSlug || baseID;
|
|
33
|
-
return (0, utils_1.resolvePathname)(baseSlug, getDirNameSlug());
|
|
26
|
+
const dirNameSlug = getDirNameSlug();
|
|
27
|
+
if (!frontMatterSlug &&
|
|
28
|
+
(0, docs_1.isCategoryIndex)((0, docs_1.toCategoryIndexMatcherParam)({ source, sourceDirName }))) {
|
|
29
|
+
return dirNameSlug;
|
|
34
30
|
}
|
|
31
|
+
const baseSlug = frontMatterSlug || baseID;
|
|
32
|
+
return (0, utils_1.resolvePathname)(baseSlug, getDirNameSlug());
|
|
35
33
|
}
|
|
36
34
|
function ensureValidSlug(slug) {
|
|
37
35
|
if (!(0, utils_1.isValidPathname)(slug)) {
|
package/lib/tags.js
CHANGED
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.getVersionTags = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
10
11
|
const utils_1 = require("@docusaurus/utils");
|
|
11
|
-
const lodash_1 = require("lodash");
|
|
12
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
12
13
|
function getVersionTags(docs) {
|
|
13
14
|
const groups = (0, utils_1.groupTaggedItems)(docs, (doc) => doc.tags);
|
|
14
|
-
return
|
|
15
|
+
return lodash_1.default.mapValues(groups, (group) => ({
|
|
15
16
|
name: group.tag.label,
|
|
16
17
|
docIds: group.items.map((item) => item.id),
|
|
17
18
|
permalink: group.tag.permalink,
|
package/lib/translations.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.translateLoadedContent = exports.getLoadedContentTranslationFiles = void 0;
|
|
10
|
-
const
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
11
12
|
const utils_1 = require("./sidebars/utils");
|
|
12
13
|
const utils_2 = require("@docusaurus/utils");
|
|
13
14
|
const constants_1 = require("./constants");
|
|
@@ -15,11 +16,9 @@ function getVersionFileName(versionName) {
|
|
|
15
16
|
if (versionName === constants_1.CURRENT_VERSION_NAME) {
|
|
16
17
|
return versionName;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return `version-${versionName}`;
|
|
22
|
-
}
|
|
19
|
+
// I don't like this "version-" prefix,
|
|
20
|
+
// but it's for consistency with site/versioned_docs
|
|
21
|
+
return `version-${versionName}`;
|
|
23
22
|
}
|
|
24
23
|
// TODO legacy, the sidebar name is like "version-2.0.0-alpha.66/docs"
|
|
25
24
|
// input: "version-2.0.0-alpha.66/docs"
|
|
@@ -44,7 +43,8 @@ function getDocTranslations(doc: DocMetadata): TranslationFileContent {
|
|
|
44
43
|
? {
|
|
45
44
|
[`${doc.unversionedId}.sidebar_label`]: {
|
|
46
45
|
message: doc.sidebar_label,
|
|
47
|
-
description:
|
|
46
|
+
description:
|
|
47
|
+
`The sidebar label for doc with id=${doc.unversionedId}`,
|
|
48
48
|
},
|
|
49
49
|
}
|
|
50
50
|
: undefined),
|
|
@@ -109,13 +109,13 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
|
109
109
|
return entries;
|
|
110
110
|
}));
|
|
111
111
|
const links = (0, utils_1.collectSidebarLinks)(sidebar);
|
|
112
|
-
const linksContent = (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
112
|
+
const linksContent = Object.fromEntries(links.map((link) => [
|
|
113
|
+
`sidebar.${sidebarName}.link.${link.label}`,
|
|
114
|
+
{
|
|
115
|
+
message: link.label,
|
|
116
|
+
description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
|
|
117
|
+
},
|
|
118
|
+
]));
|
|
119
119
|
return (0, utils_2.mergeTranslations)([categoryContent, linksContent]);
|
|
120
120
|
}
|
|
121
121
|
function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
@@ -164,7 +164,7 @@ function getSidebarsTranslations(version) {
|
|
|
164
164
|
}));
|
|
165
165
|
}
|
|
166
166
|
function translateSidebars(version, sidebarsTranslations) {
|
|
167
|
-
return
|
|
167
|
+
return lodash_1.default.mapValues(version.sidebars, (sidebar, sidebarName) => translateSidebar({
|
|
168
168
|
sidebar,
|
|
169
169
|
sidebarName: getNormalizedSidebarName({
|
|
170
170
|
sidebarName,
|
|
@@ -181,7 +181,8 @@ function getVersionTranslationFiles(version) {
|
|
|
181
181
|
},
|
|
182
182
|
};
|
|
183
183
|
const sidebarsTranslations = getSidebarsTranslations(version);
|
|
184
|
-
// const docsTranslations: TranslationFileContent =
|
|
184
|
+
// const docsTranslations: TranslationFileContent =
|
|
185
|
+
// getDocsTranslations(version);
|
|
185
186
|
return [
|
|
186
187
|
{
|
|
187
188
|
path: getVersionFileName(version.versionName),
|
|
@@ -214,7 +215,7 @@ function getLoadedContentTranslationFiles(loadedContent) {
|
|
|
214
215
|
}
|
|
215
216
|
exports.getLoadedContentTranslationFiles = getLoadedContentTranslationFiles;
|
|
216
217
|
function translateLoadedContent(loadedContent, translationFiles) {
|
|
217
|
-
const translationFilesMap =
|
|
218
|
+
const translationFilesMap = lodash_1.default.keyBy(translationFiles, (f) => f.path);
|
|
218
219
|
return {
|
|
219
220
|
loadedVersions: translateVersions(loadedContent.loadedVersions, translationFilesMap),
|
|
220
221
|
};
|
package/lib/types.d.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { Sidebars } from './sidebars/types';
|
|
8
|
-
import type { Tag, FrontMatterTag
|
|
8
|
+
import type { Tag, FrontMatterTag } from '@docusaurus/utils';
|
|
9
9
|
import type { BrokenMarkdownLink as IBrokenMarkdownLink, ContentPaths } from '@docusaurus/utils/lib/markdownLinks';
|
|
10
|
-
import type { VersionBanner
|
|
10
|
+
import type { VersionBanner } from '@docusaurus/plugin-content-docs';
|
|
11
11
|
export declare type DocFile = {
|
|
12
12
|
contentPath: string;
|
|
13
13
|
filePath: string;
|
|
@@ -29,10 +29,6 @@ export declare type VersionMetadata = ContentPaths & {
|
|
|
29
29
|
sidebarFilePath: string | false | undefined;
|
|
30
30
|
routePriority: number | undefined;
|
|
31
31
|
};
|
|
32
|
-
export declare type NormalizeSidebarsParams = SidebarOptions & {
|
|
33
|
-
version: VersionMetadata;
|
|
34
|
-
categoryLabelSlugger: Slugger;
|
|
35
|
-
};
|
|
36
32
|
export declare type LastUpdateData = {
|
|
37
33
|
lastUpdatedAt?: number;
|
|
38
34
|
formattedLastUpdatedAt?: string;
|
|
@@ -51,6 +47,7 @@ export declare type DocFrontMatter = {
|
|
|
51
47
|
sidebar_label?: string;
|
|
52
48
|
sidebar_position?: number;
|
|
53
49
|
sidebar_class_name?: string;
|
|
50
|
+
sidebar_custom_props?: Record<string, unknown>;
|
|
54
51
|
displayed_sidebar?: string | null;
|
|
55
52
|
pagination_label?: string;
|
|
56
53
|
custom_edit_url?: string | null;
|
package/lib/versions.d.ts
CHANGED
|
@@ -5,11 +5,35 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { VersionMetadata } from './types';
|
|
8
|
-
import type { PluginOptions } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
import type { PluginOptions, VersionBanner } from '@docusaurus/plugin-content-docs';
|
|
9
9
|
import type { LoadContext } from '@docusaurus/types';
|
|
10
10
|
export declare function getVersionedDocsDirPath(siteDir: string, pluginId: string): string;
|
|
11
11
|
export declare function getVersionedSidebarsDirPath(siteDir: string, pluginId: string): string;
|
|
12
12
|
export declare function getVersionsFilePath(siteDir: string, pluginId: string): string;
|
|
13
|
+
export declare function readVersionsFile(siteDir: string, pluginId: string): Promise<string[] | null>;
|
|
14
|
+
export declare function readVersionNames(siteDir: string, options: Pick<PluginOptions, 'id' | 'disableVersioning' | 'includeCurrentVersion'>): Promise<string[]>;
|
|
15
|
+
export declare function getDefaultVersionBanner({ versionName, versionNames, lastVersionName, }: {
|
|
16
|
+
versionName: string;
|
|
17
|
+
versionNames: string[];
|
|
18
|
+
lastVersionName: string;
|
|
19
|
+
}): VersionBanner | null;
|
|
20
|
+
export declare function getVersionBanner({ versionName, versionNames, lastVersionName, options, }: {
|
|
21
|
+
versionName: string;
|
|
22
|
+
versionNames: string[];
|
|
23
|
+
lastVersionName: string;
|
|
24
|
+
options: Pick<PluginOptions, 'versions'>;
|
|
25
|
+
}): VersionBanner | null;
|
|
26
|
+
export declare function getVersionBadge({ versionName, versionNames, options, }: {
|
|
27
|
+
versionName: string;
|
|
28
|
+
versionNames: string[];
|
|
29
|
+
options: Pick<PluginOptions, 'versions'>;
|
|
30
|
+
}): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Filter versions according to provided options.
|
|
33
|
+
* Note: we preserve the order in which versions are provided;
|
|
34
|
+
* the order of the onlyIncludeVersions array does not matter
|
|
35
|
+
*/
|
|
36
|
+
export declare function filterVersions(versionNamesUnfiltered: string[], options: Pick<PluginOptions, 'onlyIncludeVersions'>): string[];
|
|
13
37
|
export declare function readVersionsMetadata({ context, options, }: {
|
|
14
38
|
context: Pick<LoadContext, 'siteDir' | 'baseUrl' | 'i18n'>;
|
|
15
39
|
options: Pick<PluginOptions, 'id' | 'path' | 'sidebarPath' | 'routeBasePath' | 'tagsBasePath' | 'includeCurrentVersion' | 'disableVersioning' | 'lastVersion' | 'versions' | 'onlyIncludeVersions' | 'editUrl' | 'editCurrentVersion'>;
|