@docusaurus/plugin-content-docs 2.0.0-beta.14 → 2.0.0-beta.15
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 +2 -2
- package/lib/categoryGeneratedIndex.js +2 -0
- package/lib/cli.d.ts +1 -1
- package/lib/client/docsClientUtils.d.ts +3 -22
- package/lib/client/docsClientUtils.js +5 -1
- package/lib/{theme/hooks/useDocs.d.ts → client/globalDataHooks.d.ts} +1 -2
- package/lib/{theme/hooks/useDocs.js → client/globalDataHooks.js} +2 -1
- package/lib/client/index.d.ts +7 -0
- package/lib/client/index.js +10 -0
- package/lib/docFrontMatter.js +1 -0
- package/lib/docs.d.ts +19 -6
- package/lib/docs.js +37 -17
- package/lib/globalData.d.ts +5 -1
- package/lib/globalData.js +34 -2
- package/lib/index.d.ts +3 -2
- package/lib/index.js +2 -8
- package/lib/lastUpdate.js +2 -2
- package/lib/markdown/index.d.ts +1 -1
- package/lib/markdown/linkify.d.ts +1 -1
- package/lib/numberPrefix.d.ts +1 -1
- package/lib/options.d.ts +1 -1
- package/lib/routes.d.ts +4 -3
- package/lib/routes.js +6 -3
- package/lib/sidebars/generator.js +12 -14
- package/lib/sidebars/index.d.ts +3 -2
- package/lib/sidebars/processor.d.ts +3 -2
- package/lib/sidebars/processor.js +2 -0
- package/lib/sidebars/types.d.ts +8 -3
- package/lib/sidebars/utils.d.ts +12 -4
- package/lib/sidebars/utils.js +48 -3
- package/lib/sidebars/validation.d.ts +1 -1
- package/lib/sidebars/validation.js +4 -0
- package/lib/slug.d.ts +5 -4
- package/lib/slug.js +8 -7
- package/lib/translations.js +1 -1
- package/lib/types.d.ts +7 -78
- package/lib/versions.d.ts +3 -2
- package/lib/versions.js +27 -32
- package/package.json +14 -12
- package/src/categoryGeneratedIndex.ts +5 -3
- package/src/cli.ts +4 -1
- package/src/client/docsClientUtils.ts +22 -35
- package/src/{theme/hooks/useDocs.ts → client/globalDataHooks.ts} +6 -2
- package/src/client/index.ts +8 -0
- package/src/docFrontMatter.ts +2 -1
- package/src/docs.ts +62 -29
- package/src/globalData.ts +49 -3
- package/src/index.ts +9 -15
- package/src/lastUpdate.ts +2 -2
- package/src/markdown/index.ts +1 -1
- package/src/markdown/linkify.ts +1 -1
- package/src/numberPrefix.ts +1 -1
- package/src/options.ts +1 -1
- package/src/plugin-content-docs.d.ts +128 -18
- package/src/routes.ts +19 -5
- package/src/sidebars/generator.ts +25 -20
- package/src/sidebars/index.ts +3 -2
- package/src/sidebars/normalization.ts +2 -1
- package/src/sidebars/processor.ts +8 -7
- package/src/sidebars/types.ts +9 -5
- package/src/sidebars/utils.ts +76 -8
- package/src/sidebars/validation.ts +6 -1
- package/src/slug.ts +15 -11
- package/src/translations.ts +2 -2
- package/src/types.ts +12 -98
- package/src/versions.ts +51 -47
|
@@ -7,21 +7,18 @@
|
|
|
7
7
|
|
|
8
8
|
import {matchPath} from '@docusaurus/router';
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import type {
|
|
11
|
+
GlobalPluginData,
|
|
12
|
+
GlobalVersion,
|
|
13
|
+
GlobalDoc,
|
|
14
|
+
GetActivePluginOptions,
|
|
15
|
+
ActivePlugin,
|
|
16
|
+
ActiveDocContext,
|
|
17
|
+
DocVersionSuggestions,
|
|
18
|
+
} from '@docusaurus/plugin-content-docs/client';
|
|
11
19
|
|
|
12
20
|
// This code is not part of the api surface, not in ./theme on purpose
|
|
13
21
|
|
|
14
|
-
// Short/convenient type aliases
|
|
15
|
-
type Version = GlobalVersion;
|
|
16
|
-
type Doc = GlobalDoc;
|
|
17
|
-
|
|
18
|
-
export type ActivePlugin = {
|
|
19
|
-
pluginId: string;
|
|
20
|
-
pluginData: GlobalPluginData;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type GetActivePluginOptions = {failfast?: boolean}; // use fail-fast option if you know for sure one plugin instance is active
|
|
24
|
-
|
|
25
22
|
// get the data of the plugin that is currently "active"
|
|
26
23
|
// ie the docs of that plugin are currently browsed
|
|
27
24
|
// it is useful to support multiple docs plugin instances
|
|
@@ -30,14 +27,17 @@ export function getActivePlugin(
|
|
|
30
27
|
pathname: string,
|
|
31
28
|
options: GetActivePluginOptions = {},
|
|
32
29
|
): ActivePlugin | undefined {
|
|
33
|
-
const activeEntry = Object.entries(allPluginDatas)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
const activeEntry = Object.entries(allPluginDatas)
|
|
31
|
+
// A quick route sorting: '/android/foo' should match '/android' instead of '/'
|
|
32
|
+
.sort((a, b) => b[1].path.localeCompare(a[1].path))
|
|
33
|
+
.find(
|
|
34
|
+
([, pluginData]) =>
|
|
35
|
+
!!matchPath(pathname, {
|
|
36
|
+
path: pluginData.path,
|
|
37
|
+
exact: false,
|
|
38
|
+
strict: false,
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
41
|
|
|
42
42
|
const activePlugin: ActivePlugin | undefined = activeEntry
|
|
43
43
|
? {pluginId: activeEntry[0], pluginData: activeEntry[1]}
|
|
@@ -56,13 +56,7 @@ export function getActivePlugin(
|
|
|
56
56
|
return activePlugin;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
export
|
|
60
|
-
activeVersion?: Version;
|
|
61
|
-
activeDoc?: Doc;
|
|
62
|
-
alternateDocVersions: Record<string, Doc>;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const getLatestVersion = (data: GlobalPluginData): Version =>
|
|
59
|
+
export const getLatestVersion = (data: GlobalPluginData): GlobalVersion =>
|
|
66
60
|
data.versions.find((version) => version.isLast)!;
|
|
67
61
|
|
|
68
62
|
// Note: return undefined on doc-unrelated pages,
|
|
@@ -70,7 +64,7 @@ export const getLatestVersion = (data: GlobalPluginData): Version =>
|
|
|
70
64
|
export const getActiveVersion = (
|
|
71
65
|
data: GlobalPluginData,
|
|
72
66
|
pathname: string,
|
|
73
|
-
):
|
|
67
|
+
): GlobalVersion | undefined => {
|
|
74
68
|
const lastVersion = getLatestVersion(data);
|
|
75
69
|
// Last version is a route like /docs/*,
|
|
76
70
|
// we need to try to match it last or it would match /docs/version-1.0/* as well
|
|
@@ -127,13 +121,6 @@ export const getActiveDocContext = (
|
|
|
127
121
|
};
|
|
128
122
|
};
|
|
129
123
|
|
|
130
|
-
export type DocVersionSuggestions = {
|
|
131
|
-
// suggest the latest version
|
|
132
|
-
latestVersionSuggestion: GlobalVersion;
|
|
133
|
-
// suggest the same doc, in latest version (if exist)
|
|
134
|
-
latestDocSuggestion?: GlobalDoc;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
124
|
export const getDocVersionSuggestions = (
|
|
138
125
|
data: GlobalPluginData,
|
|
139
126
|
pathname: string,
|
|
@@ -11,18 +11,21 @@ import useGlobalData, {
|
|
|
11
11
|
usePluginData,
|
|
12
12
|
} from '@docusaurus/useGlobalData';
|
|
13
13
|
|
|
14
|
-
import {GlobalPluginData, GlobalVersion} from '../../types';
|
|
15
14
|
import {
|
|
16
15
|
getActivePlugin,
|
|
17
16
|
getLatestVersion,
|
|
18
17
|
getActiveVersion,
|
|
19
18
|
getActiveDocContext,
|
|
20
19
|
getDocVersionSuggestions,
|
|
20
|
+
} from './docsClientUtils';
|
|
21
|
+
import type {
|
|
22
|
+
GlobalPluginData,
|
|
23
|
+
GlobalVersion,
|
|
21
24
|
ActivePlugin,
|
|
22
25
|
ActiveDocContext,
|
|
23
26
|
DocVersionSuggestions,
|
|
24
27
|
GetActivePluginOptions,
|
|
25
|
-
} from '
|
|
28
|
+
} from '@docusaurus/plugin-content-docs/client';
|
|
26
29
|
|
|
27
30
|
// Important to use a constant object to avoid React useEffect executions etc...,
|
|
28
31
|
// see https://github.com/facebook/docusaurus/issues/5089
|
|
@@ -37,6 +40,7 @@ export const useAllDocsData = (): Record<string, GlobalPluginData> =>
|
|
|
37
40
|
export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
|
|
38
41
|
usePluginData('docusaurus-plugin-content-docs', pluginId) as GlobalPluginData;
|
|
39
42
|
|
|
43
|
+
// TODO this feature should be provided by docusaurus core
|
|
40
44
|
export const useActivePlugin = (
|
|
41
45
|
options: GetActivePluginOptions = {},
|
|
42
46
|
): ActivePlugin | undefined => {
|
package/src/docFrontMatter.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
|
-
JoiFrontMatter as Joi, // Custom instance for
|
|
9
|
+
JoiFrontMatter as Joi, // Custom instance for front matter
|
|
10
10
|
URISchema,
|
|
11
11
|
FrontMatterTagsSchema,
|
|
12
12
|
FrontMatterTOCHeadingLevels,
|
|
@@ -30,6 +30,7 @@ const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
|
|
|
30
30
|
sidebar_label: Joi.string(),
|
|
31
31
|
sidebar_position: Joi.number(),
|
|
32
32
|
sidebar_class_name: Joi.string(),
|
|
33
|
+
displayed_sidebar: Joi.string().allow(null),
|
|
33
34
|
tags: FrontMatterTagsSchema,
|
|
34
35
|
pagination_label: Joi.string(),
|
|
35
36
|
custom_edit_url: URISchema.allow('', null),
|
package/src/docs.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import fs from 'fs-extra';
|
|
10
10
|
import logger from '@docusaurus/logger';
|
|
11
|
-
import {keyBy
|
|
11
|
+
import {keyBy} from 'lodash';
|
|
12
12
|
import {
|
|
13
13
|
aliasedSitePath,
|
|
14
14
|
getEditUrl,
|
|
@@ -22,14 +22,12 @@ import {
|
|
|
22
22
|
import type {LoadContext} from '@docusaurus/types';
|
|
23
23
|
|
|
24
24
|
import {getFileLastUpdate} from './lastUpdate';
|
|
25
|
-
import {
|
|
25
|
+
import type {
|
|
26
26
|
DocFile,
|
|
27
27
|
DocMetadataBase,
|
|
28
28
|
DocMetadata,
|
|
29
29
|
DocNavLink,
|
|
30
30
|
LastUpdateData,
|
|
31
|
-
MetadataOptions,
|
|
32
|
-
PluginOptions,
|
|
33
31
|
VersionMetadata,
|
|
34
32
|
LoadedVersion,
|
|
35
33
|
} from './types';
|
|
@@ -38,11 +36,14 @@ import {CURRENT_VERSION_NAME} from './constants';
|
|
|
38
36
|
import {getDocsDirPaths} from './versions';
|
|
39
37
|
import {stripPathNumberPrefixes} from './numberPrefix';
|
|
40
38
|
import {validateDocFrontMatter} from './docFrontMatter';
|
|
41
|
-
import {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
import type {SidebarsUtils} from './sidebars/utils';
|
|
40
|
+
import {toDocNavigationLink, toNavigationLink} from './sidebars/utils';
|
|
41
|
+
import type {
|
|
42
|
+
MetadataOptions,
|
|
43
|
+
PluginOptions,
|
|
44
|
+
CategoryIndexMatcher,
|
|
45
|
+
CategoryIndexMatcherParam,
|
|
46
|
+
} from '@docusaurus/plugin-content-docs';
|
|
46
47
|
|
|
47
48
|
type LastUpdateOptions = Pick<
|
|
48
49
|
PluginOptions,
|
|
@@ -139,7 +140,7 @@ function doProcessDocMetadata({
|
|
|
139
140
|
custom_edit_url: customEditURL,
|
|
140
141
|
|
|
141
142
|
// Strip number prefixes by default (01-MyFolder/01-MyDoc.md => MyFolder/MyDoc) by default,
|
|
142
|
-
// but allow to disable this behavior with
|
|
143
|
+
// but allow to disable this behavior with front matter
|
|
143
144
|
parse_number_prefixes: parseNumberPrefixes = true,
|
|
144
145
|
} = frontMatter;
|
|
145
146
|
|
|
@@ -163,7 +164,7 @@ function doProcessDocMetadata({
|
|
|
163
164
|
throw new Error(`Document id "${baseID}" cannot include slash.`);
|
|
164
165
|
}
|
|
165
166
|
|
|
166
|
-
// For autogenerated sidebars, sidebar position can come from filename number prefix or
|
|
167
|
+
// For autogenerated sidebars, sidebar position can come from filename number prefix or front matter
|
|
167
168
|
const sidebarPosition: number | undefined =
|
|
168
169
|
frontMatter.sidebar_position ?? numberPrefix;
|
|
169
170
|
|
|
@@ -176,7 +177,7 @@ function doProcessDocMetadata({
|
|
|
176
177
|
: `version-${versionMetadata.versionName}`;
|
|
177
178
|
|
|
178
179
|
// TODO legacy retrocompatibility
|
|
179
|
-
// I think it's bad to affect the
|
|
180
|
+
// I think it's bad to affect the front matter id with the dirname?
|
|
180
181
|
function computeDirNameIdPrefix() {
|
|
181
182
|
if (sourceDirName === '.') {
|
|
182
183
|
return undefined;
|
|
@@ -199,7 +200,7 @@ function doProcessDocMetadata({
|
|
|
199
200
|
baseID,
|
|
200
201
|
source,
|
|
201
202
|
sourceDirName,
|
|
202
|
-
|
|
203
|
+
frontMatterSlug: frontMatter.slug,
|
|
203
204
|
stripDirNumberPrefixes: parseNumberPrefixes,
|
|
204
205
|
numberPrefixParser: options.numberPrefixParser,
|
|
205
206
|
});
|
|
@@ -296,6 +297,7 @@ export function addDocNavigation(
|
|
|
296
297
|
const navigation = sidebarsUtils.getDocNavigation(
|
|
297
298
|
doc.unversionedId,
|
|
298
299
|
doc.id,
|
|
300
|
+
doc.frontMatter.displayed_sidebar,
|
|
299
301
|
);
|
|
300
302
|
|
|
301
303
|
const toNavigationLinkByDocId = (
|
|
@@ -367,31 +369,62 @@ export function getMainDocId({
|
|
|
367
369
|
return getMainDoc().unversionedId;
|
|
368
370
|
}
|
|
369
371
|
|
|
370
|
-
function getLastPathSegment(str: string): string {
|
|
371
|
-
return last(str.split('/'))!;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
372
|
// By convention, Docusaurus considers some docs are "indexes":
|
|
375
373
|
// - index.md
|
|
376
374
|
// - readme.md
|
|
377
375
|
// - <folder>/<folder>.md
|
|
378
376
|
//
|
|
377
|
+
// This function is the default implementation of this convention
|
|
378
|
+
//
|
|
379
379
|
// Those index docs produce a different behavior
|
|
380
380
|
// - Slugs do not end with a weird "/index" suffix
|
|
381
381
|
// - Auto-generated sidebar categories link to them as intro
|
|
382
|
-
export
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}): boolean {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
382
|
+
export const isCategoryIndex: CategoryIndexMatcher = ({
|
|
383
|
+
fileName,
|
|
384
|
+
directories,
|
|
385
|
+
}): boolean => {
|
|
386
|
+
const eligibleDocIndexNames = [
|
|
387
|
+
'index',
|
|
388
|
+
'readme',
|
|
389
|
+
directories[0]?.toLowerCase(),
|
|
390
|
+
];
|
|
391
|
+
return eligibleDocIndexNames.includes(fileName.toLowerCase());
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
export function toCategoryIndexMatcherParam({
|
|
395
|
+
source,
|
|
396
|
+
sourceDirName,
|
|
397
|
+
}: Pick<
|
|
398
|
+
DocMetadataBase,
|
|
399
|
+
'source' | 'sourceDirName'
|
|
400
|
+
>): CategoryIndexMatcherParam {
|
|
401
|
+
// source + sourceDirName are always posix-style
|
|
402
|
+
return {
|
|
403
|
+
fileName: path.posix.parse(source).name,
|
|
404
|
+
extension: path.posix.parse(source).ext,
|
|
405
|
+
directories: sourceDirName.split(path.posix.sep).reverse(),
|
|
406
|
+
};
|
|
407
|
+
}
|
|
393
408
|
|
|
394
|
-
|
|
409
|
+
/**
|
|
410
|
+
* guides/sidebar/autogenerated.md -> 'autogenerated', '.md', ['sidebar', 'guides']
|
|
411
|
+
*/
|
|
412
|
+
export function splitPath(str: string): {
|
|
413
|
+
/**
|
|
414
|
+
* The list of directories, from lowest level to highest.
|
|
415
|
+
* If there's no dir name, directories is ['.']
|
|
416
|
+
*/
|
|
417
|
+
directories: string[];
|
|
418
|
+
/** The file name, without extension */
|
|
419
|
+
fileName: string;
|
|
420
|
+
/** The extension, with a leading dot */
|
|
421
|
+
extension: string;
|
|
422
|
+
} {
|
|
423
|
+
return {
|
|
424
|
+
fileName: path.parse(str).name,
|
|
425
|
+
extension: path.parse(str).ext,
|
|
426
|
+
directories: path.dirname(str).split(path.sep).reverse(),
|
|
427
|
+
};
|
|
395
428
|
}
|
|
396
429
|
|
|
397
430
|
// Return both doc ids
|
package/src/globalData.ts
CHANGED
|
@@ -5,12 +5,20 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import {mapValues} from 'lodash';
|
|
9
|
+
import {normalizeUrl} from '@docusaurus/utils';
|
|
10
|
+
import type {Sidebars} from './sidebars/types';
|
|
11
|
+
import {createSidebarsUtils} from './sidebars/utils';
|
|
8
12
|
import type {
|
|
13
|
+
CategoryGeneratedIndexMetadata,
|
|
9
14
|
DocMetadata,
|
|
10
|
-
GlobalDoc,
|
|
11
15
|
LoadedVersion,
|
|
12
|
-
GlobalVersion,
|
|
13
16
|
} from './types';
|
|
17
|
+
import type {
|
|
18
|
+
GlobalVersion,
|
|
19
|
+
GlobalSidebar,
|
|
20
|
+
GlobalDoc,
|
|
21
|
+
} from '@docusaurus/plugin-content-docs/client';
|
|
14
22
|
|
|
15
23
|
export function toGlobalDataDoc(doc: DocMetadata): GlobalDoc {
|
|
16
24
|
return {
|
|
@@ -20,6 +28,41 @@ export function toGlobalDataDoc(doc: DocMetadata): GlobalDoc {
|
|
|
20
28
|
};
|
|
21
29
|
}
|
|
22
30
|
|
|
31
|
+
export function toGlobalDataGeneratedIndex(
|
|
32
|
+
doc: CategoryGeneratedIndexMetadata,
|
|
33
|
+
): GlobalDoc {
|
|
34
|
+
return {
|
|
35
|
+
id: doc.slug,
|
|
36
|
+
path: doc.permalink,
|
|
37
|
+
sidebar: doc.sidebar,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function toGlobalSidebars(
|
|
42
|
+
sidebars: Sidebars,
|
|
43
|
+
version: LoadedVersion,
|
|
44
|
+
): Record<string, GlobalSidebar> {
|
|
45
|
+
const {getFirstLink} = createSidebarsUtils(sidebars);
|
|
46
|
+
return mapValues(sidebars, (sidebar, sidebarId) => {
|
|
47
|
+
const firstLink = getFirstLink(sidebarId);
|
|
48
|
+
if (!firstLink) {
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
link: {
|
|
53
|
+
path:
|
|
54
|
+
firstLink.type === 'generated-index'
|
|
55
|
+
? normalizeUrl([version.versionPath, firstLink.slug])
|
|
56
|
+
: version.docs.find(
|
|
57
|
+
(doc) =>
|
|
58
|
+
doc.id === firstLink.id || doc.unversionedId === firstLink.id,
|
|
59
|
+
)!.permalink,
|
|
60
|
+
label: firstLink.label,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
23
66
|
export function toGlobalDataVersion(version: LoadedVersion): GlobalVersion {
|
|
24
67
|
return {
|
|
25
68
|
name: version.versionName,
|
|
@@ -27,6 +70,9 @@ export function toGlobalDataVersion(version: LoadedVersion): GlobalVersion {
|
|
|
27
70
|
isLast: version.isLast,
|
|
28
71
|
path: version.versionPath,
|
|
29
72
|
mainDocId: version.mainDocId,
|
|
30
|
-
docs: version.docs
|
|
73
|
+
docs: version.docs
|
|
74
|
+
.map(toGlobalDataDoc)
|
|
75
|
+
.concat(version.categoryGeneratedIndices.map(toGlobalDataGeneratedIndex)),
|
|
76
|
+
sidebars: toGlobalSidebars(version.sidebars, version),
|
|
31
77
|
};
|
|
32
78
|
}
|
package/src/index.ts
CHANGED
|
@@ -29,12 +29,10 @@ import {
|
|
|
29
29
|
} from './docs';
|
|
30
30
|
import {getDocsDirPaths, readVersionsMetadata} from './versions';
|
|
31
31
|
|
|
32
|
-
import {
|
|
33
|
-
PluginOptions,
|
|
32
|
+
import type {
|
|
34
33
|
LoadedContent,
|
|
35
34
|
SourceToPermalink,
|
|
36
35
|
DocMetadataBase,
|
|
37
|
-
GlobalPluginData,
|
|
38
36
|
VersionMetadata,
|
|
39
37
|
LoadedVersion,
|
|
40
38
|
DocFile,
|
|
@@ -54,17 +52,21 @@ import {
|
|
|
54
52
|
import logger from '@docusaurus/logger';
|
|
55
53
|
import {getVersionTags} from './tags';
|
|
56
54
|
import {createVersionRoutes} from './routes';
|
|
57
|
-
import type {
|
|
55
|
+
import type {
|
|
56
|
+
PropTagsListPage,
|
|
57
|
+
PluginOptions,
|
|
58
|
+
} from '@docusaurus/plugin-content-docs';
|
|
59
|
+
import type {GlobalPluginData} from '@docusaurus/plugin-content-docs/client';
|
|
58
60
|
import {createSidebarsUtils} from './sidebars/utils';
|
|
59
61
|
import {getCategoryGeneratedIndexMetadataList} from './categoryGeneratedIndex';
|
|
60
62
|
|
|
61
|
-
export default function pluginContentDocs(
|
|
63
|
+
export default async function pluginContentDocs(
|
|
62
64
|
context: LoadContext,
|
|
63
65
|
options: PluginOptions,
|
|
64
|
-
): Plugin<LoadedContent
|
|
66
|
+
): Promise<Plugin<LoadedContent>> {
|
|
65
67
|
const {siteDir, generatedFilesDir, baseUrl, siteConfig} = context;
|
|
66
68
|
|
|
67
|
-
const versionsMetadata = readVersionsMetadata({context, options});
|
|
69
|
+
const versionsMetadata = await readVersionsMetadata({context, options});
|
|
68
70
|
|
|
69
71
|
const pluginId = options.id ?? DEFAULT_PLUGIN_ID;
|
|
70
72
|
|
|
@@ -79,14 +81,6 @@ export default function pluginContentDocs(
|
|
|
79
81
|
return {
|
|
80
82
|
name: 'docusaurus-plugin-content-docs',
|
|
81
83
|
|
|
82
|
-
getThemePath() {
|
|
83
|
-
return path.resolve(__dirname, './theme');
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
getTypeScriptThemePath() {
|
|
87
|
-
return path.resolve(__dirname, '..', 'src', 'theme');
|
|
88
|
-
},
|
|
89
|
-
|
|
90
84
|
extendCli(cli) {
|
|
91
85
|
const isDefaultPluginId = pluginId === DEFAULT_PLUGIN_ID;
|
|
92
86
|
|
package/src/lastUpdate.ts
CHANGED
|
@@ -43,12 +43,12 @@ export async function getFileLastUpdate(
|
|
|
43
43
|
return null;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const result = shell.exec(`git log -1 --format=%ct,%an ${filePath}`, {
|
|
46
|
+
const result = shell.exec(`git log -1 --format=%ct,%an "${filePath}"`, {
|
|
47
47
|
silent: true,
|
|
48
48
|
});
|
|
49
49
|
if (result.code !== 0) {
|
|
50
50
|
throw new Error(
|
|
51
|
-
`Retrieval of git history failed at ${filePath} with exit code ${result.code}: ${result.stderr}`,
|
|
51
|
+
`Retrieval of git history failed at "${filePath}" with exit code ${result.code}: ${result.stderr}`,
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
return getTimestampAndAuthor(result.stdout.trim());
|
package/src/markdown/index.ts
CHANGED
package/src/markdown/linkify.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {DocsMarkdownOption} from '../types';
|
|
8
|
+
import type {DocsMarkdownOption} from '../types';
|
|
9
9
|
import {getDocsDirPaths} from '../versions';
|
|
10
10
|
import {replaceMarkdownLinks} from '@docusaurus/utils';
|
|
11
11
|
|
package/src/numberPrefix.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {NumberPrefixParser} from '
|
|
8
|
+
import type {NumberPrefixParser} from '@docusaurus/plugin-content-docs';
|
|
9
9
|
|
|
10
10
|
// Best-effort to avoid parsing some patterns as number prefix
|
|
11
11
|
const IgnoredPrefixPatterns = (function () {
|
package/src/options.ts
CHANGED
|
@@ -6,14 +6,85 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
declare module '@docusaurus/plugin-content-docs' {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export type
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
import type {RemarkAndRehypePluginOptions} from '@docusaurus/mdx-loader';
|
|
10
|
+
|
|
11
|
+
export type NumberPrefixParser = (filename: string) => {
|
|
12
|
+
filename: string;
|
|
13
|
+
numberPrefix?: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type CategoryIndexMatcherParam = {
|
|
17
|
+
fileName: string;
|
|
18
|
+
directories: string[];
|
|
19
|
+
extension: string;
|
|
20
|
+
};
|
|
21
|
+
export type CategoryIndexMatcher = (
|
|
22
|
+
param: CategoryIndexMatcherParam,
|
|
23
|
+
) => boolean;
|
|
24
|
+
|
|
25
|
+
export type EditUrlFunction = (editUrlParams: {
|
|
26
|
+
version: string;
|
|
27
|
+
versionDocsDirPath: string;
|
|
28
|
+
docPath: string;
|
|
29
|
+
permalink: string;
|
|
30
|
+
locale: string;
|
|
31
|
+
}) => string | undefined;
|
|
32
|
+
|
|
33
|
+
export type MetadataOptions = {
|
|
34
|
+
routeBasePath: string;
|
|
35
|
+
editUrl?: string | EditUrlFunction;
|
|
36
|
+
editCurrentVersion: boolean;
|
|
37
|
+
editLocalizedFiles: boolean;
|
|
38
|
+
showLastUpdateTime?: boolean;
|
|
39
|
+
showLastUpdateAuthor?: boolean;
|
|
40
|
+
numberPrefixParser: NumberPrefixParser;
|
|
41
|
+
};
|
|
15
42
|
|
|
16
|
-
export type {
|
|
43
|
+
export type PathOptions = {
|
|
44
|
+
path: string;
|
|
45
|
+
sidebarPath?: string | false | undefined;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// TODO support custom version banner? {type: "error", content: "html content"}
|
|
49
|
+
export type VersionBanner = 'unreleased' | 'unmaintained';
|
|
50
|
+
export type VersionOptions = {
|
|
51
|
+
path?: string;
|
|
52
|
+
label?: string;
|
|
53
|
+
banner?: 'none' | VersionBanner;
|
|
54
|
+
badge?: boolean;
|
|
55
|
+
className?: string;
|
|
56
|
+
};
|
|
57
|
+
export type VersionsOptions = {
|
|
58
|
+
lastVersion?: string;
|
|
59
|
+
versions: Record<string, VersionOptions>;
|
|
60
|
+
onlyIncludeVersions?: string[];
|
|
61
|
+
};
|
|
62
|
+
export type SidebarOptions = {
|
|
63
|
+
sidebarCollapsible: boolean;
|
|
64
|
+
sidebarCollapsed: boolean;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type PluginOptions = MetadataOptions &
|
|
68
|
+
PathOptions &
|
|
69
|
+
VersionsOptions &
|
|
70
|
+
RemarkAndRehypePluginOptions &
|
|
71
|
+
SidebarOptions & {
|
|
72
|
+
id: string;
|
|
73
|
+
include: string[];
|
|
74
|
+
exclude: string[];
|
|
75
|
+
docLayoutComponent: string;
|
|
76
|
+
docItemComponent: string;
|
|
77
|
+
docTagDocListComponent: string;
|
|
78
|
+
docTagsListComponent: string;
|
|
79
|
+
docCategoryGeneratedIndexComponent: string;
|
|
80
|
+
admonitions: Record<string, unknown>;
|
|
81
|
+
disableVersioning: boolean;
|
|
82
|
+
includeCurrentVersion: boolean;
|
|
83
|
+
sidebarItemsGenerator: import('./sidebars/types').SidebarItemsGeneratorOption;
|
|
84
|
+
tagsBasePath: string;
|
|
85
|
+
};
|
|
86
|
+
export type Options = Partial<PluginOptions>;
|
|
87
|
+
export type SidebarsConfig = import('./sidebars/types').SidebarsConfig;
|
|
17
88
|
|
|
18
89
|
export type PropNavigationLink = {
|
|
19
90
|
readonly title: string;
|
|
@@ -42,6 +113,8 @@ declare module '@docusaurus/plugin-content-docs' {
|
|
|
42
113
|
export type PropCategoryGeneratedIndex = {
|
|
43
114
|
title: string;
|
|
44
115
|
description?: string;
|
|
116
|
+
image?: string;
|
|
117
|
+
keywords?: string | readonly string[];
|
|
45
118
|
slug: string;
|
|
46
119
|
permalink: string;
|
|
47
120
|
navigation: PropNavigation;
|
|
@@ -238,17 +311,54 @@ declare module '@theme/Seo' {
|
|
|
238
311
|
export default Seo;
|
|
239
312
|
}
|
|
240
313
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
type
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
314
|
+
// TODO until TS supports exports field... hope it's in 4.6
|
|
315
|
+
declare module '@docusaurus/plugin-content-docs/client' {
|
|
316
|
+
export type ActivePlugin = {
|
|
317
|
+
pluginId: string;
|
|
318
|
+
pluginData: GlobalPluginData;
|
|
319
|
+
};
|
|
320
|
+
export type ActiveDocContext = {
|
|
321
|
+
activeVersion?: GlobalVersion;
|
|
322
|
+
activeDoc?: GlobalDoc;
|
|
323
|
+
alternateDocVersions: Record<string, GlobalDoc>;
|
|
324
|
+
};
|
|
325
|
+
export type GlobalDoc = {
|
|
326
|
+
id: string;
|
|
327
|
+
path: string;
|
|
328
|
+
sidebar: string | undefined;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
export type GlobalVersion = {
|
|
332
|
+
name: string;
|
|
333
|
+
label: string;
|
|
334
|
+
isLast: boolean;
|
|
335
|
+
path: string;
|
|
336
|
+
mainDocId: string; // home doc (if docs homepage configured), or first doc
|
|
337
|
+
docs: GlobalDoc[];
|
|
338
|
+
sidebars?: Record<string, GlobalSidebar>;
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
export type GlobalSidebarLink = {
|
|
342
|
+
label: string;
|
|
343
|
+
path: string;
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
export type GlobalSidebar = {
|
|
347
|
+
link?: GlobalSidebarLink;
|
|
348
|
+
// ... we may add other things here later
|
|
349
|
+
};
|
|
350
|
+
export type GlobalPluginData = {
|
|
351
|
+
path: string;
|
|
352
|
+
versions: GlobalVersion[];
|
|
353
|
+
};
|
|
354
|
+
export type DocVersionSuggestions = {
|
|
355
|
+
// suggest the latest version
|
|
356
|
+
latestVersionSuggestion: GlobalVersion;
|
|
357
|
+
// suggest the same doc, in latest version (if exist)
|
|
358
|
+
latestDocSuggestion?: GlobalDoc;
|
|
359
|
+
};
|
|
360
|
+
export type GetActivePluginOptions = {failfast?: boolean}; // use fail-fast option if you know for sure one plugin instance is active
|
|
361
|
+
|
|
252
362
|
export const useAllDocsData: () => Record<string, GlobalPluginData>;
|
|
253
363
|
export const useDocsData: (pluginId?: string) => GlobalPluginData;
|
|
254
364
|
export const useActivePlugin: (
|