@docusaurus/plugin-content-docs 0.0.0-4788 → 0.0.0-4792
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.d.ts +1 -1
- package/lib/categoryGeneratedIndex.js +4 -2
- package/lib/docs.d.ts +3 -3
- package/lib/docs.js +4 -5
- package/lib/frontMatter.d.ts +1 -1
- package/lib/globalData.js +2 -2
- package/lib/index.js +3 -3
- package/lib/markdown/linkify.js +1 -2
- package/lib/props.d.ts +2 -2
- package/lib/props.js +5 -5
- package/lib/routes.d.ts +2 -1
- package/lib/routes.js +4 -16
- package/lib/sidebars/normalization.js +1 -1
- package/lib/sidebars/postProcessor.js +1 -1
- package/lib/sidebars/types.d.ts +14 -11
- package/lib/sidebars/utils.d.ts +3 -3
- package/lib/slug.d.ts +1 -2
- package/lib/tags.d.ts +2 -1
- package/lib/tags.js +1 -1
- package/lib/translations.js +2 -2
- package/lib/types.d.ts +4 -87
- package/lib/versions.d.ts +1 -3
- package/lib/versions.js +21 -32
- package/package.json +9 -9
- package/src/categoryGeneratedIndex.ts +8 -3
- package/src/docs.ts +13 -17
- package/src/frontMatter.ts +1 -1
- package/src/globalData.ts +4 -4
- package/src/index.ts +8 -8
- package/src/markdown/linkify.ts +2 -3
- package/src/plugin-content-docs.d.ts +377 -66
- package/src/props.ts +8 -7
- package/src/routes.ts +6 -30
- package/src/sidebars/normalization.ts +1 -1
- package/src/sidebars/postProcessor.ts +1 -1
- package/src/sidebars/processor.ts +4 -1
- package/src/sidebars/types.ts +15 -11
- package/src/sidebars/utils.ts +6 -3
- package/src/slug.ts +4 -2
- package/src/tags.ts +3 -2
- package/src/translations.ts +2 -3
- package/src/types.ts +9 -96
- package/src/versions.ts +28 -41
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type {
|
|
9
|
+
DocMetadataBase,
|
|
10
|
+
VersionMetadata,
|
|
11
|
+
} from '@docusaurus/plugin-content-docs';
|
|
9
12
|
import type {
|
|
10
13
|
NormalizedSidebarItem,
|
|
11
14
|
NormalizedSidebar,
|
package/src/sidebars/types.ts
CHANGED
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type {Optional, Required} from 'utility-types';
|
|
9
|
-
import type {DocMetadataBase, VersionMetadata} from '../types';
|
|
10
9
|
import type {
|
|
11
10
|
NumberPrefixParser,
|
|
12
11
|
SidebarOptions,
|
|
13
12
|
CategoryIndexMatcher,
|
|
13
|
+
DocMetadataBase,
|
|
14
|
+
VersionMetadata,
|
|
14
15
|
} from '@docusaurus/plugin-content-docs';
|
|
15
16
|
import type {Slugger} from '@docusaurus/utils';
|
|
16
17
|
|
|
@@ -199,16 +200,6 @@ export type PropSidebarBreadcrumbsItem =
|
|
|
199
200
|
| PropSidebarItemLink
|
|
200
201
|
| PropSidebarItemCategory;
|
|
201
202
|
|
|
202
|
-
export type PropVersionDoc = {
|
|
203
|
-
id: string;
|
|
204
|
-
title: string;
|
|
205
|
-
description?: string;
|
|
206
|
-
sidebar?: string;
|
|
207
|
-
};
|
|
208
|
-
export type PropVersionDocs = {
|
|
209
|
-
[docId: string]: PropVersionDoc;
|
|
210
|
-
};
|
|
211
|
-
|
|
212
203
|
export type CategoryMetadataFile = {
|
|
213
204
|
label?: string;
|
|
214
205
|
position?: number;
|
|
@@ -243,11 +234,20 @@ export type SidebarItemsGeneratorVersion = Pick<
|
|
|
243
234
|
>;
|
|
244
235
|
|
|
245
236
|
export type SidebarItemsGeneratorArgs = {
|
|
237
|
+
/** The sidebar item with type "autogenerated" to be transformed. */
|
|
246
238
|
item: SidebarItemAutogenerated;
|
|
239
|
+
/** Useful metadata for the version this sidebar belongs to. */
|
|
247
240
|
version: SidebarItemsGeneratorVersion;
|
|
241
|
+
/** All the docs of that version (unfiltered). */
|
|
248
242
|
docs: SidebarItemsGeneratorDoc[];
|
|
243
|
+
/** Number prefix parser configured for this plugin. */
|
|
249
244
|
numberPrefixParser: NumberPrefixParser;
|
|
245
|
+
/** The default category index matcher which you can override. */
|
|
250
246
|
isCategoryIndex: CategoryIndexMatcher;
|
|
247
|
+
/**
|
|
248
|
+
* key is the path relative to the doc content directory, value is the
|
|
249
|
+
* category metadata file's content.
|
|
250
|
+
*/
|
|
251
251
|
categoriesMetadata: {[filePath: string]: CategoryMetadataFile};
|
|
252
252
|
};
|
|
253
253
|
export type SidebarItemsGenerator = (
|
|
@@ -258,6 +258,10 @@ export type SidebarItemsGenerator = (
|
|
|
258
258
|
// default sidebar gen logic
|
|
259
259
|
// see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320
|
|
260
260
|
export type SidebarItemsGeneratorOptionArgs = {
|
|
261
|
+
/**
|
|
262
|
+
* Useful to re-use/enhance the default sidebar generation logic from
|
|
263
|
+
* Docusaurus.
|
|
264
|
+
*/
|
|
261
265
|
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
262
266
|
} & SidebarItemsGeneratorArgs;
|
|
263
267
|
export type SidebarItemsGeneratorOption = (
|
package/src/sidebars/utils.ts
CHANGED
|
@@ -21,7 +21,10 @@ import type {
|
|
|
21
21
|
|
|
22
22
|
import _ from 'lodash';
|
|
23
23
|
import {toMessageRelativeFilePath} from '@docusaurus/utils';
|
|
24
|
-
import type {
|
|
24
|
+
import type {
|
|
25
|
+
DocMetadataBase,
|
|
26
|
+
PropNavigationLink,
|
|
27
|
+
} from '@docusaurus/plugin-content-docs';
|
|
25
28
|
|
|
26
29
|
export function isCategoriesShorthand(
|
|
27
30
|
item: SidebarItemConfig,
|
|
@@ -346,7 +349,7 @@ Available document ids are:
|
|
|
346
349
|
};
|
|
347
350
|
}
|
|
348
351
|
|
|
349
|
-
export function toDocNavigationLink(doc: DocMetadataBase):
|
|
352
|
+
export function toDocNavigationLink(doc: DocMetadataBase): PropNavigationLink {
|
|
350
353
|
const {
|
|
351
354
|
title,
|
|
352
355
|
permalink,
|
|
@@ -361,7 +364,7 @@ export function toDocNavigationLink(doc: DocMetadataBase): DocNavLink {
|
|
|
361
364
|
export function toNavigationLink(
|
|
362
365
|
navigationItem: SidebarNavigationItem | undefined,
|
|
363
366
|
docsById: {[docId: string]: DocMetadataBase},
|
|
364
|
-
):
|
|
367
|
+
): PropNavigationLink | undefined {
|
|
365
368
|
function getDocById(docId: string) {
|
|
366
369
|
const doc = docsById[docId];
|
|
367
370
|
if (!doc) {
|
package/src/slug.ts
CHANGED
|
@@ -15,9 +15,11 @@ import {
|
|
|
15
15
|
DefaultNumberPrefixParser,
|
|
16
16
|
stripPathNumberPrefixes,
|
|
17
17
|
} from './numberPrefix';
|
|
18
|
-
import type {DocMetadataBase} from './types';
|
|
19
18
|
import {isCategoryIndex, toCategoryIndexMatcherParam} from './docs';
|
|
20
|
-
import type {
|
|
19
|
+
import type {
|
|
20
|
+
NumberPrefixParser,
|
|
21
|
+
DocMetadataBase,
|
|
22
|
+
} from '@docusaurus/plugin-content-docs';
|
|
21
23
|
|
|
22
24
|
export default function getSlug({
|
|
23
25
|
baseID,
|
package/src/tags.ts
CHANGED
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import {groupTaggedItems} from '@docusaurus/utils';
|
|
9
|
-
import type {VersionTags
|
|
9
|
+
import type {VersionTags} from './types';
|
|
10
|
+
import type {DocMetadata} from '@docusaurus/plugin-content-docs';
|
|
10
11
|
import _ from 'lodash';
|
|
11
12
|
|
|
12
13
|
export function getVersionTags(docs: DocMetadata[]): VersionTags {
|
|
13
14
|
const groups = groupTaggedItems(docs, (doc) => doc.tags);
|
|
14
15
|
return _.mapValues(groups, (group) => ({
|
|
15
|
-
|
|
16
|
+
label: group.tag.label,
|
|
16
17
|
docIds: group.items.map((item) => item.id),
|
|
17
18
|
permalink: group.tag.permalink,
|
|
18
19
|
}));
|
package/src/translations.ts
CHANGED
|
@@ -245,7 +245,7 @@ function translateSidebars(
|
|
|
245
245
|
function getVersionTranslationFiles(version: LoadedVersion): TranslationFiles {
|
|
246
246
|
const versionTranslations: TranslationFileContent = {
|
|
247
247
|
'version.label': {
|
|
248
|
-
message: version.
|
|
248
|
+
message: version.label,
|
|
249
249
|
description: `The label for version ${version.versionName}`,
|
|
250
250
|
},
|
|
251
251
|
};
|
|
@@ -275,8 +275,7 @@ function translateVersion(
|
|
|
275
275
|
translationFiles[getVersionFileName(version.versionName)]!.content;
|
|
276
276
|
return {
|
|
277
277
|
...version,
|
|
278
|
-
|
|
279
|
-
versionTranslations['version.label']?.message ?? version.versionLabel,
|
|
278
|
+
label: versionTranslations['version.label']?.message ?? version.label,
|
|
280
279
|
sidebars: translateSidebars(version, versionTranslations),
|
|
281
280
|
// docs: translateDocs(version.docs, versionTranslations),
|
|
282
281
|
};
|
package/src/types.ts
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
/// <reference types="@docusaurus/module-type-aliases" />
|
|
9
9
|
|
|
10
10
|
import type {Sidebars} from './sidebars/types';
|
|
11
|
+
import type {BrokenMarkdownLink, Tag} from '@docusaurus/utils';
|
|
11
12
|
import type {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} from '@docusaurus/
|
|
17
|
-
import type {VersionBanner} from '@docusaurus/plugin-content-docs';
|
|
13
|
+
VersionMetadata,
|
|
14
|
+
LastUpdateData,
|
|
15
|
+
DocMetadata,
|
|
16
|
+
CategoryGeneratedIndexMetadata,
|
|
17
|
+
} from '@docusaurus/plugin-content-docs';
|
|
18
18
|
|
|
19
19
|
export type DocFile = {
|
|
20
20
|
contentPath: string; // /!\ may be localized
|
|
@@ -24,106 +24,19 @@ export type DocFile = {
|
|
|
24
24
|
lastUpdate: LastUpdateData;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export type VersionMetadata = ContentPaths & {
|
|
28
|
-
versionName: string; // 1.0.0
|
|
29
|
-
versionLabel: string; // Version 1.0.0
|
|
30
|
-
versionPath: string; // /baseUrl/docs/1.0.0
|
|
31
|
-
tagsPath: string;
|
|
32
|
-
versionEditUrl?: string | undefined;
|
|
33
|
-
versionEditUrlLocalized?: string | undefined;
|
|
34
|
-
versionBanner: VersionBanner | null;
|
|
35
|
-
versionBadge: boolean;
|
|
36
|
-
versionClassName: string;
|
|
37
|
-
isLast: boolean;
|
|
38
|
-
sidebarFilePath: string | false | undefined; // versioned_sidebars/1.0.0.json
|
|
39
|
-
routePriority: number | undefined; // -1 for the latest docs
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export type LastUpdateData = {
|
|
43
|
-
lastUpdatedAt?: number;
|
|
44
|
-
formattedLastUpdatedAt?: string;
|
|
45
|
-
lastUpdatedBy?: string;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export type DocFrontMatter = {
|
|
49
|
-
// Front matter uses snake case
|
|
50
|
-
id?: string;
|
|
51
|
-
title?: string;
|
|
52
|
-
tags?: FrontMatterTag[];
|
|
53
|
-
hide_title?: boolean;
|
|
54
|
-
hide_table_of_contents?: boolean;
|
|
55
|
-
keywords?: string[];
|
|
56
|
-
image?: string;
|
|
57
|
-
description?: string;
|
|
58
|
-
slug?: string;
|
|
59
|
-
sidebar_label?: string;
|
|
60
|
-
sidebar_position?: number;
|
|
61
|
-
sidebar_class_name?: string;
|
|
62
|
-
sidebar_custom_props?: {[key: string]: unknown};
|
|
63
|
-
displayed_sidebar?: string | null;
|
|
64
|
-
pagination_label?: string;
|
|
65
|
-
custom_edit_url?: string | null;
|
|
66
|
-
parse_number_prefixes?: boolean;
|
|
67
|
-
toc_min_heading_level?: number;
|
|
68
|
-
toc_max_heading_level?: number;
|
|
69
|
-
pagination_next?: string | null;
|
|
70
|
-
pagination_prev?: string | null;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export type DocMetadataBase = LastUpdateData & {
|
|
74
|
-
id: string; // TODO legacy versioned id => try to remove
|
|
75
|
-
unversionedId: string; // TODO new unversioned id => try to rename to "id"
|
|
76
|
-
version: string;
|
|
77
|
-
title: string;
|
|
78
|
-
description: string;
|
|
79
|
-
source: string; // @site aliased posix source => "@site/docs/folder/subFolder/subSubFolder/myDoc.md"
|
|
80
|
-
sourceDirName: string; // posix path relative to the versioned docs folder (can be ".") => "folder/subFolder/subSubFolder"
|
|
81
|
-
slug: string;
|
|
82
|
-
permalink: string;
|
|
83
|
-
sidebarPosition?: number;
|
|
84
|
-
editUrl?: string | null;
|
|
85
|
-
tags: Tag[];
|
|
86
|
-
frontMatter: DocFrontMatter & {[key: string]: unknown};
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export type DocNavLink = {
|
|
90
|
-
title: string;
|
|
91
|
-
permalink: string;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export type DocMetadata = DocMetadataBase & {
|
|
95
|
-
sidebar?: string;
|
|
96
|
-
previous?: DocNavLink;
|
|
97
|
-
next?: DocNavLink;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export type CategoryGeneratedIndexMetadata = {
|
|
101
|
-
title: string;
|
|
102
|
-
description?: string;
|
|
103
|
-
slug: string;
|
|
104
|
-
permalink: string;
|
|
105
|
-
sidebar: string;
|
|
106
|
-
previous?: DocNavLink;
|
|
107
|
-
next?: DocNavLink;
|
|
108
|
-
image?: string;
|
|
109
|
-
keywords?: string | readonly string[];
|
|
110
|
-
};
|
|
111
|
-
|
|
112
27
|
export type SourceToPermalink = {
|
|
113
28
|
[source: string]: string;
|
|
114
29
|
};
|
|
115
30
|
|
|
116
|
-
export type VersionTag = {
|
|
117
|
-
|
|
118
|
-
docIds: string[];
|
|
119
|
-
permalink: string; // pathname of the tag
|
|
31
|
+
export type VersionTag = Tag & {
|
|
32
|
+
/** all doc ids having this tag. */
|
|
33
|
+
docIds: string[];
|
|
120
34
|
};
|
|
121
35
|
export type VersionTags = {
|
|
122
36
|
[key: string]: VersionTag;
|
|
123
37
|
};
|
|
124
38
|
|
|
125
39
|
export type LoadedVersion = VersionMetadata & {
|
|
126
|
-
versionPath: string;
|
|
127
40
|
mainDocId: string;
|
|
128
41
|
docs: DocMetadata[];
|
|
129
42
|
sidebars: Sidebars;
|
package/src/versions.ts
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import fs from 'fs-extra';
|
|
10
|
-
import type {VersionMetadata} from './types';
|
|
11
10
|
import {
|
|
12
11
|
VERSIONS_JSON_FILE,
|
|
13
12
|
VERSIONED_DOCS_DIR,
|
|
@@ -17,8 +16,8 @@ import {
|
|
|
17
16
|
import type {
|
|
18
17
|
PluginOptions,
|
|
19
18
|
VersionBanner,
|
|
20
|
-
VersionOptions,
|
|
21
19
|
VersionsOptions,
|
|
20
|
+
VersionMetadata,
|
|
22
21
|
} from '@docusaurus/plugin-content-docs';
|
|
23
22
|
|
|
24
23
|
import type {LoadContext} from '@docusaurus/types';
|
|
@@ -207,7 +206,12 @@ function getVersionEditUrls({
|
|
|
207
206
|
contentPath,
|
|
208
207
|
contentPathLocalized,
|
|
209
208
|
context: {siteDir, i18n},
|
|
210
|
-
options: {
|
|
209
|
+
options: {
|
|
210
|
+
id,
|
|
211
|
+
path: currentVersionPath,
|
|
212
|
+
editUrl: editUrlOption,
|
|
213
|
+
editCurrentVersion,
|
|
214
|
+
},
|
|
211
215
|
}: {
|
|
212
216
|
contentPath: string;
|
|
213
217
|
contentPathLocalized: string;
|
|
@@ -216,15 +220,11 @@ function getVersionEditUrls({
|
|
|
216
220
|
PluginOptions,
|
|
217
221
|
'id' | 'path' | 'editUrl' | 'editCurrentVersion'
|
|
218
222
|
>;
|
|
219
|
-
}):
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
// if the user is using the functional form of editUrl,
|
|
225
|
-
// he has total freedom and we can't compute a "version edit url"
|
|
226
|
-
if (typeof editUrl === 'function') {
|
|
227
|
-
return undefined;
|
|
223
|
+
}): Pick<VersionMetadata, 'editUrl' | 'editUrlLocalized'> {
|
|
224
|
+
// If the user is using the functional form of editUrl,
|
|
225
|
+
// she has total freedom and we can't compute a "version edit url"
|
|
226
|
+
if (!editUrlOption || typeof editUrlOption === 'function') {
|
|
227
|
+
return {editUrl: undefined, editUrlLocalized: undefined};
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
const editDirPath = editCurrentVersion ? currentVersionPath : contentPath;
|
|
@@ -244,16 +244,16 @@ function getVersionEditUrls({
|
|
|
244
244
|
path.relative(siteDir, path.resolve(siteDir, editDirPathLocalized)),
|
|
245
245
|
);
|
|
246
246
|
|
|
247
|
-
const
|
|
247
|
+
const editUrl = normalizeUrl([editUrlOption, versionPathSegment]);
|
|
248
248
|
|
|
249
|
-
const
|
|
250
|
-
|
|
249
|
+
const editUrlLocalized = normalizeUrl([
|
|
250
|
+
editUrlOption,
|
|
251
251
|
versionPathSegmentLocalized,
|
|
252
252
|
]);
|
|
253
253
|
|
|
254
254
|
return {
|
|
255
|
-
|
|
256
|
-
|
|
255
|
+
editUrl,
|
|
256
|
+
editUrlLocalized,
|
|
257
257
|
};
|
|
258
258
|
}
|
|
259
259
|
|
|
@@ -370,12 +370,12 @@ function createVersionMetadata({
|
|
|
370
370
|
}
|
|
371
371
|
const defaultVersionPathPart = getDefaultVersionPathPart();
|
|
372
372
|
|
|
373
|
-
const versionOptions
|
|
373
|
+
const versionOptions = options.versions[versionName] ?? {};
|
|
374
374
|
|
|
375
|
-
const
|
|
375
|
+
const label = versionOptions.label ?? defaultVersionLabel;
|
|
376
376
|
const versionPathPart = versionOptions.path ?? defaultVersionPathPart;
|
|
377
377
|
|
|
378
|
-
const
|
|
378
|
+
const routePath = normalizeUrl([
|
|
379
379
|
context.baseUrl,
|
|
380
380
|
options.routeBasePath,
|
|
381
381
|
versionPathPart,
|
|
@@ -388,28 +388,27 @@ function createVersionMetadata({
|
|
|
388
388
|
options,
|
|
389
389
|
});
|
|
390
390
|
|
|
391
|
-
// Because /docs/:route` should always be after `/docs/versionName/:route`.
|
|
392
391
|
const routePriority = versionPathPart === '' ? -1 : undefined;
|
|
393
392
|
|
|
394
393
|
// the path that will be used to refer the docs tags
|
|
395
394
|
// example below will be using /docs/tags
|
|
396
|
-
const tagsPath = normalizeUrl([
|
|
395
|
+
const tagsPath = normalizeUrl([routePath, options.tagsBasePath]);
|
|
397
396
|
|
|
398
397
|
return {
|
|
399
398
|
versionName,
|
|
400
|
-
|
|
401
|
-
|
|
399
|
+
label,
|
|
400
|
+
path: routePath,
|
|
402
401
|
tagsPath,
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
402
|
+
editUrl: versionEditUrls.editUrl,
|
|
403
|
+
editUrlLocalized: versionEditUrls.editUrlLocalized,
|
|
404
|
+
banner: getVersionBanner({
|
|
406
405
|
versionName,
|
|
407
406
|
versionNames,
|
|
408
407
|
lastVersionName,
|
|
409
408
|
options,
|
|
410
409
|
}),
|
|
411
|
-
|
|
412
|
-
|
|
410
|
+
badge: getVersionBadge({versionName, versionNames, options}),
|
|
411
|
+
className: getVersionClassName({versionName, options}),
|
|
413
412
|
isLast,
|
|
414
413
|
routePriority,
|
|
415
414
|
sidebarFilePath,
|
|
@@ -592,15 +591,3 @@ export async function readVersionsMetadata({
|
|
|
592
591
|
);
|
|
593
592
|
return versionsMetadata;
|
|
594
593
|
}
|
|
595
|
-
|
|
596
|
-
// order matter!
|
|
597
|
-
// Read in priority the localized path, then the unlocalized one
|
|
598
|
-
// We want the localized doc to "override" the unlocalized one
|
|
599
|
-
export function getDocsDirPaths(
|
|
600
|
-
versionMetadata: Pick<
|
|
601
|
-
VersionMetadata,
|
|
602
|
-
'contentPath' | 'contentPathLocalized'
|
|
603
|
-
>,
|
|
604
|
-
): [string, string] {
|
|
605
|
-
return [versionMetadata.contentPathLocalized, versionMetadata.contentPath];
|
|
606
|
-
}
|