@docusaurus/utils 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/dataFileUtils.d.ts +24 -0
- package/lib/dataFileUtils.d.ts.map +1 -0
- package/lib/dataFileUtils.js +65 -0
- package/lib/dataFileUtils.js.map +1 -0
- package/lib/globUtils.d.ts.map +1 -1
- package/lib/globUtils.js +2 -2
- package/lib/globUtils.js.map +1 -1
- package/lib/index.d.ts +18 -41
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +40 -139
- package/lib/index.js.map +1 -1
- package/lib/markdownLinks.d.ts.map +1 -1
- package/lib/markdownLinks.js +12 -4
- package/lib/markdownLinks.js.map +1 -1
- package/lib/markdownParser.d.ts +4 -3
- package/lib/markdownParser.d.ts.map +1 -1
- package/lib/markdownParser.js +30 -18
- package/lib/markdownParser.js.map +1 -1
- package/lib/pathUtils.d.ts +29 -0
- package/lib/pathUtils.d.ts.map +1 -1
- package/lib/pathUtils.js +69 -5
- package/lib/pathUtils.js.map +1 -1
- package/lib/tags.d.ts +1 -1
- package/lib/tags.d.ts.map +1 -1
- package/lib/tags.js +4 -5
- package/lib/tags.js.map +1 -1
- package/lib/{normalizeUrl.d.ts → urlUtils.d.ts} +2 -1
- package/lib/urlUtils.d.ts.map +1 -0
- package/lib/{normalizeUrl.js → urlUtils.js} +17 -4
- package/lib/{normalizeUrl.js.map → urlUtils.js.map} +1 -1
- package/lib/webpackUtils.js +3 -3
- package/lib/webpackUtils.js.map +1 -1
- package/package.json +6 -5
- package/src/dataFileUtils.ts +90 -0
- package/src/globUtils.ts +2 -1
- package/src/index.ts +48 -173
- package/src/markdownLinks.ts +10 -3
- package/src/markdownParser.ts +32 -20
- package/src/pathUtils.ts +70 -4
- package/src/tags.ts +5 -4
- package/src/{normalizeUrl.ts → urlUtils.ts} +17 -2
- package/src/webpackUtils.ts +4 -4
- package/lib/escapePath.d.ts +0 -18
- package/lib/escapePath.d.ts.map +0 -1
- package/lib/escapePath.js +0 -26
- package/lib/escapePath.js.map +0 -1
- package/lib/mdxUtils.d.ts +0 -17
- package/lib/mdxUtils.d.ts.map +0 -1
- package/lib/mdxUtils.js +0 -31
- package/lib/mdxUtils.js.map +0 -1
- package/lib/normalizeUrl.d.ts.map +0 -1
- package/lib/posixPath.d.ts +0 -15
- package/lib/posixPath.d.ts.map +0 -1
- package/lib/posixPath.js +0 -29
- package/lib/posixPath.js.map +0 -1
- package/src/escapePath.ts +0 -23
- package/src/mdxUtils.ts +0 -32
- package/src/posixPath.ts +0 -27
package/lib/markdownParser.d.ts
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
export declare function parseMarkdownHeadingId(heading: string): {
|
|
8
|
+
text: string;
|
|
9
|
+
id?: string;
|
|
10
|
+
};
|
|
7
11
|
export declare function createExcerpt(fileString: string): string | undefined;
|
|
8
12
|
export declare function parseFrontMatter(markdownFileContent: string): {
|
|
9
13
|
frontMatter: Record<string, unknown>;
|
|
@@ -24,8 +28,5 @@ declare type ParsedMarkdown = {
|
|
|
24
28
|
export declare function parseMarkdownString(markdownFileContent: string, options?: {
|
|
25
29
|
removeContentTitle?: boolean;
|
|
26
30
|
}): ParsedMarkdown;
|
|
27
|
-
export declare function parseMarkdownFile(source: string, options?: {
|
|
28
|
-
removeContentTitle?: boolean;
|
|
29
|
-
}): Promise<ParsedMarkdown>;
|
|
30
31
|
export {};
|
|
31
32
|
//# sourceMappingURL=markdownParser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdownParser.d.ts","sourceRoot":"","sources":["../src/markdownParser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"markdownParser.d.ts","sourceRoot":"","sources":["../src/markdownParser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAWA;AAKD,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAuEpE;AAED,wBAAgB,gBAAgB,CAAC,mBAAmB,EAAE,MAAM,GAAG;IAC7D,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,EAAE,MAAM,CAAC;CACjB,CAMA;AAYD,wBAAgB,yBAAyB,CACvC,gBAAgB,EAAE,MAAM,EACxB,OAAO,CAAC,EAAE;IAAC,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAAC,GACvC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;CAAC,CAmCrD;AAED,aAAK,cAAc,GAAG;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,mBAAmB,EAAE,MAAM,EAC3B,OAAO,CAAC,EAAE;IAAC,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAAC,GACvC,cAAc,CAuBhB"}
|
package/lib/markdownParser.js
CHANGED
|
@@ -6,11 +6,26 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.parseMarkdownString = exports.parseMarkdownContentTitle = exports.parseFrontMatter = exports.createExcerpt = exports.parseMarkdownHeadingId = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
12
|
-
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
13
12
|
const gray_matter_1 = (0, tslib_1.__importDefault)(require("gray-matter"));
|
|
13
|
+
// Input: ## Some heading {#some-heading}
|
|
14
|
+
// Output: {text: "## Some heading", id: "some-heading"}
|
|
15
|
+
function parseMarkdownHeadingId(heading) {
|
|
16
|
+
const customHeadingIdRegex = /^(.*?)\s*\{#([\w-]+)\}$/;
|
|
17
|
+
const matches = customHeadingIdRegex.exec(heading);
|
|
18
|
+
if (matches) {
|
|
19
|
+
return {
|
|
20
|
+
text: matches[1],
|
|
21
|
+
id: matches[2],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return { text: heading, id: undefined };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.parseMarkdownHeadingId = parseMarkdownHeadingId;
|
|
14
29
|
// Hacky way of stripping out import statements from the excerpt
|
|
15
30
|
// TODO: Find a better way to do so, possibly by compiling the Markdown content,
|
|
16
31
|
// stripping out HTML tags and obtaining the first line.
|
|
@@ -21,6 +36,7 @@ function createExcerpt(fileString) {
|
|
|
21
36
|
.replace(/^[^\n]*\n[=]+/g, '')
|
|
22
37
|
.split('\n');
|
|
23
38
|
let inCode = false;
|
|
39
|
+
let lastCodeFence = '';
|
|
24
40
|
/* eslint-disable no-continue */
|
|
25
41
|
// eslint-disable-next-line no-restricted-syntax
|
|
26
42
|
for (const fileLine of fileLines) {
|
|
@@ -34,7 +50,14 @@ function createExcerpt(fileString) {
|
|
|
34
50
|
}
|
|
35
51
|
// Skip code block line.
|
|
36
52
|
if (fileLine.trim().startsWith('```')) {
|
|
37
|
-
|
|
53
|
+
if (!inCode) {
|
|
54
|
+
inCode = true;
|
|
55
|
+
[lastCodeFence] = fileLine.trim().match(/^`+/);
|
|
56
|
+
// If we are in a ````-fenced block, all ``` would be plain text instead of fences
|
|
57
|
+
}
|
|
58
|
+
else if (fileLine.trim().match(/^`+/)[0].length >= lastCodeFence.length) {
|
|
59
|
+
inCode = false;
|
|
60
|
+
}
|
|
38
61
|
continue;
|
|
39
62
|
}
|
|
40
63
|
else if (inCode) {
|
|
@@ -74,11 +97,10 @@ function createExcerpt(fileString) {
|
|
|
74
97
|
}
|
|
75
98
|
exports.createExcerpt = createExcerpt;
|
|
76
99
|
function parseFrontMatter(markdownFileContent) {
|
|
77
|
-
var _a;
|
|
78
100
|
const { data, content } = (0, gray_matter_1.default)(markdownFileContent);
|
|
79
101
|
return {
|
|
80
|
-
frontMatter: data
|
|
81
|
-
content:
|
|
102
|
+
frontMatter: data,
|
|
103
|
+
content: content.trim(),
|
|
82
104
|
};
|
|
83
105
|
}
|
|
84
106
|
exports.parseFrontMatter = parseFrontMatter;
|
|
@@ -130,20 +152,10 @@ function parseMarkdownString(markdownFileContent, options) {
|
|
|
130
152
|
};
|
|
131
153
|
}
|
|
132
154
|
catch (e) {
|
|
133
|
-
logger_1.default.error(`Error while parsing Markdown
|
|
134
|
-
This can happen if you use special characters in
|
|
155
|
+
logger_1.default.error(`Error while parsing Markdown front matter.
|
|
156
|
+
This can happen if you use special characters in front matter values (try using double quotes around that value).`);
|
|
135
157
|
throw e;
|
|
136
158
|
}
|
|
137
159
|
}
|
|
138
160
|
exports.parseMarkdownString = parseMarkdownString;
|
|
139
|
-
async function parseMarkdownFile(source, options) {
|
|
140
|
-
const markdownString = await fs_extra_1.default.readFile(source, 'utf-8');
|
|
141
|
-
try {
|
|
142
|
-
return parseMarkdownString(markdownString, options);
|
|
143
|
-
}
|
|
144
|
-
catch (e) {
|
|
145
|
-
throw new Error(`Error while parsing Markdown file ${source}: "${e.message}".`);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
exports.parseMarkdownFile = parseMarkdownFile;
|
|
149
161
|
//# sourceMappingURL=markdownParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdownParser.js","sourceRoot":"","sources":["../src/markdownParser.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,6EAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"markdownParser.js","sourceRoot":"","sources":["../src/markdownParser.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,6EAAwC;AACxC,2EAAiC;AAEjC,yCAAyC;AACzC,wDAAwD;AACxD,SAAgB,sBAAsB,CAAC,OAAe;IAIpD,MAAM,oBAAoB,GAAG,yBAAyB,CAAC;IACvD,MAAM,OAAO,GAAG,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnD,IAAI,OAAO,EAAE;QACX,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;YAChB,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;SACf,CAAC;KACH;SAAM;QACL,OAAO,EAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAC,CAAC;KACvC;AACH,CAAC;AAdD,wDAcC;AAED,gEAAgE;AAChE,gFAAgF;AAChF,wDAAwD;AACxD,SAAgB,aAAa,CAAC,UAAkB;IAC9C,MAAM,SAAS,GAAG,UAAU;SACzB,QAAQ,EAAE;QACX,kCAAkC;SACjC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC;SAC7B,KAAK,CAAC,IAAI,CAAC,CAAC;IACf,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,aAAa,GAAG,EAAE,CAAC;IAEvB,gCAAgC;IAChC,gDAAgD;IAChD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;QAChC,mBAAmB;QACnB,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE;YACpB,SAAS;SACV;QAED,kCAAkC;QAClC,IAAI,6CAA6C,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;YAChE,SAAS;SACV;QAED,wBAAwB;QACxB,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,UAAU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=> boolean;
|
|
8
8
|
export declare const shortName: (str: string) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Convert Windows backslash paths to posix style paths.
|
|
11
|
+
* E.g: endi\lie -> endi/lie
|
|
12
|
+
*
|
|
13
|
+
* Returns original path if the posix counterpart is not valid Windows path.
|
|
14
|
+
* This makes the legacy code that uses posixPath safe; but also makes it less
|
|
15
|
+
* useful when you actually want a path with forward slashes (e.g. for URL)
|
|
16
|
+
*
|
|
17
|
+
* Adopted from https://github.com/sindresorhus/slash/blob/main/index.js
|
|
18
|
+
*/
|
|
19
|
+
export declare function posixPath(str: string): string;
|
|
20
|
+
export declare function toMessageRelativeFilePath(filePath: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Alias filepath relative to site directory, very useful so that we
|
|
23
|
+
* don't expose user's site structure.
|
|
24
|
+
* Example: some/path/to/website/docs/foo.md -> @site/docs/foo.md
|
|
25
|
+
*/
|
|
26
|
+
export declare function aliasedSitePath(filePath: string, siteDir: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* When you have a path like C:\X\Y
|
|
29
|
+
* It is not safe to use directly when generating code
|
|
30
|
+
* For example, this would fail due to unescaped \: `<img src={require('${filePath}')} />`
|
|
31
|
+
* But this would work: `<img src={require('${escapePath(filePath)}')} />`
|
|
32
|
+
*
|
|
33
|
+
* posixPath can't be used in all cases, because forward slashes are only valid
|
|
34
|
+
* Windows paths when they don't contain non-ascii characters, and posixPath
|
|
35
|
+
* doesn't escape those that fail to be converted.
|
|
36
|
+
*/
|
|
37
|
+
export declare function escapePath(str: string): string;
|
|
9
38
|
//# sourceMappingURL=pathUtils.d.ts.map
|
package/lib/pathUtils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathUtils.d.ts","sourceRoot":"","sources":["../src/pathUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"pathUtils.d.ts","sourceRoot":"","sources":["../src/pathUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH,eAAO,MAAM,aAAa,QAAS,MAAM,KAAG,OAIgC,CAAC;AAE7E,eAAO,MAAM,SAAS,QAAS,MAAM,KAAG,MAiBvC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAW7C;AASD,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAElE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAKzE;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK9C"}
|
package/lib/pathUtils.js
CHANGED
|
@@ -6,21 +6,25 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.shortName = exports.isNameTooLong = void 0;
|
|
9
|
+
exports.escapePath = exports.aliasedSitePath = exports.toMessageRelativeFilePath = exports.posixPath = exports.shortName = exports.isNameTooLong = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
10
11
|
// Based on https://github.com/gatsbyjs/gatsby/pull/21518/files
|
|
12
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
11
13
|
// MacOS (APFS) and Windows (NTFS) filename length limit = 255 chars, Others = 255 bytes
|
|
12
14
|
const MAX_PATH_SEGMENT_CHARS = 255;
|
|
13
15
|
const MAX_PATH_SEGMENT_BYTES = 255;
|
|
14
16
|
// Space for appending things to the string like file extensions and so on
|
|
15
17
|
const SPACE_FOR_APPENDING = 10;
|
|
16
|
-
const isMacOs = process.platform ===
|
|
17
|
-
const isWindows = process.platform ===
|
|
18
|
-
const isNameTooLong = (str) =>
|
|
18
|
+
const isMacOs = () => process.platform === 'darwin';
|
|
19
|
+
const isWindows = () => process.platform === 'win32';
|
|
20
|
+
const isNameTooLong = (str) =>
|
|
21
|
+
// This is actually not entirely correct: we can't assume FS from OS. But good enough?
|
|
22
|
+
isMacOs() || isWindows()
|
|
19
23
|
? str.length + SPACE_FOR_APPENDING > MAX_PATH_SEGMENT_CHARS // MacOS (APFS) and Windows (NTFS) filename length limit (255 chars)
|
|
20
24
|
: Buffer.from(str).length + SPACE_FOR_APPENDING > MAX_PATH_SEGMENT_BYTES; // Other (255 bytes)
|
|
21
25
|
exports.isNameTooLong = isNameTooLong;
|
|
22
26
|
const shortName = (str) => {
|
|
23
|
-
if (isMacOs || isWindows) {
|
|
27
|
+
if (isMacOs() || isWindows()) {
|
|
24
28
|
const overflowingChars = str.length - MAX_PATH_SEGMENT_CHARS;
|
|
25
29
|
return str.slice(0, str.length - overflowingChars - SPACE_FOR_APPENDING - 1);
|
|
26
30
|
}
|
|
@@ -31,4 +35,64 @@ const shortName = (str) => {
|
|
|
31
35
|
.toString();
|
|
32
36
|
};
|
|
33
37
|
exports.shortName = shortName;
|
|
38
|
+
/**
|
|
39
|
+
* Convert Windows backslash paths to posix style paths.
|
|
40
|
+
* E.g: endi\lie -> endi/lie
|
|
41
|
+
*
|
|
42
|
+
* Returns original path if the posix counterpart is not valid Windows path.
|
|
43
|
+
* This makes the legacy code that uses posixPath safe; but also makes it less
|
|
44
|
+
* useful when you actually want a path with forward slashes (e.g. for URL)
|
|
45
|
+
*
|
|
46
|
+
* Adopted from https://github.com/sindresorhus/slash/blob/main/index.js
|
|
47
|
+
*/
|
|
48
|
+
function posixPath(str) {
|
|
49
|
+
const isExtendedLengthPath = /^\\\\\?\\/.test(str);
|
|
50
|
+
// Forward slashes are only valid Windows paths when they don't contain non-ascii characters.
|
|
51
|
+
// eslint-disable-next-line no-control-regex
|
|
52
|
+
const hasNonAscii = /[^\u0000-\u0080]+/.test(str);
|
|
53
|
+
if (isExtendedLengthPath || hasNonAscii) {
|
|
54
|
+
return str;
|
|
55
|
+
}
|
|
56
|
+
return str.replace(/\\/g, '/');
|
|
57
|
+
}
|
|
58
|
+
exports.posixPath = posixPath;
|
|
59
|
+
// When you want to display a path in a message/warning/error,
|
|
60
|
+
// it's more convenient to:
|
|
61
|
+
// - make it relative to cwd()
|
|
62
|
+
// - convert to posix (ie not using windows \ path separator)
|
|
63
|
+
// This way, Jest tests can run more reliably on any computer/CI
|
|
64
|
+
// on both Unix/Windows
|
|
65
|
+
// For Windows users this is not perfect (as they see / instead of \) but it's probably good enough
|
|
66
|
+
function toMessageRelativeFilePath(filePath) {
|
|
67
|
+
return posixPath(path_1.default.relative(process.cwd(), filePath));
|
|
68
|
+
}
|
|
69
|
+
exports.toMessageRelativeFilePath = toMessageRelativeFilePath;
|
|
70
|
+
/**
|
|
71
|
+
* Alias filepath relative to site directory, very useful so that we
|
|
72
|
+
* don't expose user's site structure.
|
|
73
|
+
* Example: some/path/to/website/docs/foo.md -> @site/docs/foo.md
|
|
74
|
+
*/
|
|
75
|
+
function aliasedSitePath(filePath, siteDir) {
|
|
76
|
+
const relativePath = posixPath(path_1.default.relative(siteDir, filePath));
|
|
77
|
+
// Cannot use path.join() as it resolves '../' and removes
|
|
78
|
+
// the '@site'. Let webpack loader resolve it.
|
|
79
|
+
return `@site/${relativePath}`;
|
|
80
|
+
}
|
|
81
|
+
exports.aliasedSitePath = aliasedSitePath;
|
|
82
|
+
/**
|
|
83
|
+
* When you have a path like C:\X\Y
|
|
84
|
+
* It is not safe to use directly when generating code
|
|
85
|
+
* For example, this would fail due to unescaped \: `<img src={require('${filePath}')} />`
|
|
86
|
+
* But this would work: `<img src={require('${escapePath(filePath)}')} />`
|
|
87
|
+
*
|
|
88
|
+
* posixPath can't be used in all cases, because forward slashes are only valid
|
|
89
|
+
* Windows paths when they don't contain non-ascii characters, and posixPath
|
|
90
|
+
* doesn't escape those that fail to be converted.
|
|
91
|
+
*/
|
|
92
|
+
function escapePath(str) {
|
|
93
|
+
const escaped = JSON.stringify(str);
|
|
94
|
+
// Remove the " around the json string;
|
|
95
|
+
return escaped.substring(1, escaped.length - 1);
|
|
96
|
+
}
|
|
97
|
+
exports.escapePath = escapePath;
|
|
34
98
|
//# sourceMappingURL=pathUtils.js.map
|
package/lib/pathUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathUtils.js","sourceRoot":"","sources":["../src/pathUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG
|
|
1
|
+
{"version":3,"file":"pathUtils.js","sourceRoot":"","sources":["../src/pathUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,+DAA+D;AAE/D,6DAAwB;AAExB,wFAAwF;AACxF,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,0EAA0E;AAC1E,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC;AACpD,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;AAE9C,MAAM,aAAa,GAAG,CAAC,GAAW,EAAW,EAAE;AACpD,sFAAsF;AACtF,OAAO,EAAE,IAAI,SAAS,EAAE;IACtB,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,mBAAmB,GAAG,sBAAsB,CAAC,oEAAoE;IAChI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,mBAAmB,GAAG,sBAAsB,CAAC,CAAC,oBAAoB;AAJrF,QAAA,aAAa,iBAImD;AAEtE,MAAM,SAAS,GAAG,CAAC,GAAW,EAAU,EAAE;IAC/C,IAAI,OAAO,EAAE,IAAI,SAAS,EAAE,EAAE;QAC5B,MAAM,gBAAgB,GAAG,GAAG,CAAC,MAAM,GAAG,sBAAsB,CAAC;QAC7D,OAAO,GAAG,CAAC,KAAK,CACd,CAAC,EAC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;IACjE,0DAA0D;IAC1D,8CAA8C;IAC9C,OAAO,SAAS,YAAY,EAAE,CAAC;AACjC,CAAC;AALD,0CAKC;AAED;;;;;;;;;GASG;AACH,SAAgB,UAAU,CAAC,GAAW;IACpC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAEpC,uCAAuC;IACvC,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAClD,CAAC;AALD,gCAKC"}
|
package/lib/tags.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare type Tag = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare type FrontMatterTag = string | Tag;
|
|
12
12
|
export declare function normalizeFrontMatterTag(tagsPath: string, frontMatterTag: FrontMatterTag): Tag;
|
|
13
|
-
export declare function normalizeFrontMatterTags(tagsPath: string, frontMatterTags
|
|
13
|
+
export declare function normalizeFrontMatterTags(tagsPath: string, frontMatterTags?: FrontMatterTag[] | undefined): Tag[];
|
|
14
14
|
export declare type TaggedItemGroup<Item> = {
|
|
15
15
|
tag: Tag;
|
|
16
16
|
items: Item[];
|
package/lib/tags.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,oBAAY,GAAG,GAAG;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,oBAAY,cAAc,GAAG,MAAM,GAAG,GAAG,CAAC;AAE1C,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,cAAc,GAC7B,GAAG,CAyBL;AAED,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,MAAM,EAChB,eAAe,
|
|
1
|
+
{"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,oBAAY,GAAG,GAAG;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,oBAAY,cAAc,GAAG,MAAM,GAAG,GAAG,CAAC;AAE1C,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,cAAc,GAC7B,GAAG,CAyBL;AAED,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,MAAM,EAChB,eAAe,GAAE,cAAc,EAAE,GAAG,SAAc,GACjD,GAAG,EAAE,CAMP;AAED,oBAAY,eAAe,CAAC,IAAI,IAAI;IAClC,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,EAAE,IAAI,EAAE,CAAC;CACf,CAAC;AAOF,wBAAgB,gBAAgB,CAAC,IAAI,EACnC,KAAK,EAAE,IAAI,EAAE,EACb,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,EAAE,GACjC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC,CA6BvC"}
|
package/lib/tags.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.groupTaggedItems = exports.normalizeFrontMatterTags = exports.normalizeFrontMatterTag = void 0;
|
|
10
10
|
const lodash_1 = require("lodash");
|
|
11
|
-
const
|
|
11
|
+
const urlUtils_1 = require("./urlUtils");
|
|
12
12
|
function normalizeFrontMatterTag(tagsPath, frontMatterTag) {
|
|
13
13
|
function toTagObject(tagString) {
|
|
14
14
|
return {
|
|
@@ -21,7 +21,7 @@ function normalizeFrontMatterTag(tagsPath, frontMatterTag) {
|
|
|
21
21
|
// note: we always apply tagsPath on purpose
|
|
22
22
|
// for versioned docs, v1/doc.md and v2/doc.md tags with custom permalinks don't lead to the same created page
|
|
23
23
|
// tagsPath is different for each doc version
|
|
24
|
-
return (0,
|
|
24
|
+
return (0, urlUtils_1.normalizeUrl)([tagsPath, permalink]);
|
|
25
25
|
}
|
|
26
26
|
const tag = typeof frontMatterTag === 'string'
|
|
27
27
|
? toTagObject(frontMatterTag)
|
|
@@ -32,9 +32,8 @@ function normalizeFrontMatterTag(tagsPath, frontMatterTag) {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
exports.normalizeFrontMatterTag = normalizeFrontMatterTag;
|
|
35
|
-
function normalizeFrontMatterTags(tagsPath, frontMatterTags) {
|
|
36
|
-
|
|
37
|
-
const tags = (_a = frontMatterTags === null || frontMatterTags === void 0 ? void 0 : frontMatterTags.map((tag) => normalizeFrontMatterTag(tagsPath, tag))) !== null && _a !== void 0 ? _a : [];
|
|
35
|
+
function normalizeFrontMatterTags(tagsPath, frontMatterTags = []) {
|
|
36
|
+
const tags = frontMatterTags.map((tag) => normalizeFrontMatterTag(tagsPath, tag));
|
|
38
37
|
return (0, lodash_1.uniqBy)(tags, (tag) => tag.permalink);
|
|
39
38
|
}
|
|
40
39
|
exports.normalizeFrontMatterTags = normalizeFrontMatterTags;
|
package/lib/tags.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,mCAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,mCAA+C;AAC/C,yCAAwC;AASxC,SAAgB,uBAAuB,CACrC,QAAgB,EAChB,cAA8B;IAE9B,SAAS,WAAW,CAAC,SAAiB;QACpC,OAAO;YACL,KAAK,EAAE,SAAS;YAChB,SAAS,EAAE,IAAA,kBAAS,EAAC,SAAS,CAAC;SAChC,CAAC;IACJ,CAAC;IAED,0DAA0D;IAC1D,SAAS,qBAAqB,CAAC,SAAiB;QAC9C,4CAA4C;QAC5C,8GAA8G;QAC9G,6CAA6C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,WAAW,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YAChC,aAAa,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,mEAAmE;IACnE,wDAAwD;IACxD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACtC,KAAK,CAAC,KAAK,GAAG,IAAA,aAAI,EAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAhCD,4CAgCC"}
|
|
@@ -5,4 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
export declare function normalizeUrl(rawUrls: string[]): string;
|
|
8
|
-
|
|
8
|
+
export declare function getEditUrl(fileRelativePath: string, editUrl?: string): string | undefined;
|
|
9
|
+
//# sourceMappingURL=urlUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlUtils.d.ts","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CA6EtD;AAED,wBAAgB,UAAU,CACxB,gBAAgB,EAAE,MAAM,EACxB,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,GAAG,SAAS,CAKpB"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.normalizeUrl = void 0;
|
|
9
|
+
exports.getEditUrl = exports.normalizeUrl = void 0;
|
|
10
10
|
function normalizeUrl(rawUrls) {
|
|
11
11
|
const urls = [...rawUrls];
|
|
12
12
|
const resultArray = [];
|
|
@@ -15,7 +15,13 @@ function normalizeUrl(rawUrls) {
|
|
|
15
15
|
// If the first part is a plain protocol, we combine it with the next part.
|
|
16
16
|
if (urls[0].match(/^[^/:]+:\/*$/) && urls.length > 1) {
|
|
17
17
|
const first = urls.shift();
|
|
18
|
-
|
|
18
|
+
if (first.startsWith('file:') && urls[0].startsWith('/')) {
|
|
19
|
+
// Force a double slash here, else we lose the information that the next segment is an absolute path
|
|
20
|
+
urls[0] = `${first}//${urls[0]}`;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
urls[0] = first + urls[0];
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
26
|
// There must be two or three slashes in the file protocol,
|
|
21
27
|
// two slashes in anything else.
|
|
@@ -58,10 +64,17 @@ function normalizeUrl(rawUrls) {
|
|
|
58
64
|
const parts = str.split('?');
|
|
59
65
|
str = parts.shift() + (parts.length > 0 ? '?' : '') + parts.join('&');
|
|
60
66
|
// Dedupe forward slashes in the entire path, avoiding protocol slashes.
|
|
61
|
-
str = str.replace(/([
|
|
67
|
+
str = str.replace(/([^:/]\/)\/+/g, '$1');
|
|
62
68
|
// Dedupe forward slashes at the beginning of the path.
|
|
63
69
|
str = str.replace(/^\/+/g, '/');
|
|
64
70
|
return str;
|
|
65
71
|
}
|
|
66
72
|
exports.normalizeUrl = normalizeUrl;
|
|
67
|
-
|
|
73
|
+
function getEditUrl(fileRelativePath, editUrl) {
|
|
74
|
+
return editUrl
|
|
75
|
+
? // Don't use posixPath for this: we need to force a forward slash path
|
|
76
|
+
normalizeUrl([editUrl, fileRelativePath.replace(/\\/g, '/')])
|
|
77
|
+
: undefined;
|
|
78
|
+
}
|
|
79
|
+
exports.getEditUrl = getEditUrl;
|
|
80
|
+
//# sourceMappingURL=urlUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"urlUtils.js","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings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CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEtE,wEAAwE;IACxE,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;IAEzC,uDAAuD;IACvD,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAEhC,OAAO,GAAG,CAAC;AACb,CAAC;AA7ED,oCA6EC;AAED,SAAgB,UAAU,CACxB,gBAAwB,EACxB,OAAgB;IAEhB,OAAO,OAAO;QACZ,CAAC,CAAC,sEAAsE;YACtE,YAAY,CAAC,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;QAC/D,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AARD,gCAQC"}
|
package/lib/webpackUtils.js
CHANGED
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.getFileLoaderUtils = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
12
|
-
const
|
|
12
|
+
const pathUtils_1 = require("./pathUtils");
|
|
13
13
|
const constants_1 = require("./constants");
|
|
14
14
|
// Inspired by https://github.com/gatsbyjs/gatsby/blob/8e6e021014da310b9cc7d02e58c9b3efe938c665/packages/gatsby/src/utils/webpack-utils.ts#L447
|
|
15
15
|
function getFileLoaderUtils() {
|
|
@@ -37,8 +37,8 @@ function getFileLoaderUtils() {
|
|
|
37
37
|
// Maybe with the ideal image plugin, all md images should be "ideal"?
|
|
38
38
|
// This is used to force url-loader+file-loader on markdown images
|
|
39
39
|
// https://webpack.js.org/concepts/loaders/#inline
|
|
40
|
-
inlineMarkdownImageFileLoader: `!${(0,
|
|
41
|
-
inlineMarkdownLinkFileLoader: `!${(0,
|
|
40
|
+
inlineMarkdownImageFileLoader: `!${(0, pathUtils_1.escapePath)(require.resolve('url-loader'))}?limit=${urlLoaderLimit}&name=${fileLoaderFileName('images')}&fallback=${(0, pathUtils_1.escapePath)(require.resolve('file-loader'))}!`,
|
|
41
|
+
inlineMarkdownLinkFileLoader: `!${(0, pathUtils_1.escapePath)(require.resolve('file-loader'))}?name=${fileLoaderFileName('files')}!`,
|
|
42
42
|
};
|
|
43
43
|
const rules = {
|
|
44
44
|
/**
|
package/lib/webpackUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpackUtils.js","sourceRoot":"","sources":["../src/webpackUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAGH,6DAAwB;AACxB,
|
|
1
|
+
{"version":3,"file":"webpackUtils.js","sourceRoot":"","sources":["../src/webpackUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAGH,6DAAwB;AACxB,2CAAuC;AACvC,2CAGqB;AAoBrB,+IAA+I;AAC/I,SAAgB,kBAAkB;IAChC,uFAAuF;IACvF,MAAM,cAAc,GAAG,oCAAwB,CAAC;IAEhD,4DAA4D;IAC5D,MAAM,kBAAkB,GAAG,CAAC,MAAmB,EAAE,EAAE,CACjD,GAAG,yCAA6B,IAAI,MAAM,sBAAsB,CAAC;IAEnE,MAAM,OAAO,GAA+B;QAC1C,IAAI,EAAE,CAAC,OAA8B,EAAE,EAAE,CAAC,CAAC;YACzC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC;YACtC,OAAO,EAAE;gBACP,IAAI,EAAE,kBAAkB,CAAC,OAAO,CAAC,MAAM,CAAC;aACzC;SACF,CAAC;QACF,GAAG,EAAE,CAAC,OAA8B,EAAE,EAAE,CAAC,CAAC;YACxC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC;YACrC,OAAO,EAAE;gBACP,KAAK,EAAE,cAAc;gBACrB,IAAI,EAAE,k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AAO,CAAC,OAAO,CAAC,eAAe,CAAC;4BACxC,OAAO,EAAE;gCACP,QAAQ,EAAE,KAAK;gCACf,IAAI,EAAE,IAAI;gCACV,UAAU,EAAE;oCACV,OAAO,EAAE;wCACP;4CACE,IAAI,EAAE,gBAAgB;4CACtB,MAAM,EAAE;gDACN,SAAS,EAAE;oDACT,aAAa,EAAE,KAAK;iDACrB;6CACF;yCACF;qCACF;iCACF;gCACD,SAAS,EAAE,IAAI;gCACf,GAAG,EAAE,CAAC,CAAC,cAAI,CAAC;6BACb;yBACF;qBACF;oBACD,6DAA6D;oBAC7D,gDAAgD;oBAChD,MAAM,EAAE;wBACN,GAAG,EAAE,CAAC,2BAA2B,CAAC;qBACnC;iBACF;gBACD;oBACE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAC,MAAM,EAAE,QAAQ,EAAC,CAAC,CAAC;iBACvC;aACF;SACF,CAAC;QAEF,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC;YAClB,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC,CAAC;YACtC,IAAI,EAAE,oCAAoC;SAC3C,CAAC;KACH,CAAC;IAEF,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,CAAC;AAC1B,CAAC;AA7GD,gDA6GC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.15",
|
|
4
4
|
"description": "Node utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "2.0.0-beta.
|
|
21
|
+
"@docusaurus/logger": "2.0.0-beta.15",
|
|
22
22
|
"@mdx-js/runtime": "^1.6.22",
|
|
23
23
|
"@svgr/webpack": "^6.0.0",
|
|
24
|
-
"escape-string-regexp": "^4.0.0",
|
|
25
24
|
"file-loader": "^6.2.0",
|
|
26
25
|
"fs-extra": "^10.0.0",
|
|
27
26
|
"github-slugger": "^1.4.0",
|
|
28
27
|
"globby": "^11.0.4",
|
|
29
28
|
"gray-matter": "^4.0.3",
|
|
29
|
+
"js-yaml": "^4.0.0",
|
|
30
30
|
"lodash": "^4.17.20",
|
|
31
31
|
"micromatch": "^4.0.4",
|
|
32
32
|
"remark-mdx-remove-exports": "^1.6.22",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"node": ">=14"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@docusaurus/types": "2.0.0-beta.
|
|
42
|
+
"@docusaurus/types": "2.0.0-beta.15",
|
|
43
43
|
"@types/dedent": "^0.7.0",
|
|
44
44
|
"@types/github-slugger": "^1.3.0",
|
|
45
45
|
"@types/micromatch": "^4.0.2",
|
|
@@ -48,9 +48,10 @@
|
|
|
48
48
|
"tslib": "^2.3.1"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
+
"@babel/core": "^7.0.0",
|
|
51
52
|
"react": "*",
|
|
52
53
|
"react-dom": "*",
|
|
53
54
|
"webpack": "5.x"
|
|
54
55
|
},
|
|
55
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "32ec84ef3c0a238436e913b2026ab809e5750fa8"
|
|
56
57
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import fs from 'fs-extra';
|
|
9
|
+
import Yaml from 'js-yaml';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import {findAsyncSequential} from './index';
|
|
12
|
+
import type {ContentPaths} from './markdownLinks';
|
|
13
|
+
import logger from '@docusaurus/logger';
|
|
14
|
+
|
|
15
|
+
type DataFileParams = {
|
|
16
|
+
filePath: string;
|
|
17
|
+
contentPaths: ContentPaths;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export async function getDataFilePath({
|
|
21
|
+
filePath,
|
|
22
|
+
contentPaths,
|
|
23
|
+
}: DataFileParams): Promise<string | undefined> {
|
|
24
|
+
// Loads a localized data file in priority
|
|
25
|
+
const contentPath = await findFolderContainingFile(
|
|
26
|
+
getContentPathList(contentPaths),
|
|
27
|
+
filePath,
|
|
28
|
+
);
|
|
29
|
+
if (contentPath) {
|
|
30
|
+
return path.join(contentPath, filePath);
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Looks up for a data file in the content paths, returns the normalized object.
|
|
37
|
+
* Throws when validation fails; returns undefined when file not found
|
|
38
|
+
*/
|
|
39
|
+
export async function getDataFileData<T>(
|
|
40
|
+
params: DataFileParams & {fileType: string},
|
|
41
|
+
validate: (content: unknown) => T,
|
|
42
|
+
): Promise<T | undefined> {
|
|
43
|
+
const filePath = await getDataFilePath(params);
|
|
44
|
+
if (!filePath) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const contentString = await fs.readFile(filePath, {encoding: 'utf8'});
|
|
49
|
+
const unsafeContent = Yaml.load(contentString);
|
|
50
|
+
return validate(unsafeContent);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
// TODO replace later by error cause, see https://v8.dev/features/error-cause
|
|
53
|
+
logger.error`The ${params.fileType} file at path=${filePath} looks invalid.`;
|
|
54
|
+
throw e;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Order matters: we look in priority in localized folder
|
|
59
|
+
export function getContentPathList(contentPaths: ContentPaths): string[] {
|
|
60
|
+
return [contentPaths.contentPathLocalized, contentPaths.contentPath];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// return the first folder path in which the file exists in
|
|
64
|
+
export async function findFolderContainingFile(
|
|
65
|
+
folderPaths: string[],
|
|
66
|
+
relativeFilePath: string,
|
|
67
|
+
): Promise<string | undefined> {
|
|
68
|
+
return findAsyncSequential(folderPaths, (folderPath) =>
|
|
69
|
+
fs.pathExists(path.join(folderPath, relativeFilePath)),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function getFolderContainingFile(
|
|
74
|
+
folderPaths: string[],
|
|
75
|
+
relativeFilePath: string,
|
|
76
|
+
): Promise<string> {
|
|
77
|
+
const maybeFolderPath = await findFolderContainingFile(
|
|
78
|
+
folderPaths,
|
|
79
|
+
relativeFilePath,
|
|
80
|
+
);
|
|
81
|
+
// should never happen, as the source was read from the FS anyway...
|
|
82
|
+
if (!maybeFolderPath) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`File "${relativeFilePath}" does not exist in any of these folders:\n- ${folderPaths.join(
|
|
85
|
+
'\n- ',
|
|
86
|
+
)}]`,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return maybeFolderPath;
|
|
90
|
+
}
|
package/src/globUtils.ts
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
// Globby/Micromatch are the 2 libs we use in Docusaurus consistently
|
|
9
9
|
|
|
10
|
-
export {default as Globby} from 'globby';
|
|
11
10
|
import Micromatch from 'micromatch'; // Note: Micromatch is used by Globby
|
|
12
11
|
import path from 'path';
|
|
13
12
|
|
|
13
|
+
export {default as Globby} from 'globby';
|
|
14
|
+
|
|
14
15
|
// The default patterns we ignore when globbing
|
|
15
16
|
// using _ prefix for exclusion by convention
|
|
16
17
|
export const GlobExcludeDefault = [
|