@docusaurus/plugin-content-docs 2.0.0-beta.17 → 2.0.0-beta.18
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/categoryGeneratedIndex.js +0 -3
- package/lib/cli.js +3 -5
- package/lib/client/docsClientUtils.d.ts +3 -1
- package/lib/client/docsClientUtils.js +3 -3
- package/lib/client/index.d.ts +3 -1
- package/lib/docs.d.ts +4 -13
- package/lib/docs.js +7 -15
- package/lib/{docFrontMatter.d.ts → frontMatter.d.ts} +3 -1
- package/lib/{docFrontMatter.js → frontMatter.js} +0 -0
- package/lib/globalData.d.ts +2 -6
- package/lib/globalData.js +4 -8
- package/lib/lastUpdate.d.ts +4 -6
- package/lib/lastUpdate.js +13 -4
- package/lib/markdown/index.js +1 -1
- package/lib/markdown/linkify.js +4 -0
- package/lib/numberPrefix.js +16 -21
- package/lib/options.d.ts +3 -5
- package/lib/options.js +4 -3
- package/lib/sidebars/generator.js +33 -17
- package/lib/sidebars/index.js +13 -7
- package/lib/sidebars/postProcessor.js +11 -16
- package/lib/sidebars/processor.d.ts +3 -1
- package/lib/sidebars/processor.js +2 -2
- package/lib/sidebars/types.d.ts +13 -5
- package/lib/sidebars/utils.d.ts +15 -4
- package/lib/sidebars/utils.js +19 -23
- package/lib/sidebars/validation.d.ts +3 -1
- package/lib/sidebars/validation.js +1 -0
- package/lib/slug.js +3 -4
- package/lib/translations.js +19 -21
- package/lib/types.d.ts +9 -6
- package/lib/versions.js +3 -3
- package/package.json +10 -10
- package/src/categoryGeneratedIndex.ts +2 -6
- package/src/cli.ts +3 -5
- package/src/client/docsClientUtils.ts +3 -3
- package/src/client/index.ts +1 -1
- package/src/deps.d.ts +1 -1
- package/src/docs.ts +7 -25
- package/src/{docFrontMatter.ts → frontMatter.ts} +4 -4
- package/src/globalData.ts +5 -6
- package/src/index.ts +1 -2
- package/src/lastUpdate.ts +20 -8
- package/src/markdown/index.ts +1 -3
- package/src/markdown/linkify.ts +4 -0
- package/src/numberPrefix.ts +18 -28
- package/src/options.ts +6 -8
- package/src/plugin-content-docs.d.ts +12 -5
- package/src/sidebars/generator.ts +45 -22
- package/src/sidebars/index.ts +20 -13
- package/src/sidebars/postProcessor.ts +4 -9
- package/src/sidebars/processor.ts +4 -10
- package/src/sidebars/types.ts +5 -4
- package/src/sidebars/utils.ts +39 -43
- package/src/sidebars/validation.ts +4 -3
- package/src/slug.ts +3 -4
- package/src/translations.ts +24 -25
- package/src/types.ts +8 -7
- package/src/versions.ts +5 -5
package/lib/sidebars/types.d.ts
CHANGED
|
@@ -8,12 +8,16 @@ 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
10
|
import type { Slugger } from '@docusaurus/utils';
|
|
11
|
-
declare type Expand<T extends
|
|
11
|
+
declare type Expand<T extends {
|
|
12
|
+
[x: string]: unknown;
|
|
13
|
+
}> = {
|
|
12
14
|
[P in keyof T]: T[P];
|
|
13
15
|
};
|
|
14
16
|
export declare type SidebarItemBase = {
|
|
15
17
|
className?: string;
|
|
16
|
-
customProps?:
|
|
18
|
+
customProps?: {
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
};
|
|
17
21
|
};
|
|
18
22
|
export declare type SidebarItemDoc = SidebarItemBase & {
|
|
19
23
|
type: 'doc' | 'ref';
|
|
@@ -138,8 +142,11 @@ export declare type CategoryMetadataFile = {
|
|
|
138
142
|
collapsible?: boolean;
|
|
139
143
|
className?: string;
|
|
140
144
|
link?: SidebarItemCategoryLinkConfig | null;
|
|
145
|
+
customProps?: {
|
|
146
|
+
[key: string]: unknown;
|
|
147
|
+
};
|
|
141
148
|
};
|
|
142
|
-
export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'unversionedId' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
|
|
149
|
+
export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'unversionedId' | 'title' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
|
|
143
150
|
export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
|
|
144
151
|
export declare type SidebarItemsGeneratorArgs = {
|
|
145
152
|
item: SidebarItemAutogenerated;
|
|
@@ -147,8 +154,9 @@ export declare type SidebarItemsGeneratorArgs = {
|
|
|
147
154
|
docs: SidebarItemsGeneratorDoc[];
|
|
148
155
|
numberPrefixParser: NumberPrefixParser;
|
|
149
156
|
isCategoryIndex: CategoryIndexMatcher;
|
|
150
|
-
categoriesMetadata:
|
|
151
|
-
|
|
157
|
+
categoriesMetadata: {
|
|
158
|
+
[filePath: string]: CategoryMetadataFile;
|
|
159
|
+
};
|
|
152
160
|
};
|
|
153
161
|
export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<NormalizedSidebar>;
|
|
154
162
|
export declare type SidebarItemsGeneratorOptionArgs = {
|
package/lib/sidebars/utils.d.ts
CHANGED
|
@@ -13,8 +13,12 @@ export declare function collectSidebarCategories(sidebar: Sidebar): SidebarItemC
|
|
|
13
13
|
export declare function collectSidebarLinks(sidebar: Sidebar): SidebarItemLink[];
|
|
14
14
|
export declare function collectSidebarDocIds(sidebar: Sidebar): string[];
|
|
15
15
|
export declare function collectSidebarNavigation(sidebar: Sidebar): SidebarNavigationItem[];
|
|
16
|
-
export declare function collectSidebarsDocIds(sidebars: Sidebars):
|
|
17
|
-
|
|
16
|
+
export declare function collectSidebarsDocIds(sidebars: Sidebars): {
|
|
17
|
+
[sidebarId: string]: string[];
|
|
18
|
+
};
|
|
19
|
+
export declare function collectSidebarsNavigations(sidebars: Sidebars): {
|
|
20
|
+
[sidebarId: string]: SidebarNavigationItem[];
|
|
21
|
+
};
|
|
18
22
|
export declare type SidebarNavigation = {
|
|
19
23
|
sidebarName: string | undefined;
|
|
20
24
|
previous: SidebarNavigationItem | undefined;
|
|
@@ -27,17 +31,24 @@ export declare type SidebarsUtils = {
|
|
|
27
31
|
getDocNavigation: (unversionedId: string, versionedId: string, displayedSidebar: string | null | undefined) => SidebarNavigation;
|
|
28
32
|
getCategoryGeneratedIndexList: () => SidebarItemCategoryWithGeneratedIndex[];
|
|
29
33
|
getCategoryGeneratedIndexNavigation: (categoryGeneratedIndexPermalink: string) => SidebarNavigation;
|
|
34
|
+
/**
|
|
35
|
+
* This function may return undefined. This is usually a user mistake, because
|
|
36
|
+
* it means this sidebar will never be displayed; however, we can still use
|
|
37
|
+
* `displayed_sidebar` to make it displayed. Pretty weird but valid use-case
|
|
38
|
+
*/
|
|
30
39
|
getFirstLink: (sidebarId: string) => {
|
|
31
40
|
type: 'doc';
|
|
32
41
|
id: string;
|
|
33
42
|
label: string;
|
|
34
43
|
} | {
|
|
35
44
|
type: 'generated-index';
|
|
36
|
-
|
|
45
|
+
permalink: string;
|
|
37
46
|
label: string;
|
|
38
47
|
} | undefined;
|
|
39
48
|
checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
|
|
40
49
|
};
|
|
41
50
|
export declare function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils;
|
|
42
51
|
export declare function toDocNavigationLink(doc: DocMetadataBase): DocNavLink;
|
|
43
|
-
export declare function toNavigationLink(navigationItem: SidebarNavigationItem | undefined, docsById:
|
|
52
|
+
export declare function toNavigationLink(navigationItem: SidebarNavigationItem | undefined, docsById: {
|
|
53
|
+
[docId: string]: DocMetadataBase;
|
|
54
|
+
}): DocNavLink | undefined;
|
package/lib/sidebars/utils.js
CHANGED
|
@@ -119,10 +119,10 @@ function createSidebarsUtils(sidebars) {
|
|
|
119
119
|
if (!sidebarName) {
|
|
120
120
|
return emptySidebarNavigation();
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
123
|
+
if (!navigationItems) {
|
|
123
124
|
throw new Error(`Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`);
|
|
124
125
|
}
|
|
125
|
-
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
126
126
|
const currentItemIndex = navigationItems.findIndex((item) => {
|
|
127
127
|
if (item.type === 'doc') {
|
|
128
128
|
return item.id === docId;
|
|
@@ -135,8 +135,11 @@ function createSidebarsUtils(sidebars) {
|
|
|
135
135
|
if (currentItemIndex === -1) {
|
|
136
136
|
return { sidebarName, next: undefined, previous: undefined };
|
|
137
137
|
}
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
return {
|
|
139
|
+
sidebarName,
|
|
140
|
+
previous: navigationItems[currentItemIndex - 1],
|
|
141
|
+
next: navigationItems[currentItemIndex + 1],
|
|
142
|
+
};
|
|
140
143
|
}
|
|
141
144
|
function getCategoryGeneratedIndexList() {
|
|
142
145
|
return Object.values(sidebarNameToNavigationItems)
|
|
@@ -158,14 +161,14 @@ function createSidebarsUtils(sidebars) {
|
|
|
158
161
|
item.link?.type === 'generated-index' &&
|
|
159
162
|
item.link.permalink === categoryGeneratedIndexPermalink);
|
|
160
163
|
}
|
|
161
|
-
const sidebarName = Object.entries(sidebarNameToNavigationItems).find(([, navigationItems]) => navigationItems.find(isCurrentCategoryGeneratedIndexItem))
|
|
162
|
-
if (!sidebarName) {
|
|
163
|
-
return emptySidebarNavigation();
|
|
164
|
-
}
|
|
164
|
+
const sidebarName = Object.entries(sidebarNameToNavigationItems).find(([, navigationItems]) => navigationItems.find(isCurrentCategoryGeneratedIndexItem))[0];
|
|
165
165
|
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
166
166
|
const currentItemIndex = navigationItems.findIndex(isCurrentCategoryGeneratedIndexItem);
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
return {
|
|
168
|
+
sidebarName,
|
|
169
|
+
previous: navigationItems[currentItemIndex - 1],
|
|
170
|
+
next: navigationItems[currentItemIndex + 1],
|
|
171
|
+
};
|
|
169
172
|
}
|
|
170
173
|
function checkSidebarsDocIds(validDocIds, sidebarFilePath) {
|
|
171
174
|
const allSidebarDocIds = Object.values(sidebarNameToDocIds).flat();
|
|
@@ -199,7 +202,7 @@ Available document ids are:
|
|
|
199
202
|
else if (item.link?.type === 'generated-index') {
|
|
200
203
|
return {
|
|
201
204
|
type: 'generated-index',
|
|
202
|
-
|
|
205
|
+
permalink: item.link.permalink,
|
|
203
206
|
label: item.label,
|
|
204
207
|
};
|
|
205
208
|
}
|
|
@@ -239,21 +242,14 @@ function toNavigationLink(navigationItem, docsById) {
|
|
|
239
242
|
if (!navigationItem) {
|
|
240
243
|
return undefined;
|
|
241
244
|
}
|
|
242
|
-
if (navigationItem.type === '
|
|
243
|
-
return
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (navigationItem.link.type === 'doc') {
|
|
247
|
-
return toDocNavigationLink(getDocById(navigationItem.link.id));
|
|
248
|
-
}
|
|
249
|
-
else if (navigationItem.link.type === 'generated-index') {
|
|
250
|
-
return {
|
|
245
|
+
if (navigationItem.type === 'category') {
|
|
246
|
+
return navigationItem.link.type === 'doc'
|
|
247
|
+
? toDocNavigationLink(getDocById(navigationItem.link.id))
|
|
248
|
+
: {
|
|
251
249
|
title: navigationItem.label,
|
|
252
250
|
permalink: navigationItem.link.permalink,
|
|
253
251
|
};
|
|
254
|
-
}
|
|
255
|
-
throw new Error('unexpected category link type');
|
|
256
252
|
}
|
|
257
|
-
|
|
253
|
+
return toDocNavigationLink(getDocById(navigationItem.id));
|
|
258
254
|
}
|
|
259
255
|
exports.toNavigationLink = toNavigationLink;
|
|
@@ -5,5 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { NormalizedSidebars, CategoryMetadataFile } from './types';
|
|
8
|
-
export declare function validateSidebars(sidebars:
|
|
8
|
+
export declare function validateSidebars(sidebars: {
|
|
9
|
+
[sidebarId: string]: unknown;
|
|
10
|
+
}): asserts sidebars is NormalizedSidebars;
|
|
9
11
|
export declare function validateCategoryMetadataFile(unsafeContent: unknown): CategoryMetadataFile;
|
|
@@ -130,6 +130,7 @@ const categoryMetadataFileSchema = utils_validation_1.Joi.object({
|
|
|
130
130
|
collapsible: utils_validation_1.Joi.boolean(),
|
|
131
131
|
className: utils_validation_1.Joi.string(),
|
|
132
132
|
link: sidebarItemCategoryLinkSchema,
|
|
133
|
+
customProps: utils_validation_1.Joi.object().unknown(),
|
|
133
134
|
});
|
|
134
135
|
function validateCategoryMetadataFile(unsafeContent) {
|
|
135
136
|
return utils_validation_1.Joi.attempt(unsafeContent, categoryMetadataFileSchema);
|
package/lib/slug.js
CHANGED
|
@@ -33,12 +33,11 @@ function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumbe
|
|
|
33
33
|
}
|
|
34
34
|
function ensureValidSlug(slug) {
|
|
35
35
|
if (!(0, utils_1.isValidPathname)(slug)) {
|
|
36
|
-
throw new Error(`We couldn't compute a valid slug for document with
|
|
36
|
+
throw new Error(`We couldn't compute a valid slug for document with ID "${baseID}" in "${sourceDirName}" directory.
|
|
37
37
|
The slug we computed looks invalid: ${slug}.
|
|
38
|
-
Maybe your slug front matter is incorrect or
|
|
39
|
-
By using
|
|
38
|
+
Maybe your slug front matter is incorrect or there are special characters in the file path?
|
|
39
|
+
By using front matter to set a custom slug, you should be able to fix this error:
|
|
40
40
|
|
|
41
|
-
Example =>
|
|
42
41
|
---
|
|
43
42
|
slug: /my/customDocPath
|
|
44
43
|
---
|
package/lib/translations.js
CHANGED
|
@@ -84,26 +84,24 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
|
84
84
|
description: `The label for category ${category.label} in sidebar ${sidebarName}`,
|
|
85
85
|
},
|
|
86
86
|
]);
|
|
87
|
-
if (category.link) {
|
|
88
|
-
if (category.link.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
]);
|
|
106
|
-
}
|
|
87
|
+
if (category.link?.type === 'generated-index') {
|
|
88
|
+
if (category.link.title) {
|
|
89
|
+
entries.push([
|
|
90
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`,
|
|
91
|
+
{
|
|
92
|
+
message: category.link.title,
|
|
93
|
+
description: `The generated-index page title for category ${category.label} in sidebar ${sidebarName}`,
|
|
94
|
+
},
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
97
|
+
if (category.link.description) {
|
|
98
|
+
entries.push([
|
|
99
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`,
|
|
100
|
+
{
|
|
101
|
+
message: category.link.description,
|
|
102
|
+
description: `The generated-index page description for category ${category.label} in sidebar ${sidebarName}`,
|
|
103
|
+
},
|
|
104
|
+
]);
|
|
107
105
|
}
|
|
108
106
|
}
|
|
109
107
|
return entries;
|
|
@@ -198,7 +196,7 @@ function translateVersion(version, translationFiles) {
|
|
|
198
196
|
const versionTranslations = translationFiles[getVersionFileName(version.versionName)].content;
|
|
199
197
|
return {
|
|
200
198
|
...version,
|
|
201
|
-
versionLabel: versionTranslations['version.label']?.message,
|
|
199
|
+
versionLabel: versionTranslations['version.label']?.message ?? version.versionLabel,
|
|
202
200
|
sidebars: translateSidebars(version, versionTranslations),
|
|
203
201
|
// docs: translateDocs(version.docs, versionTranslations),
|
|
204
202
|
};
|
package/lib/types.d.ts
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
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 } from '@docusaurus/utils';
|
|
9
|
-
import type { BrokenMarkdownLink as IBrokenMarkdownLink, ContentPaths } from '@docusaurus/utils/lib/markdownLinks';
|
|
8
|
+
import type { Tag, FrontMatterTag, BrokenMarkdownLink, ContentPaths } from '@docusaurus/utils';
|
|
10
9
|
import type { VersionBanner } from '@docusaurus/plugin-content-docs';
|
|
11
10
|
export declare type DocFile = {
|
|
12
11
|
contentPath: string;
|
|
@@ -47,7 +46,9 @@ export declare type DocFrontMatter = {
|
|
|
47
46
|
sidebar_label?: string;
|
|
48
47
|
sidebar_position?: number;
|
|
49
48
|
sidebar_class_name?: string;
|
|
50
|
-
sidebar_custom_props?:
|
|
49
|
+
sidebar_custom_props?: {
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
};
|
|
51
52
|
displayed_sidebar?: string | null;
|
|
52
53
|
pagination_label?: string;
|
|
53
54
|
custom_edit_url?: string | null;
|
|
@@ -70,7 +71,9 @@ export declare type DocMetadataBase = LastUpdateData & {
|
|
|
70
71
|
sidebarPosition?: number;
|
|
71
72
|
editUrl?: string | null;
|
|
72
73
|
tags: Tag[];
|
|
73
|
-
frontMatter: DocFrontMatter &
|
|
74
|
+
frontMatter: DocFrontMatter & {
|
|
75
|
+
[key: string]: unknown;
|
|
76
|
+
};
|
|
74
77
|
};
|
|
75
78
|
export declare type DocNavLink = {
|
|
76
79
|
title: string;
|
|
@@ -113,10 +116,10 @@ export declare type LoadedVersion = VersionMetadata & {
|
|
|
113
116
|
export declare type LoadedContent = {
|
|
114
117
|
loadedVersions: LoadedVersion[];
|
|
115
118
|
};
|
|
116
|
-
export declare type
|
|
119
|
+
export declare type DocBrokenMarkdownLink = BrokenMarkdownLink<VersionMetadata>;
|
|
117
120
|
export declare type DocsMarkdownOption = {
|
|
118
121
|
versionsMetadata: VersionMetadata[];
|
|
119
122
|
siteDir: string;
|
|
120
123
|
sourceToPermalink: SourceToPermalink;
|
|
121
|
-
onBrokenMarkdownLink: (brokenMarkdownLink:
|
|
124
|
+
onBrokenMarkdownLink: (brokenMarkdownLink: DocBrokenMarkdownLink) => void;
|
|
122
125
|
};
|
package/lib/versions.js
CHANGED
|
@@ -42,8 +42,8 @@ function ensureValidVersionString(version) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
function ensureValidVersionArray(versionArray) {
|
|
45
|
-
if (!(versionArray
|
|
46
|
-
throw new Error(`The versions file should contain an array of
|
|
45
|
+
if (!Array.isArray(versionArray)) {
|
|
46
|
+
throw new Error(`The versions file should contain an array of version names! Found content: ${JSON.stringify(versionArray)}`);
|
|
47
47
|
}
|
|
48
48
|
versionArray.forEach(ensureValidVersionString);
|
|
49
49
|
}
|
|
@@ -294,7 +294,7 @@ function checkVersionsOptions(availableVersionNames, options) {
|
|
|
294
294
|
*/
|
|
295
295
|
function filterVersions(versionNamesUnfiltered, options) {
|
|
296
296
|
if (options.onlyIncludeVersions) {
|
|
297
|
-
return versionNamesUnfiltered.filter((name) =>
|
|
297
|
+
return versionNamesUnfiltered.filter((name) => options.onlyIncludeVersions.includes(name));
|
|
298
298
|
}
|
|
299
299
|
return versionNamesUnfiltered;
|
|
300
300
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.18",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@docusaurus/core": "2.0.0-beta.
|
|
27
|
-
"@docusaurus/logger": "2.0.0-beta.
|
|
28
|
-
"@docusaurus/mdx-loader": "2.0.0-beta.
|
|
29
|
-
"@docusaurus/utils": "2.0.0-beta.
|
|
30
|
-
"@docusaurus/utils-validation": "2.0.0-beta.
|
|
26
|
+
"@docusaurus/core": "2.0.0-beta.18",
|
|
27
|
+
"@docusaurus/logger": "2.0.0-beta.18",
|
|
28
|
+
"@docusaurus/mdx-loader": "2.0.0-beta.18",
|
|
29
|
+
"@docusaurus/utils": "2.0.0-beta.18",
|
|
30
|
+
"@docusaurus/utils-validation": "2.0.0-beta.18",
|
|
31
31
|
"combine-promises": "^1.1.0",
|
|
32
32
|
"fs-extra": "^10.0.1",
|
|
33
33
|
"import-fresh": "^3.3.0",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"remark-admonitions": "^1.2.1",
|
|
37
37
|
"tslib": "^2.3.1",
|
|
38
38
|
"utility-types": "^3.10.0",
|
|
39
|
-
"webpack": "^5.
|
|
39
|
+
"webpack": "^5.70.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@docusaurus/module-type-aliases": "2.0.0-beta.
|
|
43
|
-
"@docusaurus/types": "2.0.0-beta.
|
|
42
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.18",
|
|
43
|
+
"@docusaurus/types": "2.0.0-beta.18",
|
|
44
44
|
"@types/js-yaml": "^4.0.5",
|
|
45
45
|
"@types/picomatch": "^2.3.0",
|
|
46
46
|
"commander": "^5.1.0",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": ">=14"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "1a945d06993d53376e61bed2c942799fe07dc336"
|
|
60
60
|
}
|
|
@@ -17,14 +17,10 @@ function getCategoryGeneratedIndexMetadata({
|
|
|
17
17
|
}: {
|
|
18
18
|
category: SidebarItemCategoryWithGeneratedIndex;
|
|
19
19
|
sidebarsUtils: SidebarsUtils;
|
|
20
|
-
docsById:
|
|
20
|
+
docsById: {[docId: string]: DocMetadataBase};
|
|
21
21
|
}): CategoryGeneratedIndexMetadata {
|
|
22
22
|
const {sidebarName, previous, next} =
|
|
23
23
|
sidebarsUtils.getCategoryGeneratedIndexNavigation(category.link.permalink);
|
|
24
|
-
if (!sidebarName) {
|
|
25
|
-
throw new Error('unexpected');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
24
|
return {
|
|
29
25
|
title: category.link.title ?? category.label,
|
|
30
26
|
description: category.link.description,
|
|
@@ -32,7 +28,7 @@ function getCategoryGeneratedIndexMetadata({
|
|
|
32
28
|
keywords: category.link.keywords,
|
|
33
29
|
slug: category.link.slug,
|
|
34
30
|
permalink: category.link.permalink,
|
|
35
|
-
sidebar: sidebarName
|
|
31
|
+
sidebar: sidebarName!,
|
|
36
32
|
previous: toNavigationLink(previous, docsById),
|
|
37
33
|
next: toNavigationLink(next, docsById),
|
|
38
34
|
};
|
package/src/cli.ts
CHANGED
|
@@ -47,8 +47,7 @@ async function createVersionedSidebarFile({
|
|
|
47
47
|
versionedSidebarsDir,
|
|
48
48
|
`version-${version}-sidebars.json`,
|
|
49
49
|
);
|
|
50
|
-
await fs.
|
|
51
|
-
await fs.writeFile(
|
|
50
|
+
await fs.outputFile(
|
|
52
51
|
newSidebarFile,
|
|
53
52
|
`${JSON.stringify(sidebars, null, 2)}\n`,
|
|
54
53
|
'utf8',
|
|
@@ -89,7 +88,7 @@ export async function cliDocsVersionCommand(
|
|
|
89
88
|
// Since we are going to create `version-${version}` folder, we need to make
|
|
90
89
|
// sure it's a valid pathname.
|
|
91
90
|
// eslint-disable-next-line no-control-regex
|
|
92
|
-
if (/[<>:"|?*\x00-\x1F]
|
|
91
|
+
if (/[<>:"|?*\x00-\x1F]/.test(version)) {
|
|
93
92
|
throw new Error(
|
|
94
93
|
`${pluginIdLogPrefix}: invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0.`,
|
|
95
94
|
);
|
|
@@ -140,8 +139,7 @@ export async function cliDocsVersionCommand(
|
|
|
140
139
|
|
|
141
140
|
// Update versions.json file.
|
|
142
141
|
versions.unshift(version);
|
|
143
|
-
await fs.
|
|
144
|
-
await fs.writeFile(
|
|
142
|
+
await fs.outputFile(
|
|
145
143
|
versionsJSONFile,
|
|
146
144
|
`${JSON.stringify(versions, null, 2)}\n`,
|
|
147
145
|
);
|
|
@@ -23,11 +23,11 @@ import type {
|
|
|
23
23
|
// ie the docs of that plugin are currently browsed
|
|
24
24
|
// it is useful to support multiple docs plugin instances
|
|
25
25
|
export function getActivePlugin(
|
|
26
|
-
|
|
26
|
+
allPluginData: {[pluginId: string]: GlobalPluginData},
|
|
27
27
|
pathname: string,
|
|
28
28
|
options: GetActivePluginOptions = {},
|
|
29
29
|
): ActivePlugin | undefined {
|
|
30
|
-
const activeEntry = Object.entries(
|
|
30
|
+
const activeEntry = Object.entries(allPluginData)
|
|
31
31
|
// Route sorting: '/android/foo' should match '/android' instead of '/'
|
|
32
32
|
.sort((a, b) => b[1].path.localeCompare(a[1].path))
|
|
33
33
|
.find(
|
|
@@ -46,7 +46,7 @@ export function getActivePlugin(
|
|
|
46
46
|
if (!activePlugin && options.failfast) {
|
|
47
47
|
throw new Error(
|
|
48
48
|
`Can't find active docs plugin for "${pathname}" pathname, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: ${Object.values(
|
|
49
|
-
|
|
49
|
+
allPluginData,
|
|
50
50
|
)
|
|
51
51
|
.map((plugin) => plugin.path)
|
|
52
52
|
.join(', ')}`,
|
package/src/client/index.ts
CHANGED
|
@@ -31,7 +31,7 @@ const StableEmptyObject = {};
|
|
|
31
31
|
// Not using useAllPluginInstancesData() because in blog-only mode, docs hooks
|
|
32
32
|
// are still used by the theme. We need a fail-safe fallback when the docs
|
|
33
33
|
// plugin is not in use
|
|
34
|
-
export const useAllDocsData = ():
|
|
34
|
+
export const useAllDocsData = (): {[pluginId: string]: GlobalPluginData} =>
|
|
35
35
|
useGlobalData()['docusaurus-plugin-content-docs'] ?? StableEmptyObject;
|
|
36
36
|
|
|
37
37
|
export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
|
package/src/deps.d.ts
CHANGED
package/src/docs.ts
CHANGED
|
@@ -34,7 +34,7 @@ import getSlug from './slug';
|
|
|
34
34
|
import {CURRENT_VERSION_NAME} from './constants';
|
|
35
35
|
import {getDocsDirPaths} from './versions';
|
|
36
36
|
import {stripPathNumberPrefixes} from './numberPrefix';
|
|
37
|
-
import {validateDocFrontMatter} from './
|
|
37
|
+
import {validateDocFrontMatter} from './frontMatter';
|
|
38
38
|
import type {SidebarsUtils} from './sidebars/utils';
|
|
39
39
|
import {toDocNavigationLink, toNavigationLink} from './sidebars/utils';
|
|
40
40
|
import type {
|
|
@@ -363,7 +363,7 @@ export function getMainDocId({
|
|
|
363
363
|
doc.unversionedId === firstDocIdOfFirstSidebar,
|
|
364
364
|
)!;
|
|
365
365
|
}
|
|
366
|
-
return docs[0]
|
|
366
|
+
return docs[0]!;
|
|
367
367
|
}
|
|
368
368
|
|
|
369
369
|
return getMainDoc().unversionedId;
|
|
@@ -391,6 +391,10 @@ export const isCategoryIndex: CategoryIndexMatcher = ({
|
|
|
391
391
|
return eligibleDocIndexNames.includes(fileName.toLowerCase());
|
|
392
392
|
};
|
|
393
393
|
|
|
394
|
+
/**
|
|
395
|
+
* `guides/sidebar/autogenerated.md` ->
|
|
396
|
+
* `'autogenerated', '.md', ['sidebar', 'guides']`
|
|
397
|
+
*/
|
|
394
398
|
export function toCategoryIndexMatcherParam({
|
|
395
399
|
source,
|
|
396
400
|
sourceDirName,
|
|
@@ -406,28 +410,6 @@ export function toCategoryIndexMatcherParam({
|
|
|
406
410
|
};
|
|
407
411
|
}
|
|
408
412
|
|
|
409
|
-
/**
|
|
410
|
-
* `guides/sidebar/autogenerated.md` ->
|
|
411
|
-
* `'autogenerated', '.md', ['sidebar', 'guides']`
|
|
412
|
-
*/
|
|
413
|
-
export function splitPath(str: string): {
|
|
414
|
-
/**
|
|
415
|
-
* The list of directories, from lowest level to highest.
|
|
416
|
-
* If there's no dir name, directories is ['.']
|
|
417
|
-
*/
|
|
418
|
-
directories: string[];
|
|
419
|
-
/** The file name, without extension */
|
|
420
|
-
fileName: string;
|
|
421
|
-
/** The extension, with a leading dot */
|
|
422
|
-
extension: string;
|
|
423
|
-
} {
|
|
424
|
-
return {
|
|
425
|
-
fileName: path.parse(str).name,
|
|
426
|
-
extension: path.parse(str).ext,
|
|
427
|
-
directories: path.dirname(str).split(path.sep).reverse(),
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
|
|
431
413
|
// Return both doc ids
|
|
432
414
|
// TODO legacy retro-compatibility due to old versioned sidebars using
|
|
433
415
|
// versioned doc ids ("id" should be removed & "versionedId" should be renamed
|
|
@@ -442,7 +424,7 @@ export function getDocIds(doc: DocMetadataBase): [string, string] {
|
|
|
442
424
|
// to "id")
|
|
443
425
|
export function createDocsByIdIndex<
|
|
444
426
|
Doc extends {id: string; unversionedId: string},
|
|
445
|
-
>(docs: Doc[]):
|
|
427
|
+
>(docs: Doc[]): {[docId: string]: Doc} {
|
|
446
428
|
return Object.fromEntries(
|
|
447
429
|
docs.flatMap((doc) => [
|
|
448
430
|
[doc.unversionedId, doc],
|
|
@@ -25,7 +25,7 @@ const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
|
|
|
25
25
|
hide_table_of_contents: Joi.boolean(),
|
|
26
26
|
keywords: Joi.array().items(Joi.string().required()),
|
|
27
27
|
image: URISchema,
|
|
28
|
-
description: Joi.string().allow(''), // see
|
|
28
|
+
description: Joi.string().allow(''), // see https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
|
|
29
29
|
slug: Joi.string(),
|
|
30
30
|
sidebar_label: Joi.string(),
|
|
31
31
|
sidebar_position: Joi.number(),
|
|
@@ -41,8 +41,8 @@ const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
|
|
|
41
41
|
...FrontMatterTOCHeadingLevels,
|
|
42
42
|
}).unknown();
|
|
43
43
|
|
|
44
|
-
export function validateDocFrontMatter(
|
|
45
|
-
|
|
46
|
-
): DocFrontMatter {
|
|
44
|
+
export function validateDocFrontMatter(frontMatter: {
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
}): DocFrontMatter {
|
|
47
47
|
return validateFrontMatter(frontMatter, DocFrontMatterSchema);
|
|
48
48
|
}
|
package/src/globalData.ts
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import _ from 'lodash';
|
|
9
|
-
import {normalizeUrl} from '@docusaurus/utils';
|
|
10
9
|
import type {Sidebars} from './sidebars/types';
|
|
11
10
|
import {createSidebarsUtils} from './sidebars/utils';
|
|
12
11
|
import type {
|
|
@@ -20,7 +19,7 @@ import type {
|
|
|
20
19
|
GlobalDoc,
|
|
21
20
|
} from '@docusaurus/plugin-content-docs/client';
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
function toGlobalDataDoc(doc: DocMetadata): GlobalDoc {
|
|
24
23
|
return {
|
|
25
24
|
id: doc.unversionedId,
|
|
26
25
|
path: doc.permalink,
|
|
@@ -28,7 +27,7 @@ export function toGlobalDataDoc(doc: DocMetadata): GlobalDoc {
|
|
|
28
27
|
};
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
function toGlobalDataGeneratedIndex(
|
|
32
31
|
doc: CategoryGeneratedIndexMetadata,
|
|
33
32
|
): GlobalDoc {
|
|
34
33
|
return {
|
|
@@ -38,10 +37,10 @@ export function toGlobalDataGeneratedIndex(
|
|
|
38
37
|
};
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
|
|
40
|
+
function toGlobalSidebars(
|
|
42
41
|
sidebars: Sidebars,
|
|
43
42
|
version: LoadedVersion,
|
|
44
|
-
):
|
|
43
|
+
): {[sidebarId: string]: GlobalSidebar} {
|
|
45
44
|
const {getFirstLink} = createSidebarsUtils(sidebars);
|
|
46
45
|
return _.mapValues(sidebars, (sidebar, sidebarId) => {
|
|
47
46
|
const firstLink = getFirstLink(sidebarId);
|
|
@@ -52,7 +51,7 @@ export function toGlobalSidebars(
|
|
|
52
51
|
link: {
|
|
53
52
|
path:
|
|
54
53
|
firstLink.type === 'generated-index'
|
|
55
|
-
?
|
|
54
|
+
? firstLink.permalink
|
|
56
55
|
: version.docs.find(
|
|
57
56
|
(doc) =>
|
|
58
57
|
doc.id === firstLink.id || doc.unversionedId === firstLink.id,
|
package/src/index.ts
CHANGED
|
@@ -56,7 +56,6 @@ import type {
|
|
|
56
56
|
PropTagsListPage,
|
|
57
57
|
PluginOptions,
|
|
58
58
|
} from '@docusaurus/plugin-content-docs';
|
|
59
|
-
import type {GlobalPluginData} from '@docusaurus/plugin-content-docs/client';
|
|
60
59
|
import {createSidebarsUtils} from './sidebars/utils';
|
|
61
60
|
import {getCategoryGeneratedIndexMetadataList} from './categoryGeneratedIndex';
|
|
62
61
|
|
|
@@ -293,7 +292,7 @@ export default async function pluginContentDocs(
|
|
|
293
292
|
// TODO tags should be a sub route of the version route
|
|
294
293
|
await Promise.all(loadedVersions.map(createVersionTagsRoutes));
|
|
295
294
|
|
|
296
|
-
setGlobalData
|
|
295
|
+
setGlobalData({
|
|
297
296
|
path: normalizeUrl([baseUrl, options.routeBasePath]),
|
|
298
297
|
versions: loadedVersions.map(toGlobalDataVersion),
|
|
299
298
|
breadcrumbs,
|