@docusaurus/plugin-content-docs 0.0.0-4713 → 0.0.0-4717
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.js +1 -1
- package/lib/numberPrefix.js +16 -21
- package/package.json +9 -9
- package/src/cli.ts +1 -1
- package/src/numberPrefix.ts +18 -28
package/lib/cli.js
CHANGED
|
@@ -46,7 +46,7 @@ async function cliDocsVersionCommand(version, siteDir, pluginId, options) {
|
|
|
46
46
|
// Since we are going to create `version-${version}` folder, we need to make
|
|
47
47
|
// sure it's a valid pathname.
|
|
48
48
|
// eslint-disable-next-line no-control-regex
|
|
49
|
-
if (/[<>:"|?*\x00-\x1F]
|
|
49
|
+
if (/[<>:"|?*\x00-\x1F]/.test(version)) {
|
|
50
50
|
throw new Error(`${pluginIdLogPrefix}: invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0.`);
|
|
51
51
|
}
|
|
52
52
|
if (/^\.\.?$/.test(version)) {
|
package/lib/numberPrefix.js
CHANGED
|
@@ -8,33 +8,28 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.stripPathNumberPrefixes = exports.stripNumberPrefix = exports.DisabledNumberPrefixParser = exports.DefaultNumberPrefixParser = void 0;
|
|
10
10
|
// Best-effort to avoid parsing some patterns as number prefix
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return new RegExp(`${DateLikePrefixRegex.source}|${VersionLikePrefixRegex.source}`);
|
|
21
|
-
})();
|
|
22
|
-
const NumberPrefixRegex = /^(?<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
|
+
const numberPrefixPattern = /^(?<numberPrefix>\d+)\s*[-_.]+\s*(?<suffix>[^-_.\s].*)$/;
|
|
23
20
|
// 0-myDoc => {filename: myDoc, numberPrefix: 0}
|
|
24
21
|
// 003 - myDoc => {filename: myDoc, numberPrefix: 3}
|
|
25
22
|
const DefaultNumberPrefixParser = (filename) => {
|
|
26
|
-
if (
|
|
23
|
+
if (ignoredPrefixPattern.test(filename)) {
|
|
24
|
+
return { filename, numberPrefix: undefined };
|
|
25
|
+
}
|
|
26
|
+
const match = numberPrefixPattern.exec(filename);
|
|
27
|
+
if (!match) {
|
|
27
28
|
return { filename, numberPrefix: undefined };
|
|
28
29
|
}
|
|
29
|
-
const match = NumberPrefixRegex.exec(filename);
|
|
30
|
-
const cleanFileName = match?.groups?.suffix ?? filename;
|
|
31
|
-
const numberPrefixString = match?.groups?.numberPrefix;
|
|
32
|
-
const numberPrefix = numberPrefixString
|
|
33
|
-
? parseInt(numberPrefixString, 10)
|
|
34
|
-
: undefined;
|
|
35
30
|
return {
|
|
36
|
-
filename:
|
|
37
|
-
numberPrefix,
|
|
31
|
+
filename: match.groups.suffix,
|
|
32
|
+
numberPrefix: parseInt(match.groups.numberPrefix, 10),
|
|
38
33
|
};
|
|
39
34
|
};
|
|
40
35
|
exports.DefaultNumberPrefixParser = DefaultNumberPrefixParser;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4717",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@docusaurus/core": "0.0.0-
|
|
27
|
-
"@docusaurus/logger": "0.0.0-
|
|
28
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
29
|
-
"@docusaurus/utils": "0.0.0-
|
|
30
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
26
|
+
"@docusaurus/core": "0.0.0-4717",
|
|
27
|
+
"@docusaurus/logger": "0.0.0-4717",
|
|
28
|
+
"@docusaurus/mdx-loader": "0.0.0-4717",
|
|
29
|
+
"@docusaurus/utils": "0.0.0-4717",
|
|
30
|
+
"@docusaurus/utils-validation": "0.0.0-4717",
|
|
31
31
|
"combine-promises": "^1.1.0",
|
|
32
32
|
"fs-extra": "^10.0.1",
|
|
33
33
|
"import-fresh": "^3.3.0",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"webpack": "^5.70.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
43
|
-
"@docusaurus/types": "0.0.0-
|
|
42
|
+
"@docusaurus/module-type-aliases": "0.0.0-4717",
|
|
43
|
+
"@docusaurus/types": "0.0.0-4717",
|
|
44
44
|
"@types/js-yaml": "^4.0.5",
|
|
45
45
|
"@types/picomatch": "^2.3.0",
|
|
46
46
|
"commander": "^5.1.0",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": ">=14"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "9502e3b866460309be7a908034640481eb9a96ba"
|
|
60
60
|
}
|
package/src/cli.ts
CHANGED
|
@@ -88,7 +88,7 @@ export async function cliDocsVersionCommand(
|
|
|
88
88
|
// Since we are going to create `version-${version}` folder, we need to make
|
|
89
89
|
// sure it's a valid pathname.
|
|
90
90
|
// eslint-disable-next-line no-control-regex
|
|
91
|
-
if (/[<>:"|?*\x00-\x1F]
|
|
91
|
+
if (/[<>:"|?*\x00-\x1F]/.test(version)) {
|
|
92
92
|
throw new Error(
|
|
93
93
|
`${pluginIdLogPrefix}: invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0.`,
|
|
94
94
|
);
|
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
|
|