@docusaurus/plugin-content-docs 2.0.0-beta.16 → 2.0.0-beta.19
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 +5 -7
- package/lib/cli.d.ts +3 -2
- package/lib/cli.js +49 -41
- package/lib/client/docsClientUtils.d.ts +8 -5
- package/lib/client/docsClientUtils.js +13 -15
- package/lib/client/index.d.ts +12 -9
- package/lib/client/index.js +30 -33
- package/lib/constants.d.ts +4 -0
- package/lib/constants.js +4 -1
- package/lib/docs.d.ts +8 -15
- package/lib/docs.js +34 -39
- package/lib/{docFrontMatter.d.ts → frontMatter.d.ts} +4 -2
- package/lib/{docFrontMatter.js → frontMatter.js} +3 -0
- package/lib/globalData.d.ts +3 -7
- package/lib/globalData.js +9 -13
- package/lib/index.d.ts +1 -2
- package/lib/index.js +33 -26
- package/lib/lastUpdate.d.ts +4 -6
- package/lib/lastUpdate.js +14 -5
- package/lib/markdown/index.js +1 -1
- package/lib/markdown/linkify.js +5 -2
- package/lib/numberPrefix.js +16 -22
- package/lib/options.d.ts +3 -5
- package/lib/options.js +6 -5
- package/lib/props.d.ts +3 -3
- package/lib/props.js +10 -10
- package/lib/routes.d.ts +5 -4
- package/lib/routes.js +10 -24
- package/lib/server-export.d.ts +2 -1
- package/lib/server-export.js +3 -4
- package/lib/sidebars/generator.js +63 -44
- package/lib/sidebars/index.js +20 -16
- package/lib/sidebars/normalization.js +3 -3
- package/lib/sidebars/postProcessor.js +18 -25
- package/lib/sidebars/processor.d.ts +3 -1
- package/lib/sidebars/processor.js +17 -6
- package/lib/sidebars/types.d.ts +31 -19
- package/lib/sidebars/utils.d.ts +17 -6
- package/lib/sidebars/utils.js +27 -37
- package/lib/sidebars/validation.d.ts +3 -1
- package/lib/sidebars/validation.js +1 -0
- package/lib/slug.d.ts +1 -2
- package/lib/slug.js +4 -5
- package/lib/tags.d.ts +2 -1
- package/lib/tags.js +2 -2
- package/lib/translations.d.ts +3 -3
- package/lib/translations.js +28 -81
- package/lib/types.d.ts +10 -95
- package/lib/versions/files.d.ts +44 -0
- package/lib/versions/files.js +142 -0
- package/lib/versions/index.d.ts +36 -0
- package/lib/versions/index.js +155 -0
- package/lib/versions/validation.d.ts +17 -0
- package/lib/versions/validation.js +71 -0
- package/package.json +14 -12
- package/src/categoryGeneratedIndex.ts +10 -9
- package/src/cli.ts +64 -69
- package/src/client/docsClientUtils.ts +14 -16
- package/src/client/index.ts +42 -43
- package/src/constants.ts +4 -2
- package/src/deps.d.ts +1 -1
- package/src/docs.ts +48 -51
- package/src/{docFrontMatter.ts → frontMatter.ts} +9 -6
- package/src/globalData.ts +15 -16
- package/src/index.ts +45 -40
- package/src/lastUpdate.ts +20 -8
- package/src/markdown/index.ts +1 -3
- package/src/markdown/linkify.ts +6 -3
- package/src/numberPrefix.ts +18 -28
- package/src/options.ts +6 -8
- package/src/plugin-content-docs.d.ts +457 -116
- package/src/props.ts +12 -9
- package/src/routes.ts +13 -39
- package/src/server-export.ts +1 -3
- package/src/sidebars/generator.ts +88 -59
- package/src/sidebars/index.ts +20 -15
- package/src/sidebars/normalization.ts +1 -1
- package/src/sidebars/postProcessor.ts +6 -11
- package/src/sidebars/processor.ts +27 -14
- package/src/sidebars/types.ts +25 -23
- package/src/sidebars/utils.ts +45 -46
- package/src/sidebars/validation.ts +4 -3
- package/src/slug.ts +7 -6
- package/src/tags.ts +3 -2
- package/src/translations.ts +32 -84
- package/src/types.ts +15 -107
- package/src/versions/files.ts +220 -0
- package/src/versions/index.ts +247 -0
- package/src/versions/validation.ts +113 -0
- package/lib/versions.d.ts +0 -41
- package/lib/versions.js +0 -329
- package/src/versions.ts +0 -606
package/src/numberPrefix.ts
CHANGED
|
@@ -8,43 +8,33 @@
|
|
|
8
8
|
import type {NumberPrefixParser} from '@docusaurus/plugin-content-docs';
|
|
9
9
|
|
|
10
10
|
// Best-effort to avoid parsing some patterns as number prefix
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return new RegExp(
|
|
24
|
-
`${DateLikePrefixRegex.source}|${VersionLikePrefixRegex.source}`,
|
|
25
|
-
);
|
|
26
|
-
})();
|
|
27
|
-
|
|
28
|
-
const NumberPrefixRegex =
|
|
29
|
-
/^(?<numberPrefix>\d+)(?<separator>\s*[-_.]+\s*)(?<suffix>.*)$/;
|
|
11
|
+
// ignore common date-like patterns: https://github.com/facebook/docusaurus/issues/4640
|
|
12
|
+
// ignore common versioning patterns: https://github.com/facebook/docusaurus/issues/4653
|
|
13
|
+
// Both of them would look like 7.0-foo or 2021-11-foo
|
|
14
|
+
// note: we could try to parse float numbers in filenames, but that is probably
|
|
15
|
+
// not worth it, as a version such as "8.0" can be interpreted as either a
|
|
16
|
+
// version or a float. User can configure her own NumberPrefixParser if she
|
|
17
|
+
// wants 8.0 to be interpreted as a float
|
|
18
|
+
const ignoredPrefixPattern = /^\d+[-_.]\d+/;
|
|
19
|
+
|
|
20
|
+
const numberPrefixPattern =
|
|
21
|
+
/^(?<numberPrefix>\d+)\s*[-_.]+\s*(?<suffix>[^-_.\s].*)$/;
|
|
30
22
|
|
|
31
23
|
// 0-myDoc => {filename: myDoc, numberPrefix: 0}
|
|
32
24
|
// 003 - myDoc => {filename: myDoc, numberPrefix: 3}
|
|
33
25
|
export const DefaultNumberPrefixParser: NumberPrefixParser = (
|
|
34
26
|
filename: string,
|
|
35
27
|
) => {
|
|
36
|
-
if (
|
|
28
|
+
if (ignoredPrefixPattern.test(filename)) {
|
|
29
|
+
return {filename, numberPrefix: undefined};
|
|
30
|
+
}
|
|
31
|
+
const match = numberPrefixPattern.exec(filename);
|
|
32
|
+
if (!match) {
|
|
37
33
|
return {filename, numberPrefix: undefined};
|
|
38
34
|
}
|
|
39
|
-
const match = NumberPrefixRegex.exec(filename);
|
|
40
|
-
const cleanFileName = match?.groups?.suffix ?? filename;
|
|
41
|
-
const numberPrefixString = match?.groups?.numberPrefix;
|
|
42
|
-
const numberPrefix = numberPrefixString
|
|
43
|
-
? parseInt(numberPrefixString, 10)
|
|
44
|
-
: undefined;
|
|
45
35
|
return {
|
|
46
|
-
filename:
|
|
47
|
-
numberPrefix,
|
|
36
|
+
filename: match.groups!.suffix!,
|
|
37
|
+
numberPrefix: parseInt(match.groups!.numberPrefix!, 10),
|
|
48
38
|
};
|
|
49
39
|
};
|
|
50
40
|
|
package/src/options.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 {PluginOptions} from '@docusaurus/plugin-content-docs';
|
|
8
|
+
import type {PluginOptions, Options} from '@docusaurus/plugin-content-docs';
|
|
9
9
|
import {
|
|
10
10
|
Joi,
|
|
11
11
|
RemarkPluginsSchema,
|
|
@@ -15,10 +15,7 @@ import {
|
|
|
15
15
|
} from '@docusaurus/utils-validation';
|
|
16
16
|
import {GlobExcludeDefault} from '@docusaurus/utils';
|
|
17
17
|
|
|
18
|
-
import type {
|
|
19
|
-
OptionValidationContext,
|
|
20
|
-
ValidationResult,
|
|
21
|
-
} from '@docusaurus/types';
|
|
18
|
+
import type {OptionValidationContext} from '@docusaurus/types';
|
|
22
19
|
import logger from '@docusaurus/logger';
|
|
23
20
|
import admonitions from 'remark-admonitions';
|
|
24
21
|
import {DefaultSidebarItemsGenerator} from './sidebars/generator';
|
|
@@ -70,7 +67,7 @@ const VersionsOptionsSchema = Joi.object()
|
|
|
70
67
|
.pattern(Joi.string().required(), VersionOptionsSchema)
|
|
71
68
|
.default(DEFAULT_OPTIONS.versions);
|
|
72
69
|
|
|
73
|
-
|
|
70
|
+
const OptionsSchema = Joi.object<PluginOptions>({
|
|
74
71
|
path: Joi.string().default(DEFAULT_OPTIONS.path),
|
|
75
72
|
editUrl: Joi.alternatives().try(URISchema, Joi.function()),
|
|
76
73
|
editCurrentVersion: Joi.boolean().default(DEFAULT_OPTIONS.editCurrentVersion),
|
|
@@ -80,6 +77,7 @@ export const OptionsSchema = Joi.object({
|
|
|
80
77
|
// .allow('') ""
|
|
81
78
|
.default(DEFAULT_OPTIONS.routeBasePath),
|
|
82
79
|
tagsBasePath: Joi.string().default(DEFAULT_OPTIONS.tagsBasePath),
|
|
80
|
+
// @ts-expect-error: deprecated
|
|
83
81
|
homePageId: Joi.any().forbidden().messages({
|
|
84
82
|
'any.unknown':
|
|
85
83
|
'The docs plugin option homePageId is not supported anymore. To make a doc the "home", please add "slug: /" in its front matter. See: https://docusaurus.io/docs/next/docs-introduction#home-page-docs',
|
|
@@ -146,7 +144,7 @@ export const OptionsSchema = Joi.object({
|
|
|
146
144
|
export function validateOptions({
|
|
147
145
|
validate,
|
|
148
146
|
options: userOptions,
|
|
149
|
-
}: OptionValidationContext<PluginOptions>):
|
|
147
|
+
}: OptionValidationContext<Options, PluginOptions>): PluginOptions {
|
|
150
148
|
let options = userOptions;
|
|
151
149
|
|
|
152
150
|
if (options.sidebarCollapsible === false) {
|
|
@@ -168,7 +166,7 @@ export function validateOptions({
|
|
|
168
166
|
}
|
|
169
167
|
}
|
|
170
168
|
|
|
171
|
-
const normalizedOptions = validate(OptionsSchema, options);
|
|
169
|
+
const normalizedOptions = validate(OptionsSchema, options) as PluginOptions;
|
|
172
170
|
|
|
173
171
|
if (normalizedOptions.admonitions) {
|
|
174
172
|
normalizedOptions.remarkPlugins = normalizedOptions.remarkPlugins.concat([
|