@docusaurus/plugin-content-docs 0.0.0-4523 → 0.0.0-4527
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 +8 -6
- package/lib/client/docsClientUtils.js +2 -2
- package/lib/client/globalDataHooks.js +4 -3
- package/lib/docs.d.ts +2 -1
- package/lib/docs.js +17 -15
- package/lib/index.js +1 -1
- package/lib/lastUpdate.js +6 -5
- package/lib/numberPrefix.js +7 -6
- package/lib/options.js +3 -2
- package/lib/routes.js +4 -2
- package/lib/sidebars/generator.js +20 -17
- package/lib/sidebars/index.d.ts +2 -2
- package/lib/sidebars/index.js +6 -6
- package/lib/sidebars/processor.js +6 -3
- package/lib/sidebars/utils.js +46 -54
- package/lib/sidebars/validation.js +7 -4
- package/lib/slug.js +6 -8
- package/lib/translations.js +7 -7
- package/lib/versions.js +11 -21
- package/package.json +9 -9
- package/src/cli.ts +9 -7
- package/src/client/docsClientUtils.ts +2 -2
- package/src/client/globalDataHooks.ts +4 -3
- package/src/docs.ts +17 -13
- package/src/index.ts +1 -1
- package/src/lastUpdate.ts +5 -5
- package/src/numberPrefix.ts +7 -6
- package/src/options.ts +3 -2
- package/src/plugin-content-docs.d.ts +2 -1
- package/src/routes.ts +4 -2
- package/src/sidebars/generator.ts +25 -19
- package/src/sidebars/index.ts +9 -9
- package/src/sidebars/processor.ts +6 -3
- package/src/sidebars/types.ts +2 -1
- package/src/sidebars/utils.ts +57 -61
- package/src/sidebars/validation.ts +7 -4
- package/src/slug.ts +9 -10
- package/src/translations.ts +7 -6
- package/src/versions.ts +13 -19
package/src/sidebars/utils.ts
CHANGED
|
@@ -16,7 +16,6 @@ import type {
|
|
|
16
16
|
SidebarCategoriesShorthand,
|
|
17
17
|
SidebarItemConfig,
|
|
18
18
|
SidebarItemCategoryWithGeneratedIndex,
|
|
19
|
-
SidebarItemCategoryWithLink,
|
|
20
19
|
SidebarNavigationItem,
|
|
21
20
|
} from './types';
|
|
22
21
|
|
|
@@ -46,8 +45,11 @@ export function transformSidebarItems(
|
|
|
46
45
|
return sidebar.map(transformRecursive);
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Flatten sidebar items into a single flat array (containing categories/docs on
|
|
50
|
+
* the same level). Order matters (useful for next/prev nav), top categories
|
|
51
|
+
* appear before their child elements
|
|
52
|
+
*/
|
|
51
53
|
function flattenSidebarItems(items: SidebarItem[]): SidebarItem[] {
|
|
52
54
|
function flattenRecursive(item: SidebarItem): SidebarItem[] {
|
|
53
55
|
return item.type === 'category'
|
|
@@ -196,34 +198,33 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
|
|
|
196
198
|
sidebarName = getSidebarNameByDocId(docId);
|
|
197
199
|
}
|
|
198
200
|
|
|
199
|
-
if (sidebarName) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
201
|
+
if (!sidebarName) {
|
|
202
|
+
return emptySidebarNavigation();
|
|
203
|
+
}
|
|
204
|
+
if (!sidebarNameToNavigationItems[sidebarName]) {
|
|
205
|
+
throw new Error(
|
|
206
|
+
`Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`,
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
210
|
+
const currentItemIndex = navigationItems.findIndex((item) => {
|
|
211
|
+
if (item.type === 'doc') {
|
|
212
|
+
return item.id === docId;
|
|
204
213
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (item.type === 'doc') {
|
|
208
|
-
return item.id === docId;
|
|
209
|
-
}
|
|
210
|
-
if (item.type === 'category' && item.link.type === 'doc') {
|
|
211
|
-
return item.link.id === docId;
|
|
212
|
-
}
|
|
213
|
-
return false;
|
|
214
|
-
});
|
|
215
|
-
if (currentItemIndex === -1) {
|
|
216
|
-
return {sidebarName, next: undefined, previous: undefined};
|
|
214
|
+
if (item.type === 'category' && item.link.type === 'doc') {
|
|
215
|
+
return item.link.id === docId;
|
|
217
216
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
);
|
|
223
|
-
return {sidebarName, previous, next};
|
|
224
|
-
} else {
|
|
225
|
-
return emptySidebarNavigation();
|
|
217
|
+
return false;
|
|
218
|
+
});
|
|
219
|
+
if (currentItemIndex === -1) {
|
|
220
|
+
return {sidebarName, next: undefined, previous: undefined};
|
|
226
221
|
}
|
|
222
|
+
|
|
223
|
+
const {previous, next} = getElementsAround(
|
|
224
|
+
navigationItems,
|
|
225
|
+
currentItemIndex,
|
|
226
|
+
);
|
|
227
|
+
return {sidebarName, previous, next};
|
|
227
228
|
}
|
|
228
229
|
|
|
229
230
|
function getCategoryGeneratedIndexList(): SidebarItemCategoryWithGeneratedIndex[] {
|
|
@@ -237,8 +238,10 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
|
|
|
237
238
|
});
|
|
238
239
|
}
|
|
239
240
|
|
|
240
|
-
|
|
241
|
-
|
|
241
|
+
/**
|
|
242
|
+
* We identity the category generated index by its permalink (should be
|
|
243
|
+
* unique). More reliable than using object identity
|
|
244
|
+
*/
|
|
242
245
|
function getCategoryGeneratedIndexNavigation(
|
|
243
246
|
categoryGeneratedIndexPermalink: string,
|
|
244
247
|
): SidebarNavigation {
|
|
@@ -257,19 +260,18 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
|
|
|
257
260
|
navigationItems.find(isCurrentCategoryGeneratedIndexItem),
|
|
258
261
|
)?.[0];
|
|
259
262
|
|
|
260
|
-
if (sidebarName) {
|
|
261
|
-
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
262
|
-
const currentItemIndex = navigationItems.findIndex(
|
|
263
|
-
isCurrentCategoryGeneratedIndexItem,
|
|
264
|
-
);
|
|
265
|
-
const {previous, next} = getElementsAround(
|
|
266
|
-
navigationItems,
|
|
267
|
-
currentItemIndex,
|
|
268
|
-
);
|
|
269
|
-
return {sidebarName, previous, next};
|
|
270
|
-
} else {
|
|
263
|
+
if (!sidebarName) {
|
|
271
264
|
return emptySidebarNavigation();
|
|
272
265
|
}
|
|
266
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
267
|
+
const currentItemIndex = navigationItems.findIndex(
|
|
268
|
+
isCurrentCategoryGeneratedIndexItem,
|
|
269
|
+
);
|
|
270
|
+
const {previous, next} = getElementsAround(
|
|
271
|
+
navigationItems,
|
|
272
|
+
currentItemIndex,
|
|
273
|
+
);
|
|
274
|
+
return {sidebarName, previous, next};
|
|
273
275
|
}
|
|
274
276
|
|
|
275
277
|
function checkSidebarsDocIds(validDocIds: string[], sidebarFilePath: string) {
|
|
@@ -322,11 +324,10 @@ Available document ids are:
|
|
|
322
324
|
slug: item.link.slug,
|
|
323
325
|
label: item.label,
|
|
324
326
|
};
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
327
|
+
}
|
|
328
|
+
const firstSubItem = getFirstLink(item.items);
|
|
329
|
+
if (firstSubItem) {
|
|
330
|
+
return firstSubItem;
|
|
330
331
|
}
|
|
331
332
|
}
|
|
332
333
|
}
|
|
@@ -371,18 +372,6 @@ export function toNavigationLink(
|
|
|
371
372
|
return doc;
|
|
372
373
|
}
|
|
373
374
|
|
|
374
|
-
function handleCategory(category: SidebarItemCategoryWithLink): DocNavLink {
|
|
375
|
-
if (category.link.type === 'doc') {
|
|
376
|
-
return toDocNavigationLink(getDocById(category.link.id));
|
|
377
|
-
} else if (category.link.type === 'generated-index') {
|
|
378
|
-
return {
|
|
379
|
-
title: category.label,
|
|
380
|
-
permalink: category.link.permalink,
|
|
381
|
-
};
|
|
382
|
-
} else {
|
|
383
|
-
throw new Error('unexpected category link type');
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
375
|
if (!navigationItem) {
|
|
387
376
|
return undefined;
|
|
388
377
|
}
|
|
@@ -390,8 +379,15 @@ export function toNavigationLink(
|
|
|
390
379
|
if (navigationItem.type === 'doc') {
|
|
391
380
|
return toDocNavigationLink(getDocById(navigationItem.id));
|
|
392
381
|
} else if (navigationItem.type === 'category') {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
382
|
+
if (navigationItem.link.type === 'doc') {
|
|
383
|
+
return toDocNavigationLink(getDocById(navigationItem.link.id));
|
|
384
|
+
} else if (navigationItem.link.type === 'generated-index') {
|
|
385
|
+
return {
|
|
386
|
+
title: navigationItem.label,
|
|
387
|
+
permalink: navigationItem.link.permalink,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
throw new Error('unexpected category link type');
|
|
396
391
|
}
|
|
392
|
+
throw new Error('unexpected navigation item');
|
|
397
393
|
}
|
|
@@ -23,7 +23,8 @@ import {isCategoriesShorthand} from './utils';
|
|
|
23
23
|
import type {CategoryMetadataFile} from './generator';
|
|
24
24
|
|
|
25
25
|
// NOTE: we don't add any default values during validation on purpose!
|
|
26
|
-
// Config types are exposed to users for typechecking and we use the same type
|
|
26
|
+
// Config types are exposed to users for typechecking and we use the same type
|
|
27
|
+
// in normalization
|
|
27
28
|
|
|
28
29
|
const sidebarItemBaseSchema = Joi.object<SidebarItemBase>({
|
|
29
30
|
className: Joi.string(),
|
|
@@ -35,7 +36,7 @@ const sidebarItemAutogeneratedSchema =
|
|
|
35
36
|
type: 'autogenerated',
|
|
36
37
|
dirName: Joi.string()
|
|
37
38
|
.required()
|
|
38
|
-
.pattern(/^[^/](
|
|
39
|
+
.pattern(/^[^/](?:.*[^/])?$/)
|
|
39
40
|
.message(
|
|
40
41
|
'"dirName" must be a dir path relative to the docs folder root, and should not start or end with slash',
|
|
41
42
|
),
|
|
@@ -71,7 +72,8 @@ const sidebarItemCategoryLinkSchema = Joi.object<SidebarItemCategoryLink>()
|
|
|
71
72
|
then: Joi.object<SidebarItemCategoryLinkGeneratedIndex>({
|
|
72
73
|
type: 'generated-index',
|
|
73
74
|
slug: Joi.string().optional(),
|
|
74
|
-
//
|
|
75
|
+
// This one is not in the user config, only in the normalized version
|
|
76
|
+
// permalink: Joi.string().optional(),
|
|
75
77
|
title: Joi.string().optional(),
|
|
76
78
|
description: Joi.string().optional(),
|
|
77
79
|
image: Joi.string().optional(),
|
|
@@ -132,7 +134,8 @@ function validateSidebarItem(item: unknown): asserts item is SidebarItemConfig {
|
|
|
132
134
|
return;
|
|
133
135
|
}
|
|
134
136
|
// TODO: remove once with proper Joi support
|
|
135
|
-
// Because we can't use Joi to validate nested items (see above), we do it
|
|
137
|
+
// Because we can't use Joi to validate nested items (see above), we do it
|
|
138
|
+
// manually
|
|
136
139
|
if (isCategoriesShorthand(item as SidebarItemConfig)) {
|
|
137
140
|
Object.values(item as SidebarCategoriesShorthand).forEach((category) =>
|
|
138
141
|
category.forEach(validateSidebarItem),
|
package/src/slug.ts
CHANGED
|
@@ -48,17 +48,16 @@ export default function getSlug({
|
|
|
48
48
|
function computeSlug(): string {
|
|
49
49
|
if (frontMatterSlug?.startsWith('/')) {
|
|
50
50
|
return frontMatterSlug;
|
|
51
|
-
} else {
|
|
52
|
-
const dirNameSlug = getDirNameSlug();
|
|
53
|
-
if (
|
|
54
|
-
!frontMatterSlug &&
|
|
55
|
-
isCategoryIndex(toCategoryIndexMatcherParam({source, sourceDirName}))
|
|
56
|
-
) {
|
|
57
|
-
return dirNameSlug;
|
|
58
|
-
}
|
|
59
|
-
const baseSlug = frontMatterSlug || baseID;
|
|
60
|
-
return resolvePathname(baseSlug, getDirNameSlug());
|
|
61
51
|
}
|
|
52
|
+
const dirNameSlug = getDirNameSlug();
|
|
53
|
+
if (
|
|
54
|
+
!frontMatterSlug &&
|
|
55
|
+
isCategoryIndex(toCategoryIndexMatcherParam({source, sourceDirName}))
|
|
56
|
+
) {
|
|
57
|
+
return dirNameSlug;
|
|
58
|
+
}
|
|
59
|
+
const baseSlug = frontMatterSlug || baseID;
|
|
60
|
+
return resolvePathname(baseSlug, getDirNameSlug());
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
function ensureValidSlug(slug: string): string {
|
package/src/translations.ts
CHANGED
|
@@ -31,11 +31,10 @@ import {CURRENT_VERSION_NAME} from './constants';
|
|
|
31
31
|
function getVersionFileName(versionName: string): string {
|
|
32
32
|
if (versionName === CURRENT_VERSION_NAME) {
|
|
33
33
|
return versionName;
|
|
34
|
-
} else {
|
|
35
|
-
// I don't like this "version-" prefix,
|
|
36
|
-
// but it's for consistency with site/versioned_docs
|
|
37
|
-
return `version-${versionName}`;
|
|
38
34
|
}
|
|
35
|
+
// I don't like this "version-" prefix,
|
|
36
|
+
// but it's for consistency with site/versioned_docs
|
|
37
|
+
return `version-${versionName}`;
|
|
39
38
|
}
|
|
40
39
|
|
|
41
40
|
// TODO legacy, the sidebar name is like "version-2.0.0-alpha.66/docs"
|
|
@@ -68,7 +67,8 @@ function getDocTranslations(doc: DocMetadata): TranslationFileContent {
|
|
|
68
67
|
? {
|
|
69
68
|
[`${doc.unversionedId}.sidebar_label`]: {
|
|
70
69
|
message: doc.sidebar_label,
|
|
71
|
-
description:
|
|
70
|
+
description:
|
|
71
|
+
`The sidebar label for doc with id=${doc.unversionedId}`,
|
|
72
72
|
},
|
|
73
73
|
}
|
|
74
74
|
: undefined),
|
|
@@ -253,7 +253,8 @@ function getVersionTranslationFiles(version: LoadedVersion): TranslationFiles {
|
|
|
253
253
|
const sidebarsTranslations: TranslationFileContent =
|
|
254
254
|
getSidebarsTranslations(version);
|
|
255
255
|
|
|
256
|
-
// const docsTranslations: TranslationFileContent =
|
|
256
|
+
// const docsTranslations: TranslationFileContent =
|
|
257
|
+
// getDocsTranslations(version);
|
|
257
258
|
|
|
258
259
|
return [
|
|
259
260
|
{
|
package/src/versions.ts
CHANGED
|
@@ -33,11 +33,9 @@ import {resolveSidebarPathOption} from './sidebars';
|
|
|
33
33
|
|
|
34
34
|
// retro-compatibility: no prefix for the default plugin id
|
|
35
35
|
function addPluginIdPrefix(fileOrDir: string, pluginId: string): string {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return `${pluginId}_${fileOrDir}`;
|
|
40
|
-
}
|
|
36
|
+
return pluginId === DEFAULT_PLUGIN_ID
|
|
37
|
+
? fileOrDir
|
|
38
|
+
: `${pluginId}_${fileOrDir}`;
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
export function getVersionedDocsDirPath(
|
|
@@ -96,9 +94,8 @@ async function readVersionsFile(
|
|
|
96
94
|
const content = JSON.parse(await fs.readFile(versionsFilePath, 'utf8'));
|
|
97
95
|
ensureValidVersionArray(content);
|
|
98
96
|
return content;
|
|
99
|
-
} else {
|
|
100
|
-
return null;
|
|
101
97
|
}
|
|
98
|
+
return null;
|
|
102
99
|
}
|
|
103
100
|
|
|
104
101
|
async function readVersionNames(
|
|
@@ -274,15 +271,13 @@ function getDefaultVersionBanner({
|
|
|
274
271
|
return null;
|
|
275
272
|
}
|
|
276
273
|
// Upcoming versions: unreleased banner
|
|
277
|
-
|
|
274
|
+
if (
|
|
278
275
|
versionNames.indexOf(versionName) < versionNames.indexOf(lastVersionName)
|
|
279
276
|
) {
|
|
280
277
|
return 'unreleased';
|
|
281
278
|
}
|
|
282
279
|
// Older versions: display unmaintained banner
|
|
283
|
-
|
|
284
|
-
return 'unmaintained';
|
|
285
|
-
}
|
|
280
|
+
return 'unmaintained';
|
|
286
281
|
}
|
|
287
282
|
|
|
288
283
|
function getVersionBanner({
|
|
@@ -443,8 +438,9 @@ function checkVersionMetadataPaths({
|
|
|
443
438
|
);
|
|
444
439
|
}
|
|
445
440
|
|
|
446
|
-
// If the current version defines a path to a sidebar file
|
|
447
|
-
// Note: for versioned sidebars, the file may not exist (as
|
|
441
|
+
// If the current version defines a path to a sidebar file that does not
|
|
442
|
+
// exist, we throw! Note: for versioned sidebars, the file may not exist (as
|
|
443
|
+
// we prefer to not create it rather than to create an empty file)
|
|
448
444
|
// See https://github.com/facebook/docusaurus/issues/3366
|
|
449
445
|
// See https://github.com/facebook/docusaurus/pull/4775
|
|
450
446
|
if (
|
|
@@ -469,11 +465,10 @@ Please set the docs "sidebarPath" field in your config file to:
|
|
|
469
465
|
function getDefaultLastVersionName(versionNames: string[]) {
|
|
470
466
|
if (versionNames.length === 1) {
|
|
471
467
|
return versionNames[0];
|
|
472
|
-
} else {
|
|
473
|
-
return versionNames.filter(
|
|
474
|
-
(versionName) => versionName !== CURRENT_VERSION_NAME,
|
|
475
|
-
)[0];
|
|
476
468
|
}
|
|
469
|
+
return versionNames.filter(
|
|
470
|
+
(versionName) => versionName !== CURRENT_VERSION_NAME,
|
|
471
|
+
)[0];
|
|
477
472
|
}
|
|
478
473
|
|
|
479
474
|
function checkVersionsOptions(
|
|
@@ -544,9 +539,8 @@ function filterVersions(
|
|
|
544
539
|
return versionNamesUnfiltered.filter((name) =>
|
|
545
540
|
(options.onlyIncludeVersions || []).includes(name),
|
|
546
541
|
);
|
|
547
|
-
} else {
|
|
548
|
-
return versionNamesUnfiltered;
|
|
549
542
|
}
|
|
543
|
+
return versionNamesUnfiltered;
|
|
550
544
|
}
|
|
551
545
|
|
|
552
546
|
export async function readVersionsMetadata({
|