@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/src/sidebars/utils.ts
CHANGED
|
@@ -20,7 +20,7 @@ import type {
|
|
|
20
20
|
} from './types';
|
|
21
21
|
|
|
22
22
|
import _ from 'lodash';
|
|
23
|
-
import {
|
|
23
|
+
import {toMessageRelativeFilePath} from '@docusaurus/utils';
|
|
24
24
|
import type {DocMetadataBase, DocNavLink} from '../types';
|
|
25
25
|
|
|
26
26
|
export function isCategoriesShorthand(
|
|
@@ -107,15 +107,15 @@ export function collectSidebarNavigation(
|
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
export function collectSidebarsDocIds(
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
export function collectSidebarsDocIds(sidebars: Sidebars): {
|
|
111
|
+
[sidebarId: string]: string[];
|
|
112
|
+
} {
|
|
113
113
|
return _.mapValues(sidebars, collectSidebarDocIds);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
export function collectSidebarsNavigations(
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
export function collectSidebarsNavigations(sidebars: Sidebars): {
|
|
117
|
+
[sidebarId: string]: SidebarNavigationItem[];
|
|
118
|
+
} {
|
|
119
119
|
return _.mapValues(sidebars, collectSidebarNavigation);
|
|
120
120
|
}
|
|
121
121
|
|
|
@@ -139,6 +139,11 @@ export type SidebarsUtils = {
|
|
|
139
139
|
getCategoryGeneratedIndexNavigation: (
|
|
140
140
|
categoryGeneratedIndexPermalink: string,
|
|
141
141
|
) => SidebarNavigation;
|
|
142
|
+
/**
|
|
143
|
+
* This function may return undefined. This is usually a user mistake, because
|
|
144
|
+
* it means this sidebar will never be displayed; however, we can still use
|
|
145
|
+
* `displayed_sidebar` to make it displayed. Pretty weird but valid use-case
|
|
146
|
+
*/
|
|
142
147
|
getFirstLink: (sidebarId: string) =>
|
|
143
148
|
| {
|
|
144
149
|
type: 'doc';
|
|
@@ -147,7 +152,7 @@ export type SidebarsUtils = {
|
|
|
147
152
|
}
|
|
148
153
|
| {
|
|
149
154
|
type: 'generated-index';
|
|
150
|
-
|
|
155
|
+
permalink: string;
|
|
151
156
|
label: string;
|
|
152
157
|
}
|
|
153
158
|
| undefined;
|
|
@@ -201,12 +206,12 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
|
|
|
201
206
|
if (!sidebarName) {
|
|
202
207
|
return emptySidebarNavigation();
|
|
203
208
|
}
|
|
204
|
-
|
|
209
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
210
|
+
if (!navigationItems) {
|
|
205
211
|
throw new Error(
|
|
206
212
|
`Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`,
|
|
207
213
|
);
|
|
208
214
|
}
|
|
209
|
-
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
210
215
|
const currentItemIndex = navigationItems.findIndex((item) => {
|
|
211
216
|
if (item.type === 'doc') {
|
|
212
217
|
return item.id === docId;
|
|
@@ -220,11 +225,11 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
|
|
|
220
225
|
return {sidebarName, next: undefined, previous: undefined};
|
|
221
226
|
}
|
|
222
227
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
currentItemIndex,
|
|
226
|
-
|
|
227
|
-
|
|
228
|
+
return {
|
|
229
|
+
sidebarName,
|
|
230
|
+
previous: navigationItems[currentItemIndex - 1],
|
|
231
|
+
next: navigationItems[currentItemIndex + 1],
|
|
232
|
+
};
|
|
228
233
|
}
|
|
229
234
|
|
|
230
235
|
function getCategoryGeneratedIndexList(): SidebarItemCategoryWithGeneratedIndex[] {
|
|
@@ -258,20 +263,16 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
|
|
|
258
263
|
const sidebarName = Object.entries(sidebarNameToNavigationItems).find(
|
|
259
264
|
([, navigationItems]) =>
|
|
260
265
|
navigationItems.find(isCurrentCategoryGeneratedIndexItem),
|
|
261
|
-
)
|
|
262
|
-
|
|
263
|
-
if (!sidebarName) {
|
|
264
|
-
return emptySidebarNavigation();
|
|
265
|
-
}
|
|
266
|
-
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
266
|
+
)![0];
|
|
267
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName]!;
|
|
267
268
|
const currentItemIndex = navigationItems.findIndex(
|
|
268
269
|
isCurrentCategoryGeneratedIndexItem,
|
|
269
270
|
);
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
currentItemIndex,
|
|
273
|
-
|
|
274
|
-
|
|
271
|
+
return {
|
|
272
|
+
sidebarName,
|
|
273
|
+
previous: navigationItems[currentItemIndex - 1],
|
|
274
|
+
next: navigationItems[currentItemIndex + 1],
|
|
275
|
+
};
|
|
275
276
|
}
|
|
276
277
|
|
|
277
278
|
function checkSidebarsDocIds(validDocIds: string[], sidebarFilePath: string) {
|
|
@@ -299,7 +300,7 @@ Available document ids are:
|
|
|
299
300
|
}
|
|
300
301
|
| {
|
|
301
302
|
type: 'generated-index';
|
|
302
|
-
|
|
303
|
+
permalink: string;
|
|
303
304
|
label: string;
|
|
304
305
|
}
|
|
305
306
|
| undefined {
|
|
@@ -320,7 +321,7 @@ Available document ids are:
|
|
|
320
321
|
} else if (item.link?.type === 'generated-index') {
|
|
321
322
|
return {
|
|
322
323
|
type: 'generated-index',
|
|
323
|
-
|
|
324
|
+
permalink: item.link.permalink,
|
|
324
325
|
label: item.label,
|
|
325
326
|
};
|
|
326
327
|
}
|
|
@@ -341,7 +342,7 @@ Available document ids are:
|
|
|
341
342
|
getCategoryGeneratedIndexList,
|
|
342
343
|
getCategoryGeneratedIndexNavigation,
|
|
343
344
|
checkSidebarsDocIds,
|
|
344
|
-
getFirstLink: (id) => getFirstLink(sidebars[id]),
|
|
345
|
+
getFirstLink: (id) => getFirstLink(sidebars[id]!),
|
|
345
346
|
};
|
|
346
347
|
}
|
|
347
348
|
|
|
@@ -359,7 +360,7 @@ export function toDocNavigationLink(doc: DocMetadataBase): DocNavLink {
|
|
|
359
360
|
|
|
360
361
|
export function toNavigationLink(
|
|
361
362
|
navigationItem: SidebarNavigationItem | undefined,
|
|
362
|
-
docsById:
|
|
363
|
+
docsById: {[docId: string]: DocMetadataBase},
|
|
363
364
|
): DocNavLink | undefined {
|
|
364
365
|
function getDocById(docId: string) {
|
|
365
366
|
const doc = docsById[docId];
|
|
@@ -375,18 +376,13 @@ export function toNavigationLink(
|
|
|
375
376
|
return undefined;
|
|
376
377
|
}
|
|
377
378
|
|
|
378
|
-
if (navigationItem.type === '
|
|
379
|
-
return
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
title: navigationItem.label,
|
|
386
|
-
permalink: navigationItem.link.permalink,
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
throw new Error('unexpected category link type');
|
|
379
|
+
if (navigationItem.type === 'category') {
|
|
380
|
+
return navigationItem.link.type === 'doc'
|
|
381
|
+
? toDocNavigationLink(getDocById(navigationItem.link.id))
|
|
382
|
+
: {
|
|
383
|
+
title: navigationItem.label,
|
|
384
|
+
permalink: navigationItem.link.permalink,
|
|
385
|
+
};
|
|
390
386
|
}
|
|
391
|
-
|
|
387
|
+
return toDocNavigationLink(getDocById(navigationItem.id));
|
|
392
388
|
}
|
|
@@ -149,9 +149,9 @@ function validateSidebarItem(
|
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
export function validateSidebars(
|
|
153
|
-
|
|
154
|
-
): asserts sidebars is NormalizedSidebars {
|
|
152
|
+
export function validateSidebars(sidebars: {
|
|
153
|
+
[sidebarId: string]: unknown;
|
|
154
|
+
}): asserts sidebars is NormalizedSidebars {
|
|
155
155
|
Object.values(sidebars as NormalizedSidebars).forEach((sidebar) => {
|
|
156
156
|
sidebar.forEach(validateSidebarItem);
|
|
157
157
|
});
|
|
@@ -164,6 +164,7 @@ const categoryMetadataFileSchema = Joi.object<CategoryMetadataFile>({
|
|
|
164
164
|
collapsible: Joi.boolean(),
|
|
165
165
|
className: Joi.string(),
|
|
166
166
|
link: sidebarItemCategoryLinkSchema,
|
|
167
|
+
customProps: Joi.object().unknown(),
|
|
167
168
|
});
|
|
168
169
|
|
|
169
170
|
export function validateCategoryMetadataFile(
|
package/src/slug.ts
CHANGED
|
@@ -63,12 +63,11 @@ export default function getSlug({
|
|
|
63
63
|
function ensureValidSlug(slug: string): string {
|
|
64
64
|
if (!isValidPathname(slug)) {
|
|
65
65
|
throw new Error(
|
|
66
|
-
`We couldn't compute a valid slug for document with
|
|
66
|
+
`We couldn't compute a valid slug for document with ID "${baseID}" in "${sourceDirName}" directory.
|
|
67
67
|
The slug we computed looks invalid: ${slug}.
|
|
68
|
-
Maybe your slug front matter is incorrect or
|
|
69
|
-
By using
|
|
68
|
+
Maybe your slug front matter is incorrect or there are special characters in the file path?
|
|
69
|
+
By using front matter to set a custom slug, you should be able to fix this error:
|
|
70
70
|
|
|
71
|
-
Example =>
|
|
72
71
|
---
|
|
73
72
|
slug: /my/customDocPath
|
|
74
73
|
---
|
package/src/translations.ts
CHANGED
|
@@ -118,26 +118,24 @@ function getSidebarTranslationFileContent(
|
|
|
118
118
|
},
|
|
119
119
|
]);
|
|
120
120
|
|
|
121
|
-
if (category.link) {
|
|
122
|
-
if (category.link.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
]);
|
|
140
|
-
}
|
|
121
|
+
if (category.link?.type === 'generated-index') {
|
|
122
|
+
if (category.link.title) {
|
|
123
|
+
entries.push([
|
|
124
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`,
|
|
125
|
+
{
|
|
126
|
+
message: category.link.title,
|
|
127
|
+
description: `The generated-index page title for category ${category.label} in sidebar ${sidebarName}`,
|
|
128
|
+
},
|
|
129
|
+
]);
|
|
130
|
+
}
|
|
131
|
+
if (category.link.description) {
|
|
132
|
+
entries.push([
|
|
133
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`,
|
|
134
|
+
{
|
|
135
|
+
message: category.link.description,
|
|
136
|
+
description: `The generated-index page description for category ${category.label} in sidebar ${sidebarName}`,
|
|
137
|
+
},
|
|
138
|
+
]);
|
|
141
139
|
}
|
|
142
140
|
}
|
|
143
141
|
|
|
@@ -271,13 +269,14 @@ function getVersionTranslationFiles(version: LoadedVersion): TranslationFiles {
|
|
|
271
269
|
}
|
|
272
270
|
function translateVersion(
|
|
273
271
|
version: LoadedVersion,
|
|
274
|
-
translationFiles:
|
|
272
|
+
translationFiles: {[fileName: string]: TranslationFile},
|
|
275
273
|
): LoadedVersion {
|
|
276
274
|
const versionTranslations =
|
|
277
|
-
translationFiles[getVersionFileName(version.versionName)]
|
|
275
|
+
translationFiles[getVersionFileName(version.versionName)]!.content;
|
|
278
276
|
return {
|
|
279
277
|
...version,
|
|
280
|
-
versionLabel:
|
|
278
|
+
versionLabel:
|
|
279
|
+
versionTranslations['version.label']?.message ?? version.versionLabel,
|
|
281
280
|
sidebars: translateSidebars(version, versionTranslations),
|
|
282
281
|
// docs: translateDocs(version.docs, versionTranslations),
|
|
283
282
|
};
|
|
@@ -290,7 +289,7 @@ function getVersionsTranslationFiles(
|
|
|
290
289
|
}
|
|
291
290
|
function translateVersions(
|
|
292
291
|
versions: LoadedVersion[],
|
|
293
|
-
translationFiles:
|
|
292
|
+
translationFiles: {[fileName: string]: TranslationFile},
|
|
294
293
|
): LoadedVersion[] {
|
|
295
294
|
return versions.map((version) => translateVersion(version, translationFiles));
|
|
296
295
|
}
|
|
@@ -304,7 +303,7 @@ export function translateLoadedContent(
|
|
|
304
303
|
loadedContent: LoadedContent,
|
|
305
304
|
translationFiles: TranslationFile[],
|
|
306
305
|
): LoadedContent {
|
|
307
|
-
const translationFilesMap:
|
|
306
|
+
const translationFilesMap: {[fileName: string]: TranslationFile} = _.keyBy(
|
|
308
307
|
translationFiles,
|
|
309
308
|
(f) => f.path,
|
|
310
309
|
);
|
package/src/types.ts
CHANGED
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
/// <reference types="@docusaurus/module-type-aliases" />
|
|
9
9
|
|
|
10
10
|
import type {Sidebars} from './sidebars/types';
|
|
11
|
-
import type {Tag, FrontMatterTag} from '@docusaurus/utils';
|
|
12
11
|
import type {
|
|
13
|
-
|
|
12
|
+
Tag,
|
|
13
|
+
FrontMatterTag,
|
|
14
|
+
BrokenMarkdownLink,
|
|
14
15
|
ContentPaths,
|
|
15
|
-
} from '@docusaurus/utils
|
|
16
|
+
} from '@docusaurus/utils';
|
|
16
17
|
import type {VersionBanner} from '@docusaurus/plugin-content-docs';
|
|
17
18
|
|
|
18
19
|
export type DocFile = {
|
|
@@ -58,7 +59,7 @@ export type DocFrontMatter = {
|
|
|
58
59
|
sidebar_label?: string;
|
|
59
60
|
sidebar_position?: number;
|
|
60
61
|
sidebar_class_name?: string;
|
|
61
|
-
sidebar_custom_props?:
|
|
62
|
+
sidebar_custom_props?: {[key: string]: unknown};
|
|
62
63
|
displayed_sidebar?: string | null;
|
|
63
64
|
pagination_label?: string;
|
|
64
65
|
custom_edit_url?: string | null;
|
|
@@ -82,7 +83,7 @@ export type DocMetadataBase = LastUpdateData & {
|
|
|
82
83
|
sidebarPosition?: number;
|
|
83
84
|
editUrl?: string | null;
|
|
84
85
|
tags: Tag[];
|
|
85
|
-
frontMatter: DocFrontMatter &
|
|
86
|
+
frontMatter: DocFrontMatter & {[key: string]: unknown};
|
|
86
87
|
};
|
|
87
88
|
|
|
88
89
|
export type DocNavLink = {
|
|
@@ -133,11 +134,11 @@ export type LoadedContent = {
|
|
|
133
134
|
loadedVersions: LoadedVersion[];
|
|
134
135
|
};
|
|
135
136
|
|
|
136
|
-
export type
|
|
137
|
+
export type DocBrokenMarkdownLink = BrokenMarkdownLink<VersionMetadata>;
|
|
137
138
|
|
|
138
139
|
export type DocsMarkdownOption = {
|
|
139
140
|
versionsMetadata: VersionMetadata[];
|
|
140
141
|
siteDir: string;
|
|
141
142
|
sourceToPermalink: SourceToPermalink;
|
|
142
|
-
onBrokenMarkdownLink: (brokenMarkdownLink:
|
|
143
|
+
onBrokenMarkdownLink: (brokenMarkdownLink: DocBrokenMarkdownLink) => void;
|
|
143
144
|
};
|
package/src/versions.ts
CHANGED
|
@@ -74,9 +74,9 @@ function ensureValidVersionString(version: unknown): asserts version is string {
|
|
|
74
74
|
function ensureValidVersionArray(
|
|
75
75
|
versionArray: unknown,
|
|
76
76
|
): asserts versionArray is string[] {
|
|
77
|
-
if (!(versionArray
|
|
77
|
+
if (!Array.isArray(versionArray)) {
|
|
78
78
|
throw new Error(
|
|
79
|
-
`The versions file should contain an array of
|
|
79
|
+
`The versions file should contain an array of version names! Found content: ${JSON.stringify(
|
|
80
80
|
versionArray,
|
|
81
81
|
)}`,
|
|
82
82
|
);
|
|
@@ -464,11 +464,11 @@ Please set the docs "sidebarPath" field in your config file to:
|
|
|
464
464
|
// "last version" is not a very good concept nor api surface
|
|
465
465
|
function getDefaultLastVersionName(versionNames: string[]) {
|
|
466
466
|
if (versionNames.length === 1) {
|
|
467
|
-
return versionNames[0]
|
|
467
|
+
return versionNames[0]!;
|
|
468
468
|
}
|
|
469
469
|
return versionNames.filter(
|
|
470
470
|
(versionName) => versionName !== CURRENT_VERSION_NAME,
|
|
471
|
-
)[0]
|
|
471
|
+
)[0]!;
|
|
472
472
|
}
|
|
473
473
|
|
|
474
474
|
function checkVersionsOptions(
|
|
@@ -537,7 +537,7 @@ export function filterVersions(
|
|
|
537
537
|
): string[] {
|
|
538
538
|
if (options.onlyIncludeVersions) {
|
|
539
539
|
return versionNamesUnfiltered.filter((name) =>
|
|
540
|
-
|
|
540
|
+
options.onlyIncludeVersions!.includes(name),
|
|
541
541
|
);
|
|
542
542
|
}
|
|
543
543
|
return versionNamesUnfiltered;
|