@docusaurus/plugin-content-docs 2.4.1 → 3.0.0-beta.0
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/client/index.d.ts +9 -8
- package/lib/docs.d.ts +5 -4
- package/lib/docs.js +26 -44
- package/lib/frontMatter.js +3 -2
- package/lib/globalData.js +6 -3
- package/lib/index.js +30 -75
- package/lib/options.js +7 -6
- package/lib/props.d.ts +8 -2
- package/lib/props.js +37 -13
- package/lib/routes.d.ts +12 -19
- package/lib/routes.js +107 -35
- package/lib/sidebars/generator.js +2 -1
- package/lib/sidebars/postProcessor.d.ts +1 -1
- package/lib/sidebars/postProcessor.js +1 -2
- package/lib/sidebars/processor.js +0 -1
- package/lib/sidebars/types.d.ts +49 -47
- package/lib/sidebars/utils.d.ts +17 -5
- package/lib/sidebars/utils.js +78 -14
- package/lib/tags.js +12 -5
- package/lib/translations.js +2 -21
- package/lib/types.d.ts +8 -7
- package/lib/versions/index.d.ts +4 -2
- package/lib/versions/index.js +15 -1
- package/package.json +15 -15
- package/src/client/index.ts +2 -1
- package/src/docs.ts +36 -73
- package/src/frontMatter.ts +4 -2
- package/src/globalData.ts +8 -6
- package/src/index.ts +35 -105
- package/src/options.ts +10 -6
- package/src/plugin-content-docs.d.ts +47 -14
- package/src/props.ts +61 -18
- package/src/routes.ts +164 -68
- package/src/sidebars/generator.ts +6 -1
- package/src/sidebars/postProcessor.ts +1 -2
- package/src/sidebars/processor.ts +0 -1
- package/src/sidebars/types.ts +7 -1
- package/src/sidebars/utils.ts +151 -24
- package/src/tags.ts +13 -6
- package/src/translations.ts +4 -28
- package/src/types.ts +1 -0
- package/src/versions/index.ts +17 -1
package/lib/routes.js
CHANGED
|
@@ -6,20 +6,22 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.createAllRoutes = exports.buildAllRoutes = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
11
12
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
13
|
const utils_1 = require("@docusaurus/utils");
|
|
13
14
|
const props_1 = require("./props");
|
|
14
|
-
|
|
15
|
+
const tags_1 = require("./tags");
|
|
16
|
+
async function buildVersionCategoryGeneratedIndexRoutes({ version, actions, options, aliasedSource, }) {
|
|
15
17
|
const slugs = (0, utils_1.createSlugger)();
|
|
16
|
-
async function
|
|
18
|
+
async function buildCategoryGeneratedIndexRoute(categoryGeneratedIndex) {
|
|
17
19
|
const { sidebar, ...prop } = categoryGeneratedIndex;
|
|
18
20
|
const propFileName = slugs.slug(`${version.path}-${categoryGeneratedIndex.sidebar}-category-${categoryGeneratedIndex.title}`);
|
|
19
21
|
const propData = await actions.createData(`${(0, utils_1.docuHash)(`category/${propFileName}`)}.json`, JSON.stringify(prop, null, 2));
|
|
20
22
|
return {
|
|
21
23
|
path: categoryGeneratedIndex.permalink,
|
|
22
|
-
component: docCategoryGeneratedIndexComponent,
|
|
24
|
+
component: options.docCategoryGeneratedIndexComponent,
|
|
23
25
|
exact: true,
|
|
24
26
|
modules: {
|
|
25
27
|
categoryGeneratedIndex: aliasedSource(propData),
|
|
@@ -29,23 +31,22 @@ async function createCategoryGeneratedIndexRoutes({ version, actions, docCategor
|
|
|
29
31
|
...(sidebar && { sidebar }),
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
|
-
return Promise.all(version.categoryGeneratedIndices.map(
|
|
34
|
+
return Promise.all(version.categoryGeneratedIndices.map(buildCategoryGeneratedIndexRoute));
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return Promise.all(docs.map(async (metadataItem) => {
|
|
36
|
+
async function buildVersionDocRoutes({ version, actions, options, }) {
|
|
37
|
+
return Promise.all(version.docs.map(async (metadataItem) => {
|
|
37
38
|
await actions.createData(
|
|
38
39
|
// Note that this created data path must be in sync with
|
|
39
40
|
// metadataPath provided to mdx-loader.
|
|
40
41
|
`${(0, utils_1.docuHash)(metadataItem.source)}.json`, JSON.stringify(metadataItem, null, 2));
|
|
41
42
|
const docRoute = {
|
|
42
43
|
path: metadataItem.permalink,
|
|
43
|
-
component: docItemComponent,
|
|
44
|
+
component: options.docItemComponent,
|
|
44
45
|
exact: true,
|
|
45
46
|
modules: {
|
|
46
47
|
content: metadataItem.source,
|
|
47
48
|
},
|
|
48
|
-
// Because the parent (
|
|
49
|
+
// Because the parent (DocRoot) comp need to access it easily
|
|
49
50
|
// This permits to render the sidebar once without unmount/remount when
|
|
50
51
|
// navigating (and preserve sidebar state)
|
|
51
52
|
...(metadataItem.sidebar && {
|
|
@@ -55,42 +56,113 @@ async function createDocRoutes({ docs, actions, docItemComponent, }) {
|
|
|
55
56
|
return docRoute;
|
|
56
57
|
}));
|
|
57
58
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
59
|
+
async function buildVersionSidebarRoute(param) {
|
|
60
|
+
const [docRoutes, categoryGeneratedIndexRoutes] = await Promise.all([
|
|
61
|
+
buildVersionDocRoutes(param),
|
|
62
|
+
buildVersionCategoryGeneratedIndexRoutes(param),
|
|
63
|
+
]);
|
|
64
|
+
const subRoutes = [...docRoutes, ...categoryGeneratedIndexRoutes];
|
|
65
|
+
return {
|
|
66
|
+
path: param.version.path,
|
|
67
|
+
exact: false,
|
|
68
|
+
component: param.options.docRootComponent,
|
|
69
|
+
routes: subRoutes,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async function buildVersionTagsRoutes(param) {
|
|
73
|
+
const { version, options, actions, aliasedSource } = param;
|
|
74
|
+
const versionTags = (0, tags_1.getVersionTags)(version.docs);
|
|
75
|
+
async function buildTagsListRoute() {
|
|
76
|
+
// Don't create a tags list page if there's no tag
|
|
77
|
+
if (Object.keys(versionTags).length === 0) {
|
|
78
|
+
return null;
|
|
75
79
|
}
|
|
76
|
-
|
|
80
|
+
const tagsProp = (0, props_1.toTagsListTagsProp)(versionTags);
|
|
81
|
+
const tagsPropPath = await actions.createData(`${(0, utils_1.docuHash)(`tags-list-${version.versionName}-prop`)}.json`, JSON.stringify(tagsProp, null, 2));
|
|
82
|
+
return {
|
|
83
|
+
path: version.tagsPath,
|
|
84
|
+
exact: true,
|
|
85
|
+
component: options.docTagsListComponent,
|
|
86
|
+
modules: {
|
|
87
|
+
tags: aliasedSource(tagsPropPath),
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async function buildTagDocListRoute(tag) {
|
|
92
|
+
const tagProps = (0, props_1.toTagDocListProp)({
|
|
93
|
+
allTagsPath: version.tagsPath,
|
|
94
|
+
tag,
|
|
95
|
+
docs: version.docs,
|
|
96
|
+
});
|
|
97
|
+
const tagPropPath = await actions.createData(`${(0, utils_1.docuHash)(`tag-${tag.permalink}`)}.json`, JSON.stringify(tagProps, null, 2));
|
|
98
|
+
return {
|
|
99
|
+
path: tag.permalink,
|
|
100
|
+
component: options.docTagDocListComponent,
|
|
101
|
+
exact: true,
|
|
102
|
+
modules: {
|
|
103
|
+
tag: aliasedSource(tagPropPath),
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const [tagsListRoute, allTagsDocListRoutes] = await Promise.all([
|
|
108
|
+
buildTagsListRoute(),
|
|
109
|
+
Promise.all(Object.values(versionTags).map(buildTagDocListRoute)),
|
|
110
|
+
]);
|
|
111
|
+
return lodash_1.default.compact([tagsListRoute, ...allTagsDocListRoutes]);
|
|
112
|
+
}
|
|
113
|
+
async function buildVersionRoutes(param) {
|
|
114
|
+
const { version, actions, options, aliasedSource } = param;
|
|
115
|
+
async function buildVersionSubRoutes() {
|
|
116
|
+
const [sidebarRoute, tagsRoutes] = await Promise.all([
|
|
117
|
+
buildVersionSidebarRoute(param),
|
|
118
|
+
buildVersionTagsRoutes(param),
|
|
119
|
+
]);
|
|
120
|
+
return [sidebarRoute, ...tagsRoutes];
|
|
121
|
+
}
|
|
122
|
+
async function doBuildVersionRoutes() {
|
|
123
|
+
const versionProp = (0, props_1.toVersionMetadataProp)(options.id, version);
|
|
124
|
+
const versionPropPath = await actions.createData(`${(0, utils_1.docuHash)(`version-${version.versionName}-metadata-prop`)}.json`, JSON.stringify(versionProp, null, 2));
|
|
125
|
+
const subRoutes = await buildVersionSubRoutes();
|
|
126
|
+
return {
|
|
77
127
|
path: version.path,
|
|
78
|
-
// Allow matching /docs/* since this is the wrapping route
|
|
79
128
|
exact: false,
|
|
80
|
-
component:
|
|
81
|
-
routes:
|
|
129
|
+
component: options.docVersionRootComponent,
|
|
130
|
+
routes: subRoutes,
|
|
82
131
|
modules: {
|
|
83
|
-
|
|
132
|
+
version: aliasedSource(versionPropPath),
|
|
84
133
|
},
|
|
85
134
|
priority: version.routePriority,
|
|
86
|
-
}
|
|
135
|
+
};
|
|
87
136
|
}
|
|
88
137
|
try {
|
|
89
|
-
return await
|
|
138
|
+
return await doBuildVersionRoutes();
|
|
90
139
|
}
|
|
91
140
|
catch (err) {
|
|
92
141
|
logger_1.default.error `Can't create version routes for version name=${version.versionName}`;
|
|
93
142
|
throw err;
|
|
94
143
|
}
|
|
95
144
|
}
|
|
96
|
-
|
|
145
|
+
// TODO we want this buildAllRoutes function to be easily testable
|
|
146
|
+
// Ideally, we should avoid side effects here (ie not injecting actions)
|
|
147
|
+
async function buildAllRoutes(param) {
|
|
148
|
+
const subRoutes = await Promise.all(param.versions.map((version) => buildVersionRoutes({
|
|
149
|
+
...param,
|
|
150
|
+
version,
|
|
151
|
+
})));
|
|
152
|
+
// all docs routes are wrapped under a single parent route, this ensures
|
|
153
|
+
// the theme layout never unmounts/remounts when navigating between versions
|
|
154
|
+
return [
|
|
155
|
+
{
|
|
156
|
+
path: (0, utils_1.normalizeUrl)([param.baseUrl, param.options.routeBasePath]),
|
|
157
|
+
exact: false,
|
|
158
|
+
component: param.options.docsRootComponent,
|
|
159
|
+
routes: subRoutes,
|
|
160
|
+
},
|
|
161
|
+
];
|
|
162
|
+
}
|
|
163
|
+
exports.buildAllRoutes = buildAllRoutes;
|
|
164
|
+
async function createAllRoutes(param) {
|
|
165
|
+
const routes = await buildAllRoutes(param);
|
|
166
|
+
routes.forEach(param.actions.addRoute);
|
|
167
|
+
}
|
|
168
|
+
exports.createAllRoutes = createAllRoutes;
|
|
@@ -91,7 +91,7 @@ Available doc IDs:
|
|
|
91
91
|
*/
|
|
92
92
|
function generateSidebar(fsModel) {
|
|
93
93
|
function createDocItem(id, fullPath, fileName) {
|
|
94
|
-
const { sidebarPosition: position, frontMatter: { sidebar_label: label, sidebar_class_name: className }, } = getDoc(id);
|
|
94
|
+
const { sidebarPosition: position, frontMatter: { sidebar_label: label, sidebar_class_name: className, sidebar_custom_props: customProps, }, } = getDoc(id);
|
|
95
95
|
return {
|
|
96
96
|
type: 'doc',
|
|
97
97
|
id,
|
|
@@ -101,6 +101,7 @@ Available doc IDs:
|
|
|
101
101
|
// sidebar
|
|
102
102
|
...(label !== undefined && { label }),
|
|
103
103
|
...(className !== undefined && { className }),
|
|
104
|
+
...(customProps !== undefined && { customProps }),
|
|
104
105
|
};
|
|
105
106
|
}
|
|
106
107
|
function createCategoryItem(dir, fullPath, folderName) {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { Sidebars, SidebarProcessorParams, ProcessedSidebars } from './types';
|
|
8
|
-
export
|
|
8
|
+
export type SidebarPostProcessorParams = SidebarProcessorParams & {
|
|
9
9
|
draftIds: Set<string>;
|
|
10
10
|
};
|
|
11
11
|
export declare function postProcessSidebars(sidebars: ProcessedSidebars, params: SidebarProcessorParams): Sidebars;
|
|
@@ -10,7 +10,6 @@ exports.postProcessSidebars = void 0;
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
|
-
const docs_1 = require("../docs");
|
|
14
13
|
function normalizeCategoryLink(category, params) {
|
|
15
14
|
if (category.link?.type === 'doc' && params.draftIds.has(category.link.id)) {
|
|
16
15
|
return undefined;
|
|
@@ -73,7 +72,7 @@ function postProcessSidebarItem(item, params) {
|
|
|
73
72
|
return item;
|
|
74
73
|
}
|
|
75
74
|
function postProcessSidebars(sidebars, params) {
|
|
76
|
-
const draftIds = new Set(params.drafts.
|
|
75
|
+
const draftIds = new Set(params.drafts.map((d) => d.id));
|
|
77
76
|
return lodash_1.default.mapValues(sidebars, (sidebar) => sidebar
|
|
78
77
|
.map((item) => postProcessSidebarItem(item, { ...params, draftIds }))
|
|
79
78
|
.filter((v) => Boolean(v)));
|
package/lib/sidebars/types.d.ts
CHANGED
|
@@ -7,18 +7,18 @@
|
|
|
7
7
|
import type { Optional, Required } from 'utility-types';
|
|
8
8
|
import type { NumberPrefixParser, SidebarOptions, CategoryIndexMatcher, DocMetadataBase, VersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
9
9
|
import type { Slugger } from '@docusaurus/utils';
|
|
10
|
-
|
|
10
|
+
type Expand<T extends {
|
|
11
11
|
[x: string]: unknown;
|
|
12
12
|
}> = {
|
|
13
13
|
[P in keyof T]: T[P];
|
|
14
14
|
};
|
|
15
|
-
export
|
|
15
|
+
export type SidebarItemBase = {
|
|
16
16
|
className?: string;
|
|
17
17
|
customProps?: {
|
|
18
18
|
[key: string]: unknown;
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
-
export
|
|
21
|
+
export type SidebarItemDoc = SidebarItemBase & {
|
|
22
22
|
type: 'doc' | 'ref';
|
|
23
23
|
label?: string;
|
|
24
24
|
id: string;
|
|
@@ -28,34 +28,34 @@ export declare type SidebarItemDoc = SidebarItemBase & {
|
|
|
28
28
|
*/
|
|
29
29
|
translatable?: true;
|
|
30
30
|
};
|
|
31
|
-
export
|
|
31
|
+
export type SidebarItemHtml = SidebarItemBase & {
|
|
32
32
|
type: 'html';
|
|
33
33
|
value: string;
|
|
34
34
|
defaultStyle?: boolean;
|
|
35
35
|
};
|
|
36
|
-
export
|
|
36
|
+
export type SidebarItemLink = SidebarItemBase & {
|
|
37
37
|
type: 'link';
|
|
38
38
|
href: string;
|
|
39
39
|
label: string;
|
|
40
40
|
autoAddBaseUrl?: boolean;
|
|
41
41
|
description?: string;
|
|
42
42
|
};
|
|
43
|
-
export
|
|
43
|
+
export type SidebarItemAutogenerated = SidebarItemBase & {
|
|
44
44
|
type: 'autogenerated';
|
|
45
45
|
dirName: string;
|
|
46
46
|
};
|
|
47
|
-
|
|
47
|
+
type SidebarItemCategoryBase = SidebarItemBase & {
|
|
48
48
|
type: 'category';
|
|
49
49
|
label: string;
|
|
50
50
|
collapsed: boolean;
|
|
51
51
|
collapsible: boolean;
|
|
52
52
|
description?: string;
|
|
53
53
|
};
|
|
54
|
-
export
|
|
54
|
+
export type SidebarItemCategoryLinkDoc = {
|
|
55
55
|
type: 'doc';
|
|
56
56
|
id: string;
|
|
57
57
|
};
|
|
58
|
-
export
|
|
58
|
+
export type SidebarItemCategoryLinkGeneratedIndexConfig = {
|
|
59
59
|
type: 'generated-index';
|
|
60
60
|
slug?: string;
|
|
61
61
|
title?: string;
|
|
@@ -63,7 +63,7 @@ export declare type SidebarItemCategoryLinkGeneratedIndexConfig = {
|
|
|
63
63
|
image?: string;
|
|
64
64
|
keywords?: string | readonly string[];
|
|
65
65
|
};
|
|
66
|
-
export
|
|
66
|
+
export type SidebarItemCategoryLinkGeneratedIndex = {
|
|
67
67
|
type: 'generated-index';
|
|
68
68
|
slug: string;
|
|
69
69
|
permalink: string;
|
|
@@ -72,68 +72,70 @@ export declare type SidebarItemCategoryLinkGeneratedIndex = {
|
|
|
72
72
|
image?: string;
|
|
73
73
|
keywords?: string | readonly string[];
|
|
74
74
|
};
|
|
75
|
-
export
|
|
76
|
-
export
|
|
77
|
-
export
|
|
75
|
+
export type SidebarItemCategoryLinkConfig = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndexConfig;
|
|
76
|
+
export type SidebarItemCategoryLink = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndex;
|
|
77
|
+
export type SidebarItemCategoryConfig = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
78
78
|
items: SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
79
79
|
link?: SidebarItemCategoryLinkConfig;
|
|
80
80
|
}>;
|
|
81
|
-
export
|
|
81
|
+
export type SidebarCategoriesShorthand = {
|
|
82
82
|
[sidebarCategory: string]: SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
83
83
|
};
|
|
84
|
-
export
|
|
85
|
-
export
|
|
86
|
-
export
|
|
84
|
+
export type SidebarItemConfig = Omit<SidebarItemDoc, 'translatable'> | SidebarItemHtml | SidebarItemLink | SidebarItemAutogenerated | SidebarItemCategoryConfig | string | SidebarCategoriesShorthand;
|
|
85
|
+
export type SidebarConfig = SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
86
|
+
export type SidebarsConfig = {
|
|
87
87
|
[sidebarId: string]: SidebarConfig;
|
|
88
88
|
};
|
|
89
|
-
export
|
|
89
|
+
export type NormalizedSidebarItemCategory = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
90
90
|
items: NormalizedSidebarItem[];
|
|
91
91
|
link?: SidebarItemCategoryLinkConfig;
|
|
92
92
|
}>;
|
|
93
|
-
export
|
|
94
|
-
export
|
|
95
|
-
export
|
|
93
|
+
export type NormalizedSidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | NormalizedSidebarItemCategory | SidebarItemAutogenerated;
|
|
94
|
+
export type NormalizedSidebar = NormalizedSidebarItem[];
|
|
95
|
+
export type NormalizedSidebars = {
|
|
96
96
|
[sidebarId: string]: NormalizedSidebar;
|
|
97
97
|
};
|
|
98
|
-
export
|
|
98
|
+
export type ProcessedSidebarItemCategory = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
99
99
|
items: ProcessedSidebarItem[];
|
|
100
100
|
link?: SidebarItemCategoryLinkConfig;
|
|
101
101
|
}>;
|
|
102
|
-
export
|
|
103
|
-
export
|
|
104
|
-
export
|
|
102
|
+
export type ProcessedSidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | ProcessedSidebarItemCategory;
|
|
103
|
+
export type ProcessedSidebar = ProcessedSidebarItem[];
|
|
104
|
+
export type ProcessedSidebars = {
|
|
105
105
|
[sidebarId: string]: ProcessedSidebar;
|
|
106
106
|
};
|
|
107
|
-
export
|
|
107
|
+
export type SidebarItemCategory = Expand<SidebarItemCategoryBase & {
|
|
108
108
|
items: SidebarItem[];
|
|
109
109
|
link?: SidebarItemCategoryLink;
|
|
110
110
|
}>;
|
|
111
|
-
export
|
|
112
|
-
export
|
|
111
|
+
export type SidebarItemCategoryWithLink = Required<SidebarItemCategory, 'link'>;
|
|
112
|
+
export type SidebarItemCategoryWithGeneratedIndex = SidebarItemCategoryWithLink & {
|
|
113
113
|
link: SidebarItemCategoryLinkGeneratedIndex;
|
|
114
114
|
};
|
|
115
|
-
export
|
|
116
|
-
export
|
|
117
|
-
export
|
|
118
|
-
export
|
|
119
|
-
export
|
|
115
|
+
export type SidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | SidebarItemCategory;
|
|
116
|
+
export type SidebarNavigationItem = SidebarItemDoc | SidebarItemCategoryWithLink;
|
|
117
|
+
export type Sidebar = SidebarItem[];
|
|
118
|
+
export type SidebarItemType = SidebarItem['type'];
|
|
119
|
+
export type Sidebars = {
|
|
120
120
|
[sidebarId: string]: Sidebar;
|
|
121
121
|
};
|
|
122
|
-
export
|
|
122
|
+
export type PropSidebarItemCategory = Expand<SidebarItemCategoryBase & {
|
|
123
123
|
items: PropSidebarItem[];
|
|
124
124
|
href?: string;
|
|
125
|
+
linkUnlisted?: boolean;
|
|
125
126
|
}>;
|
|
126
|
-
export
|
|
127
|
+
export type PropSidebarItemLink = SidebarItemLink & {
|
|
127
128
|
docId?: string;
|
|
129
|
+
unlisted?: boolean;
|
|
128
130
|
};
|
|
129
|
-
export
|
|
130
|
-
export
|
|
131
|
-
export
|
|
132
|
-
export
|
|
131
|
+
export type PropSidebarItemHtml = SidebarItemHtml;
|
|
132
|
+
export type PropSidebarItem = PropSidebarItemLink | PropSidebarItemCategory | PropSidebarItemHtml;
|
|
133
|
+
export type PropSidebar = PropSidebarItem[];
|
|
134
|
+
export type PropSidebars = {
|
|
133
135
|
[sidebarId: string]: PropSidebar;
|
|
134
136
|
};
|
|
135
|
-
export
|
|
136
|
-
export
|
|
137
|
+
export type PropSidebarBreadcrumbsItem = PropSidebarItemLink | PropSidebarItemCategory;
|
|
138
|
+
export type CategoryMetadataFile = {
|
|
137
139
|
label?: string;
|
|
138
140
|
position?: number;
|
|
139
141
|
collapsed?: boolean;
|
|
@@ -144,9 +146,9 @@ export declare type CategoryMetadataFile = {
|
|
|
144
146
|
[key: string]: unknown;
|
|
145
147
|
};
|
|
146
148
|
};
|
|
147
|
-
export
|
|
148
|
-
export
|
|
149
|
-
export
|
|
149
|
+
export type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'title' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
|
|
150
|
+
export type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
|
|
151
|
+
export type SidebarItemsGeneratorArgs = {
|
|
150
152
|
/** The sidebar item with type "autogenerated" to be transformed. */
|
|
151
153
|
item: SidebarItemAutogenerated;
|
|
152
154
|
/** Useful metadata for the version this sidebar belongs to. */
|
|
@@ -165,8 +167,8 @@ export declare type SidebarItemsGeneratorArgs = {
|
|
|
165
167
|
[filePath: string]: CategoryMetadataFile;
|
|
166
168
|
};
|
|
167
169
|
};
|
|
168
|
-
export
|
|
169
|
-
export
|
|
170
|
+
export type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => NormalizedSidebar | Promise<NormalizedSidebar>;
|
|
171
|
+
export type SidebarItemsGeneratorOption = (generatorArgs: {
|
|
170
172
|
/**
|
|
171
173
|
* Useful to re-use/enhance the default sidebar generation logic from
|
|
172
174
|
* Docusaurus.
|
|
@@ -174,7 +176,7 @@ export declare type SidebarItemsGeneratorOption = (generatorArgs: {
|
|
|
174
176
|
*/
|
|
175
177
|
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
176
178
|
} & SidebarItemsGeneratorArgs) => NormalizedSidebar | Promise<NormalizedSidebar>;
|
|
177
|
-
export
|
|
179
|
+
export type SidebarProcessorParams = {
|
|
178
180
|
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
179
181
|
numberPrefixParser: NumberPrefixParser;
|
|
180
182
|
docs: DocMetadataBase[];
|
package/lib/sidebars/utils.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { Sidebars, Sidebar, SidebarItem, SidebarItemCategory, SidebarItemLink, SidebarItemDoc, SidebarCategoriesShorthand, SidebarItemConfig, SidebarItemCategoryWithGeneratedIndex, SidebarNavigationItem } from './types';
|
|
8
|
-
import type { DocMetadataBase, PropNavigationLink } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
import type { DocMetadataBase, PropNavigationLink, VersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
9
9
|
export declare function isCategoriesShorthand(item: SidebarItemConfig): item is SidebarCategoriesShorthand;
|
|
10
10
|
export declare function transformSidebarItems(sidebar: Sidebar, updateFn: (item: SidebarItem) => SidebarItem): Sidebar;
|
|
11
11
|
export declare function collectSidebarDocItems(sidebar: Sidebar): SidebarItemDoc[];
|
|
@@ -20,16 +20,20 @@ export declare function collectSidebarsDocIds(sidebars: Sidebars): {
|
|
|
20
20
|
export declare function collectSidebarsNavigations(sidebars: Sidebars): {
|
|
21
21
|
[sidebarId: string]: SidebarNavigationItem[];
|
|
22
22
|
};
|
|
23
|
-
export
|
|
23
|
+
export type SidebarNavigation = {
|
|
24
24
|
sidebarName: string | undefined;
|
|
25
25
|
previous: SidebarNavigationItem | undefined;
|
|
26
26
|
next: SidebarNavigationItem | undefined;
|
|
27
27
|
};
|
|
28
|
-
export
|
|
28
|
+
export type SidebarsUtils = {
|
|
29
29
|
sidebars: Sidebars;
|
|
30
30
|
getFirstDocIdOfFirstSidebar: () => string | undefined;
|
|
31
31
|
getSidebarNameByDocId: (docId: string) => string | undefined;
|
|
32
|
-
getDocNavigation: (
|
|
32
|
+
getDocNavigation: (params: {
|
|
33
|
+
docId: string;
|
|
34
|
+
displayedSidebar: string | null | undefined;
|
|
35
|
+
unlistedIds: Set<string>;
|
|
36
|
+
}) => SidebarNavigation;
|
|
33
37
|
getCategoryGeneratedIndexList: () => SidebarItemCategoryWithGeneratedIndex[];
|
|
34
38
|
getCategoryGeneratedIndexNavigation: (categoryGeneratedIndexPermalink: string) => SidebarNavigation;
|
|
35
39
|
/**
|
|
@@ -46,7 +50,15 @@ export declare type SidebarsUtils = {
|
|
|
46
50
|
permalink: string;
|
|
47
51
|
label: string;
|
|
48
52
|
} | undefined;
|
|
49
|
-
|
|
53
|
+
checkLegacyVersionedSidebarNames: ({ versionMetadata, }: {
|
|
54
|
+
sidebarFilePath: string;
|
|
55
|
+
versionMetadata: VersionMetadata;
|
|
56
|
+
}) => void;
|
|
57
|
+
checkSidebarsDocIds: ({ allDocIds, sidebarFilePath, versionMetadata, }: {
|
|
58
|
+
allDocIds: string[];
|
|
59
|
+
sidebarFilePath: string;
|
|
60
|
+
versionMetadata: VersionMetadata;
|
|
61
|
+
}) => void;
|
|
50
62
|
};
|
|
51
63
|
export declare function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils;
|
|
52
64
|
export declare function toDocNavigationLink(doc: DocMetadataBase): PropNavigationLink;
|
package/lib/sidebars/utils.js
CHANGED
|
@@ -110,23 +110,29 @@ function createSidebarsUtils(sidebars) {
|
|
|
110
110
|
next: undefined,
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
-
function getDocNavigation(
|
|
114
|
-
|
|
115
|
-
let docId = unversionedId;
|
|
116
|
-
let sidebarName = displayedSidebar === undefined
|
|
113
|
+
function getDocNavigation({ docId, displayedSidebar, unlistedIds, }) {
|
|
114
|
+
const sidebarName = displayedSidebar === undefined
|
|
117
115
|
? getSidebarNameByDocId(docId)
|
|
118
116
|
: displayedSidebar;
|
|
119
|
-
if (sidebarName === undefined) {
|
|
120
|
-
docId = versionedId;
|
|
121
|
-
sidebarName = getSidebarNameByDocId(docId);
|
|
122
|
-
}
|
|
123
117
|
if (!sidebarName) {
|
|
124
118
|
return emptySidebarNavigation();
|
|
125
119
|
}
|
|
126
|
-
|
|
120
|
+
let navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
127
121
|
if (!navigationItems) {
|
|
128
122
|
throw new Error(`Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`);
|
|
129
123
|
}
|
|
124
|
+
// Filter unlisted items from navigation
|
|
125
|
+
navigationItems = navigationItems.filter((item) => {
|
|
126
|
+
if (item.type === 'doc' && unlistedIds.has(item.id)) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
if (item.type === 'category' &&
|
|
130
|
+
item.link.type === 'doc' &&
|
|
131
|
+
unlistedIds.has(item.link.id)) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
return true;
|
|
135
|
+
});
|
|
130
136
|
const currentItemIndex = navigationItems.findIndex((item) => {
|
|
131
137
|
if (item.type === 'doc') {
|
|
132
138
|
return item.id === docId;
|
|
@@ -174,16 +180,73 @@ function createSidebarsUtils(sidebars) {
|
|
|
174
180
|
next: navigationItems[currentItemIndex + 1],
|
|
175
181
|
};
|
|
176
182
|
}
|
|
177
|
-
|
|
183
|
+
// TODO remove in Docusaurus v4
|
|
184
|
+
function getLegacyVersionedPrefix(versionMetadata) {
|
|
185
|
+
return `version-${versionMetadata.versionName}/`;
|
|
186
|
+
}
|
|
187
|
+
// In early v2, sidebar names used to be versioned
|
|
188
|
+
// example: "version-2.0.0-alpha.66/my-sidebar-name"
|
|
189
|
+
// In v3 it's not the case anymore and we throw an error to explain
|
|
190
|
+
// TODO remove in Docusaurus v4
|
|
191
|
+
function checkLegacyVersionedSidebarNames({ versionMetadata, sidebarFilePath, }) {
|
|
192
|
+
const illegalPrefix = getLegacyVersionedPrefix(versionMetadata);
|
|
193
|
+
const legacySidebarNames = Object.keys(sidebars).filter((sidebarName) => sidebarName.startsWith(illegalPrefix));
|
|
194
|
+
if (legacySidebarNames.length > 0) {
|
|
195
|
+
throw new Error(`Invalid sidebar file at "${(0, utils_1.toMessageRelativeFilePath)(sidebarFilePath)}".
|
|
196
|
+
These legacy versioned sidebar names are not supported anymore in Docusaurus v3:
|
|
197
|
+
- ${legacySidebarNames.sort().join('\n- ')}
|
|
198
|
+
|
|
199
|
+
The sidebar names you should now use are:
|
|
200
|
+
- ${legacySidebarNames
|
|
201
|
+
.sort()
|
|
202
|
+
.map((legacyName) => legacyName.split('/').splice(1).join('/'))
|
|
203
|
+
.join('\n- ')}
|
|
204
|
+
|
|
205
|
+
Please remove the "${illegalPrefix}" prefix from your versioned sidebar file.
|
|
206
|
+
This breaking change is documented on Docusaurus v3 release notes: https://docusaurus.io/blog/releases/3.0
|
|
207
|
+
`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// throw a better error message for Docusaurus v3 breaking change
|
|
211
|
+
// TODO this can be removed in Docusaurus v4
|
|
212
|
+
function handleLegacyVersionedDocIds({ invalidDocIds, sidebarFilePath, versionMetadata, }) {
|
|
213
|
+
const illegalPrefix = getLegacyVersionedPrefix(versionMetadata);
|
|
214
|
+
// In older v2.0 alpha/betas, versioned docs had a legacy versioned prefix
|
|
215
|
+
// Example: "version-1.4/my-doc-id"
|
|
216
|
+
//
|
|
217
|
+
const legacyVersionedDocIds = invalidDocIds.filter((docId) => docId.startsWith(illegalPrefix));
|
|
218
|
+
if (legacyVersionedDocIds.length > 0) {
|
|
219
|
+
throw new Error(`Invalid sidebar file at "${(0, utils_1.toMessageRelativeFilePath)(sidebarFilePath)}".
|
|
220
|
+
These legacy versioned document ids are not supported anymore in Docusaurus v3:
|
|
221
|
+
- ${legacyVersionedDocIds.sort().join('\n- ')}
|
|
222
|
+
|
|
223
|
+
The document ids you should now use are:
|
|
224
|
+
- ${legacyVersionedDocIds
|
|
225
|
+
.sort()
|
|
226
|
+
.map((legacyId) => legacyId.split('/').splice(1).join('/'))
|
|
227
|
+
.join('\n- ')}
|
|
228
|
+
|
|
229
|
+
Please remove the "${illegalPrefix}" prefix from your versioned sidebar file.
|
|
230
|
+
This breaking change is documented on Docusaurus v3 release notes: https://docusaurus.io/blog/releases/3.0
|
|
231
|
+
`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function checkSidebarsDocIds({ allDocIds, sidebarFilePath, versionMetadata, }) {
|
|
178
235
|
const allSidebarDocIds = Object.values(sidebarNameToDocIds).flat();
|
|
179
|
-
const
|
|
180
|
-
if (
|
|
236
|
+
const invalidDocIds = lodash_1.default.difference(allSidebarDocIds, allDocIds);
|
|
237
|
+
if (invalidDocIds.length > 0) {
|
|
238
|
+
handleLegacyVersionedDocIds({
|
|
239
|
+
invalidDocIds,
|
|
240
|
+
sidebarFilePath,
|
|
241
|
+
versionMetadata,
|
|
242
|
+
});
|
|
181
243
|
throw new Error(`Invalid sidebar file at "${(0, utils_1.toMessageRelativeFilePath)(sidebarFilePath)}".
|
|
182
244
|
These sidebar document ids do not exist:
|
|
183
|
-
- ${
|
|
245
|
+
- ${invalidDocIds.sort().join('\n- ')}
|
|
184
246
|
|
|
185
247
|
Available document ids are:
|
|
186
|
-
- ${lodash_1.default.uniq(
|
|
248
|
+
- ${lodash_1.default.uniq(allDocIds).sort().join('\n- ')}
|
|
249
|
+
`);
|
|
187
250
|
}
|
|
188
251
|
}
|
|
189
252
|
function getFirstLink(sidebar) {
|
|
@@ -225,6 +288,7 @@ Available document ids are:
|
|
|
225
288
|
getDocNavigation,
|
|
226
289
|
getCategoryGeneratedIndexList,
|
|
227
290
|
getCategoryGeneratedIndexNavigation,
|
|
291
|
+
checkLegacyVersionedSidebarNames,
|
|
228
292
|
checkSidebarsDocIds,
|
|
229
293
|
getFirstLink: (id) => getFirstLink(sidebars[id]),
|
|
230
294
|
};
|
package/lib/tags.js
CHANGED
|
@@ -12,10 +12,17 @@ const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
13
|
function getVersionTags(docs) {
|
|
14
14
|
const groups = (0, utils_1.groupTaggedItems)(docs, (doc) => doc.tags);
|
|
15
|
-
return lodash_1.default.mapValues(groups, (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
return lodash_1.default.mapValues(groups, ({ tag, items: tagDocs }) => {
|
|
16
|
+
const tagVisibility = (0, utils_1.getTagVisibility)({
|
|
17
|
+
items: tagDocs,
|
|
18
|
+
isUnlisted: (item) => item.unlisted,
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
label: tag.label,
|
|
22
|
+
docIds: tagVisibility.listedItems.map((item) => item.id),
|
|
23
|
+
permalink: tag.permalink,
|
|
24
|
+
unlisted: tagVisibility.unlisted,
|
|
25
|
+
};
|
|
26
|
+
});
|
|
20
27
|
}
|
|
21
28
|
exports.getVersionTags = getVersionTags;
|