@docusaurus/utils 2.0.0-beta.13 → 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/constants.d.ts +1 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +1 -0
- package/lib/constants.js.map +1 -0
- 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 +1 -0
- package/lib/globUtils.d.ts.map +1 -0
- package/lib/globUtils.js +3 -2
- package/lib/globUtils.js.map +1 -0
- package/lib/hashUtils.d.ts +1 -0
- package/lib/hashUtils.d.ts.map +1 -0
- package/lib/hashUtils.js +1 -0
- package/lib/hashUtils.js.map +1 -0
- package/lib/index.d.ts +19 -41
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +45 -143
- package/lib/index.js.map +1 -0
- package/lib/markdownLinks.d.ts +1 -0
- package/lib/markdownLinks.d.ts.map +1 -0
- package/lib/markdownLinks.js +13 -4
- package/lib/markdownLinks.js.map +1 -0
- package/lib/markdownParser.d.ts +5 -3
- package/lib/markdownParser.d.ts.map +1 -0
- package/lib/markdownParser.js +32 -19
- package/lib/markdownParser.js.map +1 -0
- package/lib/pathUtils.d.ts +30 -0
- package/lib/pathUtils.d.ts.map +1 -0
- package/lib/pathUtils.js +70 -5
- package/lib/pathUtils.js.map +1 -0
- package/lib/slugger.d.ts +1 -0
- package/lib/slugger.d.ts.map +1 -0
- package/lib/slugger.js +1 -0
- package/lib/slugger.js.map +1 -0
- package/lib/tags.d.ts +2 -1
- package/lib/tags.d.ts.map +1 -0
- package/lib/tags.js +5 -5
- package/lib/tags.js.map +1 -0
- package/lib/{normalizeUrl.d.ts → urlUtils.d.ts} +2 -0
- package/lib/urlUtils.d.ts.map +1 -0
- package/lib/{normalizeUrl.js → urlUtils.js} +17 -3
- package/lib/urlUtils.js.map +1 -0
- package/lib/webpackUtils.d.ts +1 -0
- package/lib/webpackUtils.d.ts.map +1 -0
- package/lib/webpackUtils.js +4 -3
- package/lib/webpackUtils.js.map +1 -0
- package/package.json +8 -6
- package/src/dataFileUtils.ts +90 -0
- package/src/globUtils.ts +2 -1
- package/src/index.ts +52 -177
- package/src/markdownLinks.ts +10 -3
- package/src/markdownParser.ts +33 -23
- 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/.tsbuildinfo +0 -1
- package/lib/escapePath.d.ts +0 -17
- package/lib/escapePath.js +0 -25
- package/lib/mdxUtils.d.ts +0 -16
- package/lib/mdxUtils.js +0 -30
- package/lib/posixPath.d.ts +0 -14
- package/lib/posixPath.js +0 -28
- package/src/__tests__/__snapshots__/index.test.ts.snap +0 -8
- package/src/__tests__/escapePath.test.ts +0 -25
- package/src/__tests__/globUtils.test.ts +0 -109
- package/src/__tests__/hashUtils.test.ts +0 -51
- package/src/__tests__/index.test.ts +0 -527
- package/src/__tests__/markdownParser.test.ts +0 -830
- package/src/__tests__/mdxUtils.test.ts +0 -133
- package/src/__tests__/normalizeUrl.test.ts +0 -117
- package/src/__tests__/pathUtils.test.ts +0 -65
- package/src/__tests__/posixPath.test.ts +0 -25
- package/src/__tests__/slugger.test.ts +0 -27
- package/src/__tests__/tags.test.ts +0 -183
- package/src/__tests__/webpackUtils.test.ts +0 -33
- package/src/escapePath.ts +0 -23
- package/src/mdxUtils.ts +0 -32
- package/src/posixPath.ts +0 -27
- package/tsconfig.json +0 -9
package/lib/constants.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,kBAAkB,QAG9B,CAAC;AACF,eAAO,MAAM,kBAAkB,QAG9B,CAAC;AAGF,eAAO,MAAM,sBAAsB,UAAU,CAAC;AAG9C,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAE/D,eAAO,MAAM,sBAAsB,QACiC,CAAC;AAErE,eAAO,MAAM,wBAAwB,QAC6B,CAAC;AAEnE,eAAO,MAAM,YAAY,QAAQ,CAAC;AAClC,eAAO,MAAM,eAAe,WAAW,CAAC;AACxC,eAAO,MAAM,6BAA6B,WAAW,CAAC;AACtD,eAAO,MAAM,UAAU,QAA0B,CAAC;AAClD,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAG3C,eAAO,MAAM,wBAAwB,iBACU,CAAC"}
|
package/lib/constants.js
CHANGED
|
@@ -24,3 +24,4 @@ exports.DEFAULT_PORT = 3000;
|
|
|
24
24
|
exports.DEFAULT_PLUGIN_ID = 'default';
|
|
25
25
|
// Temporary fix for https://github.com/facebook/docusaurus/issues/5493
|
|
26
26
|
exports.WEBPACK_URL_LOADER_LIMIT = (_a = process.env.WEBPACK_URL_LOADER_LIMIT) !== null && _a !== void 0 ? _a : 10000;
|
|
27
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEU,QAAA,kBAAkB,GAAG,QAAQ,CACxC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EACnC,EAAE,CACH,CAAC;AACW,QAAA,kBAAkB,GAAG,QAAQ,CACxC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EACnC,EAAE,CACH,CAAC;AAEF,8CAA8C;AACjC,QAAA,sBAAsB,GAAG,OAAO,CAAC;AAE9C,6CAA6C;AAChC,QAAA,wBAAwB,GAAG,sBAAsB,CAAC;AAElD,QAAA,sBAAsB,GACjC,OAAO,CAAC,GAAG,CAAC,iCAAiC,IAAI,iBAAiB,CAAC;AAExD,QAAA,wBAAwB,GACnC,OAAO,CAAC,GAAG,CAAC,mCAAmC,IAAI,aAAa,CAAC;AAEtD,QAAA,YAAY,GAAG,KAAK,CAAC;AACrB,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,6BAA6B,GAAG,QAAQ,CAAC,CAAC,gEAAgE;AAC1G,QAAA,UAAU,GAAG,GAAG,oBAAY,QAAQ,CAAC;AACrC,QAAA,YAAY,GAAG,IAAI,CAAC;AACpB,QAAA,iBAAiB,GAAG,SAAS,CAAC;AAE3C,uEAAuE;AAC1D,QAAA,wBAAwB,GACnC,MAAA,OAAO,CAAC,GAAG,CAAC,wBAAwB,mCAAI,KAAK,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
import type { ContentPaths } from './markdownLinks';
|
|
8
|
+
declare type DataFileParams = {
|
|
9
|
+
filePath: string;
|
|
10
|
+
contentPaths: ContentPaths;
|
|
11
|
+
};
|
|
12
|
+
export declare function getDataFilePath({ filePath, contentPaths, }: DataFileParams): Promise<string | undefined>;
|
|
13
|
+
/**
|
|
14
|
+
* Looks up for a data file in the content paths, returns the normalized object.
|
|
15
|
+
* Throws when validation fails; returns undefined when file not found
|
|
16
|
+
*/
|
|
17
|
+
export declare function getDataFileData<T>(params: DataFileParams & {
|
|
18
|
+
fileType: string;
|
|
19
|
+
}, validate: (content: unknown) => T): Promise<T | undefined>;
|
|
20
|
+
export declare function getContentPathList(contentPaths: ContentPaths): string[];
|
|
21
|
+
export declare function findFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string | undefined>;
|
|
22
|
+
export declare function getFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string>;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=dataFileUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataFileUtils.d.ts","sourceRoot":"","sources":["../src/dataFileUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAGlD,aAAK,cAAc,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,wBAAsB,eAAe,CAAC,EACpC,QAAQ,EACR,YAAY,GACb,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAU9C;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,CAAC,EACrC,MAAM,EAAE,cAAc,GAAG;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAC,EAC3C,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,CAAC,GAChC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAcxB;AAGD,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,EAAE,CAEvE;AAGD,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,MAAM,EAAE,EACrB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAI7B;AAED,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EAAE,EACrB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,CAAC,CAcjB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getFolderContainingFile = exports.findFolderContainingFile = exports.getContentPathList = exports.getDataFileData = exports.getDataFilePath = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
12
|
+
const js_yaml_1 = (0, tslib_1.__importDefault)(require("js-yaml"));
|
|
13
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
14
|
+
const index_1 = require("./index");
|
|
15
|
+
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
16
|
+
async function getDataFilePath({ filePath, contentPaths, }) {
|
|
17
|
+
// Loads a localized data file in priority
|
|
18
|
+
const contentPath = await findFolderContainingFile(getContentPathList(contentPaths), filePath);
|
|
19
|
+
if (contentPath) {
|
|
20
|
+
return path_1.default.join(contentPath, filePath);
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
exports.getDataFilePath = getDataFilePath;
|
|
25
|
+
/**
|
|
26
|
+
* Looks up for a data file in the content paths, returns the normalized object.
|
|
27
|
+
* Throws when validation fails; returns undefined when file not found
|
|
28
|
+
*/
|
|
29
|
+
async function getDataFileData(params, validate) {
|
|
30
|
+
const filePath = await getDataFilePath(params);
|
|
31
|
+
if (!filePath) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const contentString = await fs_extra_1.default.readFile(filePath, { encoding: 'utf8' });
|
|
36
|
+
const unsafeContent = js_yaml_1.default.load(contentString);
|
|
37
|
+
return validate(unsafeContent);
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
// TODO replace later by error cause, see https://v8.dev/features/error-cause
|
|
41
|
+
logger_1.default.error `The ${params.fileType} file at path=${filePath} looks invalid.`;
|
|
42
|
+
throw e;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.getDataFileData = getDataFileData;
|
|
46
|
+
// Order matters: we look in priority in localized folder
|
|
47
|
+
function getContentPathList(contentPaths) {
|
|
48
|
+
return [contentPaths.contentPathLocalized, contentPaths.contentPath];
|
|
49
|
+
}
|
|
50
|
+
exports.getContentPathList = getContentPathList;
|
|
51
|
+
// return the first folder path in which the file exists in
|
|
52
|
+
async function findFolderContainingFile(folderPaths, relativeFilePath) {
|
|
53
|
+
return (0, index_1.findAsyncSequential)(folderPaths, (folderPath) => fs_extra_1.default.pathExists(path_1.default.join(folderPath, relativeFilePath)));
|
|
54
|
+
}
|
|
55
|
+
exports.findFolderContainingFile = findFolderContainingFile;
|
|
56
|
+
async function getFolderContainingFile(folderPaths, relativeFilePath) {
|
|
57
|
+
const maybeFolderPath = await findFolderContainingFile(folderPaths, relativeFilePath);
|
|
58
|
+
// should never happen, as the source was read from the FS anyway...
|
|
59
|
+
if (!maybeFolderPath) {
|
|
60
|
+
throw new Error(`File "${relativeFilePath}" does not exist in any of these folders:\n- ${folderPaths.join('\n- ')}]`);
|
|
61
|
+
}
|
|
62
|
+
return maybeFolderPath;
|
|
63
|
+
}
|
|
64
|
+
exports.getFolderContainingFile = getFolderContainingFile;
|
|
65
|
+
//# sourceMappingURL=dataFileUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataFileUtils.js","sourceRoot":"","sources":["../src/dataFileUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,qEAA0B;AAC1B,mEAA2B;AAC3B,6DAAwB;AACxB,mCAA4C;AAE5C,6EAAwC;AAOjC,KAAK,UAAU,eAAe,CAAC,EACpC,QAAQ,EACR,YAAY,GACG;IACf,0CAA0C;IAC1C,MAAM,WAAW,GAAG,MAAM,wBAAwB,CAChD,kBAAkB,CAAC,YAAY,CAAC,EAChC,QAAQ,CACT,CAAC;IACF,IAAI,WAAW,EAAE;QACf,OAAO,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE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oEAAoE;IACpE,IAAI,CAAC,eAAe,EAAE;QACpB,MAAM,IAAI,KAAK,CACb,SAAS,gBAAgB,gDAAgD,WAAW,CAAC,IAAI,CACvF,MAAM,CACP,GAAG,CACL,CAAC;KACH;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAjBD,0DAiBC"}
|
package/lib/globUtils.d.ts
CHANGED
|
@@ -9,3 +9,4 @@ export declare const GlobExcludeDefault: string[];
|
|
|
9
9
|
declare type Matcher = (str: string) => boolean;
|
|
10
10
|
export declare function createMatcher(patterns: string[]): Matcher;
|
|
11
11
|
export declare function createAbsoluteFilePathMatcher(patterns: string[], rootFolders: string[]): Matcher;
|
|
12
|
+
//# sourceMappingURL=globUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"globUtils.d.ts","sourceRoot":"","sources":["../src/globUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,QAAQ,CAAC;AAIzC,eAAO,MAAM,kBAAkB,UAU9B,CAAC;AAEF,aAAK,OAAO,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;AAExC,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAKzD;AAMD,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,MAAM,EAAE,EAClB,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAmBT"}
|
package/lib/globUtils.js
CHANGED
|
@@ -9,10 +9,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.createAbsoluteFilePathMatcher = exports.createMatcher = exports.GlobExcludeDefault = exports.Globby = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
// Globby/Micromatch are the 2 libs we use in Docusaurus consistently
|
|
12
|
-
var globby_1 = require("globby");
|
|
13
|
-
Object.defineProperty(exports, "Globby", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(globby_1).default; } });
|
|
14
12
|
const micromatch_1 = (0, tslib_1.__importDefault)(require("micromatch")); // Note: Micromatch is used by Globby
|
|
15
13
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
14
|
+
var globby_1 = require("globby");
|
|
15
|
+
Object.defineProperty(exports, "Globby", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(globby_1).default; } });
|
|
16
16
|
// The default patterns we ignore when globbing
|
|
17
17
|
// using _ prefix for exclusion by convention
|
|
18
18
|
exports.GlobExcludeDefault = [
|
|
@@ -45,3 +45,4 @@ function createAbsoluteFilePathMatcher(patterns, rootFolders) {
|
|
|
45
45
|
return (absoluteFilePath) => matcher(getRelativeFilePath(absoluteFilePath));
|
|
46
46
|
}
|
|
47
47
|
exports.createAbsoluteFilePathMatcher = createAbsoluteFilePathMatcher;
|
|
48
|
+
//# sourceMappingURL=globUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"globUtils.js","sourceRoot":"","sources":["../src/globUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,qEAAqE;AAErE,yEAAoC,CAAC,qCAAqC;AAC1E,6DAAwB;AAExB,iCAAyC;AAAjC,8HAAA,OAAO,OAAU;AAEzB,+CAA+C;AAC/C,6CAA6C;AAChC,QAAA,kBAAkB,GAAG;IAChC,+BAA+B;IAC/B,8BAA8B;IAE9B,4DAA4D;IAC5D,UAAU;IAEV,eAAe;IACf,2BAA2B;IAC3B,iBAAiB;CAClB,CAAC;AAIF,SAAgB,aAAa,CAAC,QAAkB;IAC9C,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,oBAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CACvE,CAAC;IACF,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC;AALD,sCAKC;AAED,yCAAyC;AACzC,oCAAoC;AACpC,sDAAsD;AACtD,uDAAuD;AACvD,SAAgB,6BAA6B,CAC3C,QAAkB,EAClB,WAAqB;IAErB,MAAM,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAExC,SAAS,mBAAmB,CAAC,gBAAwB;QACnD,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CACjD,gBAAgB,CAAC,UAAU,CAAC,UAAU,CAAC,CACxC,CAAC;QACF,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,IAAI,KAAK,CACb,oEAAoE,gBAAgB,iDAAiD,IAAI,CAAC,SAAS,CACjJ,WAAW,CACZ,EAAE,CACJ,CAAC;SACH;QACD,OAAO,cAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,CAAC,gBAAwB,EAAE,EAAE,CAClC,OAAO,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAAC,CAAC;AACnD,CAAC;AAtBD,sEAsBC"}
|
package/lib/hashUtils.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashUtils.d.ts","sourceRoot":"","sources":["../src/hashUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE9D;AAGD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAU5C"}
|
package/lib/hashUtils.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashUtils.js","sourceRoot":"","sources":["../src/hashUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,mCAAkC;AAClC,mCAAiC;AACjC,2CAAqD;AAErD,SAAgB,OAAO,CAAC,GAAW;IACjC,OAAO,IAAA,mBAAU,EAAC,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC;AAFD,0BAEC;AAED,SAAgB,UAAU,CAAC,GAAW,EAAE,MAAc;IACpD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACxC,CAAC;AAFD,gCAEC;AAED,+DAA+D;AAC/D;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,GAAW;IAClC,IAAI,GAAG,KAAK,GAAG,EAAE;QACf,OAAO,OAAO,CAAC;KAChB;IACD,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACrC,MAAM,UAAU,GAAG,GAAG,IAAA,kBAAS,EAAC,GAAG,CAAC,IAAI,SAAS,EAAE,CAAC;IACpD,IAAI,IAAA,yBAAa,EAAC,UAAU,CAAC,EAAE;QAC7B,OAAO,GAAG,IAAA,qBAAS,EAAC,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC;KACpD;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAVD,4BAUC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -4,55 +4,30 @@
|
|
|
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
|
-
|
|
8
|
-
import {
|
|
7
|
+
/// <reference types="node" />
|
|
8
|
+
import type { ReportingSeverity, TranslationFileContent, TranslationFile } from '@docusaurus/types';
|
|
9
9
|
export * from './constants';
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './normalizeUrl';
|
|
10
|
+
export * from './urlUtils';
|
|
12
11
|
export * from './tags';
|
|
13
|
-
export declare const posixPath: typeof posixPathImport;
|
|
14
12
|
export * from './markdownParser';
|
|
15
13
|
export * from './markdownLinks';
|
|
16
|
-
export * from './escapePath';
|
|
17
14
|
export * from './slugger';
|
|
18
|
-
export
|
|
19
|
-
export
|
|
15
|
+
export * from './pathUtils';
|
|
16
|
+
export * from './hashUtils';
|
|
17
|
+
export * from './globUtils';
|
|
20
18
|
export * from './webpackUtils';
|
|
19
|
+
export * from './dataFileUtils';
|
|
21
20
|
export declare function generate(generatedFilesDir: string, file: string, content: string, skipCache?: boolean): Promise<void>;
|
|
22
|
-
export declare function objectWithKeySorted<T>(obj: Record<string, T>): Record<string, T>;
|
|
23
21
|
/**
|
|
24
22
|
* Convert filepath to url path.
|
|
25
23
|
* Example: 'index.md' -> '/', 'foo/bar.js' -> '/foo/bar',
|
|
26
24
|
*/
|
|
27
25
|
export declare function fileToPath(file: string): string;
|
|
28
|
-
export declare function encodePath(
|
|
29
|
-
/**
|
|
30
|
-
* Convert first string character to the upper case.
|
|
31
|
-
* E.g: docusaurus -> Docusaurus
|
|
32
|
-
*/
|
|
33
|
-
export declare function upperFirst(str: string): string;
|
|
34
|
-
/**
|
|
35
|
-
* Generate unique React Component Name.
|
|
36
|
-
* E.g: /foo-bar -> FooBar096
|
|
37
|
-
*/
|
|
38
|
-
export declare function genComponentName(pagePath: string): string;
|
|
39
|
-
export declare function toMessageRelativeFilePath(filePath: string): string;
|
|
26
|
+
export declare function encodePath(userPath: string): string;
|
|
40
27
|
/**
|
|
41
28
|
* Generate unique chunk name given a module path.
|
|
42
29
|
*/
|
|
43
30
|
export declare function genChunkName(modulePath: string, prefix?: string, preferredName?: string, shortId?: boolean): string;
|
|
44
|
-
export declare function idx(target: any, keyPaths?: string | (string | number)[]): any;
|
|
45
|
-
/**
|
|
46
|
-
* Given a filepath and dirpath, get the first directory.
|
|
47
|
-
*/
|
|
48
|
-
export declare function getSubFolder(file: string, refDir: string): string | null;
|
|
49
|
-
/**
|
|
50
|
-
* Alias filepath relative to site directory, very useful so that we
|
|
51
|
-
* don't expose user's site structure.
|
|
52
|
-
* Example: some/path/to/website/docs/foo.md -> @site/docs/foo.md
|
|
53
|
-
*/
|
|
54
|
-
export declare function aliasedSitePath(filePath: string, siteDir: string): string;
|
|
55
|
-
export declare function getEditUrl(fileRelativePath: string, editUrl?: string): string | undefined;
|
|
56
31
|
export declare function isValidPathname(str: string): boolean;
|
|
57
32
|
export declare function resolvePathname(to: string, from?: string): string;
|
|
58
33
|
export declare function addLeadingSlash(str: string): string;
|
|
@@ -72,15 +47,18 @@ export declare function getPluginI18nPath({ siteDir, locale, pluginName, pluginI
|
|
|
72
47
|
pluginId?: string | undefined;
|
|
73
48
|
subPaths?: string[];
|
|
74
49
|
}): string;
|
|
75
|
-
|
|
50
|
+
/**
|
|
51
|
+
* @param permalink The URL that the HTML file corresponds to, without base URL
|
|
52
|
+
* @param outDir Full path to the output directory
|
|
53
|
+
* @param trailingSlash The site config option. If provided, only one path will be read.
|
|
54
|
+
* @returns This returns a buffer, which you have to decode string yourself if
|
|
55
|
+
* needed. (Not always necessary since the output isn't for human consumption
|
|
56
|
+
* anyways, and most HTML manipulation libs accept buffers)
|
|
57
|
+
*/
|
|
58
|
+
export declare function readOutputHTMLFile(permalink: string, outDir: string, trailingSlash: boolean | undefined): Promise<Buffer>;
|
|
59
|
+
export declare function mapAsyncSequential<T, R>(array: T[], action: (t: T) => Promise<R>): Promise<R[]>;
|
|
76
60
|
export declare function findAsyncSequential<T>(array: T[], predicate: (t: T) => Promise<boolean>): Promise<T | undefined>;
|
|
77
|
-
export declare function findFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string | undefined>;
|
|
78
|
-
export declare function getFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string>;
|
|
79
61
|
export declare function reportMessage(message: string, reportingSeverity: ReportingSeverity): void;
|
|
80
62
|
export declare function mergeTranslations(contents: TranslationFileContent[]): TranslationFileContent;
|
|
81
|
-
export declare function getSwizzledComponent(componentPath: string): string | undefined;
|
|
82
63
|
export declare function updateTranslationFileMessages(translationFile: TranslationFile, updateMessage: (message: string) => string): TranslationFile;
|
|
83
|
-
|
|
84
|
-
text: string;
|
|
85
|
-
id?: string;
|
|
86
|
-
};
|
|
64
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAQH,OAAO,KAAK,EACV,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAO3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAGhC,wBAAsB,QAAQ,CAC5B,iBAAiB,EAAE,MAAM,EACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,OAA+C,GACzD,OAAO,CAAC,IAAI,CAAC,CA2Bf;AAKD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKnD;AAGD;;GAEG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,MAAM,EACtB,OAAO,GAAE,OAA+C,GACvD,MAAM,CAiBR;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAWpD;AAGD,wBAAgB,eAAe,CAAC,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V,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,CAAC,EAAE,CAAC,CAQd;AAED,wBAAsB,mBAAmB,CAAC,CAAC,EACzC,KAAK,EAAE,CAAC,EAAE,EACV,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,GACpC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAQxB;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,iBAAiB,EAAE,iBAAiB,GACnC,IAAI,CAoBN;AAED,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,sBAAsB,EAAE,GACjC,sBAAsB,CAExB;AAID,wBAAgB,6BAA6B,CAC3C,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GACzC,eAAe,CAQjB"}
|
package/lib/index.js
CHANGED
|
@@ -6,39 +6,28 @@
|
|
|
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.updateTranslationFileMessages = exports.mergeTranslations = exports.reportMessage = exports.findAsyncSequential = exports.mapAsyncSequential = exports.readOutputHTMLFile = exports.getPluginI18nPath = exports.getElementsAround = exports.removePrefix = exports.removeSuffix = exports.removeTrailingSlash = exports.addTrailingSlash = exports.addTrailingPathSeparator = exports.addLeadingSlash = exports.resolvePathname = exports.isValidPathname = exports.genChunkName = exports.encodePath = exports.fileToPath = exports.generate = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const
|
|
11
|
+
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
12
12
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
13
13
|
const crypto_1 = require("crypto");
|
|
14
14
|
const lodash_1 = require("lodash");
|
|
15
|
-
const escape_string_regexp_1 = (0, tslib_1.__importDefault)(require("escape-string-regexp"));
|
|
16
15
|
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
17
16
|
const url_1 = require("url");
|
|
18
17
|
const resolve_pathname_1 = (0, tslib_1.__importDefault)(require("resolve-pathname"));
|
|
19
|
-
const posixPath_1 = require("./posixPath");
|
|
20
18
|
const hashUtils_1 = require("./hashUtils");
|
|
21
|
-
const normalizeUrl_1 = require("./normalizeUrl");
|
|
22
19
|
const constants_1 = require("./constants");
|
|
23
20
|
(0, tslib_1.__exportStar)(require("./constants"), exports);
|
|
24
|
-
(0, tslib_1.__exportStar)(require("./
|
|
25
|
-
(0, tslib_1.__exportStar)(require("./normalizeUrl"), exports);
|
|
21
|
+
(0, tslib_1.__exportStar)(require("./urlUtils"), exports);
|
|
26
22
|
(0, tslib_1.__exportStar)(require("./tags"), exports);
|
|
27
|
-
exports.posixPath = posixPath_1.posixPath;
|
|
28
23
|
(0, tslib_1.__exportStar)(require("./markdownParser"), exports);
|
|
29
24
|
(0, tslib_1.__exportStar)(require("./markdownLinks"), exports);
|
|
30
|
-
(0, tslib_1.__exportStar)(require("./escapePath"), exports);
|
|
31
25
|
(0, tslib_1.__exportStar)(require("./slugger"), exports);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
Object.defineProperty(exports, "docuHash", { enumerable: true, get: function () { return hashUtils_2.docuHash; } });
|
|
36
|
-
var globUtils_1 = require("./globUtils");
|
|
37
|
-
Object.defineProperty(exports, "Globby", { enumerable: true, get: function () { return globUtils_1.Globby; } });
|
|
38
|
-
Object.defineProperty(exports, "GlobExcludeDefault", { enumerable: true, get: function () { return globUtils_1.GlobExcludeDefault; } });
|
|
39
|
-
Object.defineProperty(exports, "createMatcher", { enumerable: true, get: function () { return globUtils_1.createMatcher; } });
|
|
40
|
-
Object.defineProperty(exports, "createAbsoluteFilePathMatcher", { enumerable: true, get: function () { return globUtils_1.createAbsoluteFilePathMatcher; } });
|
|
26
|
+
(0, tslib_1.__exportStar)(require("./pathUtils"), exports);
|
|
27
|
+
(0, tslib_1.__exportStar)(require("./hashUtils"), exports);
|
|
28
|
+
(0, tslib_1.__exportStar)(require("./globUtils"), exports);
|
|
41
29
|
(0, tslib_1.__exportStar)(require("./webpackUtils"), exports);
|
|
30
|
+
(0, tslib_1.__exportStar)(require("./dataFileUtils"), exports);
|
|
42
31
|
const fileHash = new Map();
|
|
43
32
|
async function generate(generatedFilesDir, file, content, skipCache = process.env.NODE_ENV === 'production') {
|
|
44
33
|
const filepath = path_1.default.join(generatedFilesDir, file);
|
|
@@ -64,16 +53,6 @@ async function generate(generatedFilesDir, file, content, skipCache = process.en
|
|
|
64
53
|
}
|
|
65
54
|
}
|
|
66
55
|
exports.generate = generate;
|
|
67
|
-
function objectWithKeySorted(obj) {
|
|
68
|
-
// https://github.com/lodash/lodash/issues/1459#issuecomment-460941233
|
|
69
|
-
return Object.keys(obj)
|
|
70
|
-
.sort()
|
|
71
|
-
.reduce((acc, key) => {
|
|
72
|
-
acc[key] = obj[key];
|
|
73
|
-
return acc;
|
|
74
|
-
}, {});
|
|
75
|
-
}
|
|
76
|
-
exports.objectWithKeySorted = objectWithKeySorted;
|
|
77
56
|
const indexRE = /(^|.*\/)index\.(md|mdx|js|jsx|ts|tsx)$/i;
|
|
78
57
|
const extRE = /\.(md|mdx|js|jsx|ts|tsx)$/;
|
|
79
58
|
/**
|
|
@@ -87,44 +66,13 @@ function fileToPath(file) {
|
|
|
87
66
|
return `/${file.replace(extRE, '').replace(/\\/g, '/')}`;
|
|
88
67
|
}
|
|
89
68
|
exports.fileToPath = fileToPath;
|
|
90
|
-
function encodePath(
|
|
91
|
-
return
|
|
69
|
+
function encodePath(userPath) {
|
|
70
|
+
return userPath
|
|
92
71
|
.split('/')
|
|
93
72
|
.map((item) => encodeURIComponent(item))
|
|
94
73
|
.join('/');
|
|
95
74
|
}
|
|
96
75
|
exports.encodePath = encodePath;
|
|
97
|
-
/**
|
|
98
|
-
* Convert first string character to the upper case.
|
|
99
|
-
* E.g: docusaurus -> Docusaurus
|
|
100
|
-
*/
|
|
101
|
-
function upperFirst(str) {
|
|
102
|
-
return str ? str.charAt(0).toUpperCase() + str.slice(1) : '';
|
|
103
|
-
}
|
|
104
|
-
exports.upperFirst = upperFirst;
|
|
105
|
-
/**
|
|
106
|
-
* Generate unique React Component Name.
|
|
107
|
-
* E.g: /foo-bar -> FooBar096
|
|
108
|
-
*/
|
|
109
|
-
function genComponentName(pagePath) {
|
|
110
|
-
if (pagePath === '/') {
|
|
111
|
-
return 'index';
|
|
112
|
-
}
|
|
113
|
-
const pageHash = (0, hashUtils_1.docuHash)(pagePath);
|
|
114
|
-
return upperFirst((0, lodash_1.camelCase)(pageHash));
|
|
115
|
-
}
|
|
116
|
-
exports.genComponentName = genComponentName;
|
|
117
|
-
// When you want to display a path in a message/warning/error,
|
|
118
|
-
// it's more convenient to:
|
|
119
|
-
// - make it relative to cwd()
|
|
120
|
-
// - convert to posix (ie not using windows \ path separator)
|
|
121
|
-
// This way, Jest tests can run more reliably on any computer/CI
|
|
122
|
-
// on both Unix/Windows
|
|
123
|
-
// For Windows users this is not perfect (as they see / instead of \) but it's probably good enough
|
|
124
|
-
function toMessageRelativeFilePath(filePath) {
|
|
125
|
-
return (0, exports.posixPath)(path_1.default.relative(process.cwd(), filePath));
|
|
126
|
-
}
|
|
127
|
-
exports.toMessageRelativeFilePath = toMessageRelativeFilePath;
|
|
128
76
|
const chunkNameCache = new Map();
|
|
129
77
|
/**
|
|
130
78
|
* Generate unique chunk name given a module path.
|
|
@@ -149,45 +97,6 @@ function genChunkName(modulePath, prefix, preferredName, shortId = process.env.N
|
|
|
149
97
|
return chunkName;
|
|
150
98
|
}
|
|
151
99
|
exports.genChunkName = genChunkName;
|
|
152
|
-
// Too dynamic
|
|
153
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
|
|
154
|
-
function idx(target, keyPaths) {
|
|
155
|
-
return (target &&
|
|
156
|
-
keyPaths &&
|
|
157
|
-
(Array.isArray(keyPaths)
|
|
158
|
-
? keyPaths.reduce((obj, key) => obj && obj[key], target)
|
|
159
|
-
: target[keyPaths]));
|
|
160
|
-
}
|
|
161
|
-
exports.idx = idx;
|
|
162
|
-
/**
|
|
163
|
-
* Given a filepath and dirpath, get the first directory.
|
|
164
|
-
*/
|
|
165
|
-
function getSubFolder(file, refDir) {
|
|
166
|
-
const separator = (0, escape_string_regexp_1.default)(path_1.default.sep);
|
|
167
|
-
const baseDir = (0, escape_string_regexp_1.default)(path_1.default.basename(refDir));
|
|
168
|
-
const regexSubFolder = new RegExp(`${baseDir}${separator}(.*?)${separator}.*`);
|
|
169
|
-
const match = regexSubFolder.exec(file);
|
|
170
|
-
return match && match[1];
|
|
171
|
-
}
|
|
172
|
-
exports.getSubFolder = getSubFolder;
|
|
173
|
-
/**
|
|
174
|
-
* Alias filepath relative to site directory, very useful so that we
|
|
175
|
-
* don't expose user's site structure.
|
|
176
|
-
* Example: some/path/to/website/docs/foo.md -> @site/docs/foo.md
|
|
177
|
-
*/
|
|
178
|
-
function aliasedSitePath(filePath, siteDir) {
|
|
179
|
-
const relativePath = (0, exports.posixPath)(path_1.default.relative(siteDir, filePath));
|
|
180
|
-
// Cannot use path.join() as it resolves '../' and removes
|
|
181
|
-
// the '@site'. Let webpack loader resolve it.
|
|
182
|
-
return `@site/${relativePath}`;
|
|
183
|
-
}
|
|
184
|
-
exports.aliasedSitePath = aliasedSitePath;
|
|
185
|
-
function getEditUrl(fileRelativePath, editUrl) {
|
|
186
|
-
return editUrl
|
|
187
|
-
? (0, normalizeUrl_1.normalizeUrl)([editUrl, (0, exports.posixPath)(fileRelativePath)])
|
|
188
|
-
: undefined;
|
|
189
|
-
}
|
|
190
|
-
exports.getEditUrl = getEditUrl;
|
|
191
100
|
function isValidPathname(str) {
|
|
192
101
|
if (!str.startsWith('/')) {
|
|
193
102
|
return false;
|
|
@@ -212,7 +121,10 @@ function addLeadingSlash(str) {
|
|
|
212
121
|
}
|
|
213
122
|
exports.addLeadingSlash = addLeadingSlash;
|
|
214
123
|
function addTrailingPathSeparator(str) {
|
|
215
|
-
return str.endsWith(path_1.default.sep)
|
|
124
|
+
return str.endsWith(path_1.default.sep)
|
|
125
|
+
? str
|
|
126
|
+
: // If this is Windows, we need to change the forward slash to backward
|
|
127
|
+
`${str.replace(/\/$/, '')}${path_1.default.sep}`;
|
|
216
128
|
}
|
|
217
129
|
exports.addTrailingPathSeparator = addTrailingPathSeparator;
|
|
218
130
|
// TODO deduplicate: also present in @docusaurus/utils-common
|
|
@@ -255,7 +167,33 @@ function getPluginI18nPath({ siteDir, locale, pluginName, pluginId = constants_1
|
|
|
255
167
|
`${pluginName}${pluginId === constants_1.DEFAULT_PLUGIN_ID ? '' : `-${pluginId}`}`, ...subPaths);
|
|
256
168
|
}
|
|
257
169
|
exports.getPluginI18nPath = getPluginI18nPath;
|
|
258
|
-
|
|
170
|
+
/**
|
|
171
|
+
* @param permalink The URL that the HTML file corresponds to, without base URL
|
|
172
|
+
* @param outDir Full path to the output directory
|
|
173
|
+
* @param trailingSlash The site config option. If provided, only one path will be read.
|
|
174
|
+
* @returns This returns a buffer, which you have to decode string yourself if
|
|
175
|
+
* needed. (Not always necessary since the output isn't for human consumption
|
|
176
|
+
* anyways, and most HTML manipulation libs accept buffers)
|
|
177
|
+
*/
|
|
178
|
+
async function readOutputHTMLFile(permalink, outDir, trailingSlash) {
|
|
179
|
+
const withTrailingSlashPath = path_1.default.join(outDir, permalink, 'index.html');
|
|
180
|
+
const withoutTrailingSlashPath = path_1.default.join(outDir, `${permalink}.html`);
|
|
181
|
+
if (trailingSlash) {
|
|
182
|
+
return fs_extra_1.default.readFile(withTrailingSlashPath);
|
|
183
|
+
}
|
|
184
|
+
else if (trailingSlash === false) {
|
|
185
|
+
return fs_extra_1.default.readFile(withoutTrailingSlashPath);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
const HTMLPath = await findAsyncSequential([withTrailingSlashPath, withoutTrailingSlashPath], fs_extra_1.default.pathExists);
|
|
189
|
+
if (!HTMLPath) {
|
|
190
|
+
throw new Error(`Expected output HTML file to be found at ${withTrailingSlashPath}`);
|
|
191
|
+
}
|
|
192
|
+
return fs_extra_1.default.readFile(HTMLPath);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.readOutputHTMLFile = readOutputHTMLFile;
|
|
196
|
+
async function mapAsyncSequential(array, action) {
|
|
259
197
|
const results = [];
|
|
260
198
|
// eslint-disable-next-line no-restricted-syntax
|
|
261
199
|
for (const t of array) {
|
|
@@ -264,7 +202,7 @@ async function mapAsyncSequencial(array, action) {
|
|
|
264
202
|
}
|
|
265
203
|
return results;
|
|
266
204
|
}
|
|
267
|
-
exports.
|
|
205
|
+
exports.mapAsyncSequential = mapAsyncSequential;
|
|
268
206
|
async function findAsyncSequential(array, predicate) {
|
|
269
207
|
// eslint-disable-next-line no-restricted-syntax
|
|
270
208
|
for (const t of array) {
|
|
@@ -275,32 +213,18 @@ async function findAsyncSequential(array, predicate) {
|
|
|
275
213
|
return undefined;
|
|
276
214
|
}
|
|
277
215
|
exports.findAsyncSequential = findAsyncSequential;
|
|
278
|
-
// return the first folder path in which the file exists in
|
|
279
|
-
async function findFolderContainingFile(folderPaths, relativeFilePath) {
|
|
280
|
-
return findAsyncSequential(folderPaths, (folderPath) => fs_extra_1.default.pathExists(path_1.default.join(folderPath, relativeFilePath)));
|
|
281
|
-
}
|
|
282
|
-
exports.findFolderContainingFile = findFolderContainingFile;
|
|
283
|
-
async function getFolderContainingFile(folderPaths, relativeFilePath) {
|
|
284
|
-
const maybeFolderPath = await findFolderContainingFile(folderPaths, relativeFilePath);
|
|
285
|
-
// should never happen, as the source was read from the FS anyway...
|
|
286
|
-
if (!maybeFolderPath) {
|
|
287
|
-
throw new Error(`File "${relativeFilePath}" does not exist in any of these folders:\n- ${folderPaths.join('\n- ')}]`);
|
|
288
|
-
}
|
|
289
|
-
return maybeFolderPath;
|
|
290
|
-
}
|
|
291
|
-
exports.getFolderContainingFile = getFolderContainingFile;
|
|
292
216
|
function reportMessage(message, reportingSeverity) {
|
|
293
217
|
switch (reportingSeverity) {
|
|
294
218
|
case 'ignore':
|
|
295
219
|
break;
|
|
296
220
|
case 'log':
|
|
297
|
-
|
|
221
|
+
logger_1.default.info(message);
|
|
298
222
|
break;
|
|
299
223
|
case 'warn':
|
|
300
|
-
|
|
224
|
+
logger_1.default.warn(message);
|
|
301
225
|
break;
|
|
302
226
|
case 'error':
|
|
303
|
-
|
|
227
|
+
logger_1.default.error(message);
|
|
304
228
|
break;
|
|
305
229
|
case 'throw':
|
|
306
230
|
throw new Error(message);
|
|
@@ -313,13 +237,6 @@ function mergeTranslations(contents) {
|
|
|
313
237
|
return contents.reduce((acc, content) => ({ ...acc, ...content }), {});
|
|
314
238
|
}
|
|
315
239
|
exports.mergeTranslations = mergeTranslations;
|
|
316
|
-
function getSwizzledComponent(componentPath) {
|
|
317
|
-
const swizzledComponentPath = path_1.default.resolve(process.cwd(), 'src', componentPath);
|
|
318
|
-
return fs_extra_1.default.existsSync(swizzledComponentPath)
|
|
319
|
-
? swizzledComponentPath
|
|
320
|
-
: undefined;
|
|
321
|
-
}
|
|
322
|
-
exports.getSwizzledComponent = getSwizzledComponent;
|
|
323
240
|
// Useful to update all the messages of a translation file
|
|
324
241
|
// Used in tests to simulate translations
|
|
325
242
|
function updateTranslationFileMessages(translationFile, updateMessage) {
|
|
@@ -332,19 +249,4 @@ function updateTranslationFileMessages(translationFile, updateMessage) {
|
|
|
332
249
|
};
|
|
333
250
|
}
|
|
334
251
|
exports.updateTranslationFileMessages = updateTranslationFileMessages;
|
|
335
|
-
|
|
336
|
-
// Output: {text: "## Some heading", id: "some-heading"}
|
|
337
|
-
function parseMarkdownHeadingId(heading) {
|
|
338
|
-
const customHeadingIdRegex = /^(.*?)\s*\{#([\w-]+)\}$/;
|
|
339
|
-
const matches = customHeadingIdRegex.exec(heading);
|
|
340
|
-
if (matches) {
|
|
341
|
-
return {
|
|
342
|
-
text: matches[1],
|
|
343
|
-
id: matches[2],
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
return { text: heading, id: undefined };
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
exports.parseMarkdownHeadingId = parseMarkdownHeadingId;
|
|
252
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,6EAAwC;AACxC,6DAAwB;AACxB,mCAAkC;AAClC,mCAAiC;AACjC,qEAA0B;AAC1B,6BAAwB;AAOxB,qFAAqD;AAErD,2CAAiD;AACjD,2CAA8C;AAE9C,2DAA4B;AAC5B,0DAA2B;AAC3B,sDAAuB;AACvB,gEAAiC;AACjC,+DAAgC;AAChC,yDAA0B;AAC1B,2DAA4B;AAC5B,2DAA4B;AAC5B,2DAA4B;AAC5B,8DAA+B;AAC/B,+DAAgC;AAEhC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;AACpC,KAAK,UAAU,QAAQ,CAC5B,iBAAyB,EACzB,IAAY,EACZ,OAAe,EACf,YAAqB,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;IAE1D,MAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;IAEpD,IAAI,SAAS,EAAE;QACb,MAAM,kBAAE,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC3C,MAAM,kBAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACtC,OAAO;KACR;IAED,IAAI,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC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AAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YAC5D,GAAG,WAAW;YACd,OAAO,EAAE,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC;SAC5C,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAXD,sEAWC"}
|
package/lib/markdownLinks.d.ts
CHANGED
|
@@ -25,3 +25,4 @@ export declare type ReplaceMarkdownLinksReturn<T extends ContentPaths> = {
|
|
|
25
25
|
brokenMarkdownLinks: BrokenMarkdownLink<T>[];
|
|
26
26
|
};
|
|
27
27
|
export declare function replaceMarkdownLinks<T extends ContentPaths>({ siteDir, fileString, filePath, contentPaths, sourceToPermalink, }: ReplaceMarkdownLinksParams<T>): ReplaceMarkdownLinksReturn<T>;
|
|
28
|
+
//# sourceMappingURL=markdownLinks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownLinks.d.ts","sourceRoot":"","sources":["../src/markdownLinks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,oBAAY,YAAY,GAAG;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,oBAAY,kBAAkB,CAAC,CAAC,SAAS,YAAY,IAAI;IACvD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,CAAC,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,oBAAY,0BAA0B,CAAC,CAAC,SAAS,YAAY,IAAI;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,CAAC,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C,CAAC;AAEF,oBAAY,0BAA0B,CAAC,CAAC,SAAS,YAAY,IAAI;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC;CAC9C,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,YAAY,EAAE,EAC3D,OAAO,EACP,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,iBAAiB,GAClB,EAAE,0BAA0B,CAAC,CAAC,CAAC,GAAG,0BAA0B,CAAC,CAAC,CAAC,CAsE/D"}
|
package/lib/markdownLinks.js
CHANGED
|
@@ -9,15 +9,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.replaceMarkdownLinks = 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
|
function replaceMarkdownLinks({ siteDir, fileString, filePath, contentPaths, sourceToPermalink, }) {
|
|
14
14
|
const { contentPath, contentPathLocalized } = contentPaths;
|
|
15
15
|
const brokenMarkdownLinks = [];
|
|
16
16
|
// Replace internal markdown linking (except in fenced blocks).
|
|
17
17
|
let fencedBlock = false;
|
|
18
|
+
let lastCodeFence = '';
|
|
18
19
|
const lines = fileString.split('\n').map((line) => {
|
|
19
20
|
if (line.trim().startsWith('```')) {
|
|
20
|
-
|
|
21
|
+
if (!fencedBlock) {
|
|
22
|
+
fencedBlock = true;
|
|
23
|
+
[lastCodeFence] = line.trim().match(/^`+/);
|
|
24
|
+
// If we are in a ````-fenced block, all ``` would be plain text instead of fences
|
|
25
|
+
}
|
|
26
|
+
else if (line.trim().match(/^`+/)[0].length >= lastCodeFence.length) {
|
|
27
|
+
fencedBlock = false;
|
|
28
|
+
}
|
|
21
29
|
}
|
|
22
30
|
if (fencedBlock) {
|
|
23
31
|
return line;
|
|
@@ -26,7 +34,7 @@ function replaceMarkdownLinks({ siteDir, fileString, filePath, contentPaths, sou
|
|
|
26
34
|
// Replace inline-style links or reference-style links e.g:
|
|
27
35
|
// This is [Document 1](doc1.md) -> we replace this doc1.md with correct link
|
|
28
36
|
// [doc1]: doc1.md -> we replace this doc1.md with correct link
|
|
29
|
-
const mdRegex = /(?:(?:\]\()|(?:\]:\s?))(?!https)([^'")\]\s>]+\.mdx?)/g;
|
|
37
|
+
const mdRegex = /(?:(?:\]\()|(?:\]:\s?))(?!https?)([^'")\]\s>]+\.mdx?)/g;
|
|
30
38
|
let mdMatch = mdRegex.exec(modifiedLine);
|
|
31
39
|
while (mdMatch !== null) {
|
|
32
40
|
// Replace it to correct html link.
|
|
@@ -37,7 +45,7 @@ function replaceMarkdownLinks({ siteDir, fileString, filePath, contentPaths, sou
|
|
|
37
45
|
`${contentPath}/${decodeURIComponent(mdLink)}`,
|
|
38
46
|
];
|
|
39
47
|
const aliasedSourceMatch = sourcesToTry
|
|
40
|
-
.map((source) => (0,
|
|
48
|
+
.map((source) => (0, pathUtils_1.aliasedSitePath)(source, siteDir))
|
|
41
49
|
.find((source) => sourceToPermalink[source]);
|
|
42
50
|
const permalink = aliasedSourceMatch
|
|
43
51
|
? sourceToPermalink[aliasedSourceMatch]
|
|
@@ -66,3 +74,4 @@ function replaceMarkdownLinks({ siteDir, fileString, filePath, contentPaths, sou
|
|
|
66
74
|
return { newContent, brokenMarkdownLinks };
|
|
67
75
|
}
|
|
68
76
|
exports.replaceMarkdownLinks = replaceMarkdownLinks;
|
|
77
|
+
//# sourceMappingURL=markdownLinks.js.map
|