@docusaurus/utils 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/constants.d.ts +51 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +57 -10
- package/lib/constants.js.map +1 -1
- package/lib/dataFileUtils.d.ts +38 -2
- package/lib/dataFileUtils.d.ts.map +1 -1
- package/lib/dataFileUtils.js +39 -13
- package/lib/dataFileUtils.js.map +1 -1
- package/lib/emitUtils.d.ts +32 -0
- package/lib/emitUtils.d.ts.map +1 -0
- package/lib/emitUtils.js +80 -0
- package/lib/emitUtils.js.map +1 -0
- package/lib/gitUtils.d.ts +54 -5
- package/lib/gitUtils.d.ts.map +1 -1
- package/lib/gitUtils.js +17 -14
- package/lib/gitUtils.js.map +1 -1
- package/lib/globUtils.d.ts +28 -0
- package/lib/globUtils.d.ts.map +1 -1
- package/lib/globUtils.js +36 -13
- package/lib/globUtils.js.map +1 -1
- package/lib/hashUtils.d.ts +5 -4
- package/lib/hashUtils.d.ts.map +1 -1
- package/lib/hashUtils.js +7 -6
- package/lib/hashUtils.js.map +1 -1
- package/lib/i18nUtils.d.ts +51 -0
- package/lib/i18nUtils.d.ts.map +1 -0
- package/lib/i18nUtils.js +69 -0
- package/lib/i18nUtils.js.map +1 -0
- package/lib/index.d.ts +10 -54
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +56 -256
- package/lib/index.js.map +1 -1
- package/lib/jsUtils.d.ts +45 -0
- package/lib/jsUtils.d.ts.map +1 -0
- package/lib/jsUtils.js +94 -0
- package/lib/jsUtils.js.map +1 -0
- package/lib/markdownLinks.d.ts +48 -5
- package/lib/markdownLinks.d.ts.map +1 -1
- package/lib/markdownLinks.js +29 -13
- package/lib/markdownLinks.js.map +1 -1
- package/lib/markdownUtils.d.ts +112 -0
- package/lib/markdownUtils.d.ts.map +1 -0
- package/lib/markdownUtils.js +271 -0
- package/lib/markdownUtils.js.map +1 -0
- package/lib/pathUtils.d.ts +2 -1
- package/lib/pathUtils.d.ts.map +1 -1
- package/lib/pathUtils.js +16 -7
- package/lib/pathUtils.js.map +1 -1
- package/lib/slugger.d.ts +10 -0
- package/lib/slugger.d.ts.map +1 -1
- package/lib/slugger.js +6 -2
- package/lib/slugger.js.map +1 -1
- package/lib/tags.d.ts +42 -10
- package/lib/tags.d.ts.map +1 -1
- package/lib/tags.js +40 -26
- package/lib/tags.js.map +1 -1
- package/lib/urlUtils.d.ts +57 -0
- package/lib/urlUtils.d.ts.map +1 -1
- package/lib/urlUtils.js +132 -6
- package/lib/urlUtils.js.map +1 -1
- package/lib/webpackUtils.d.ts +5 -0
- package/lib/webpackUtils.d.ts.map +1 -1
- package/lib/webpackUtils.js +8 -5
- package/lib/webpackUtils.js.map +1 -1
- package/package.json +11 -11
- package/src/constants.ts +65 -9
- package/src/dataFileUtils.ts +44 -12
- package/src/emitUtils.ts +99 -0
- package/src/gitUtils.ts +77 -17
- package/src/globUtils.ts +34 -13
- package/src/hashUtils.ts +6 -5
- package/src/i18nUtils.ts +115 -0
- package/src/index.ts +43 -307
- package/src/jsUtils.ts +102 -0
- package/src/markdownLinks.ts +71 -28
- package/src/markdownUtils.ts +354 -0
- package/src/pathUtils.ts +15 -7
- package/src/slugger.ts +13 -1
- package/src/tags.ts +53 -28
- package/src/urlUtils.ts +145 -7
- package/src/webpackUtils.ts +11 -4
- package/lib/markdownParser.d.ts +0 -32
- package/lib/markdownParser.d.ts.map +0 -1
- package/lib/markdownParser.js +0 -161
- package/lib/markdownParser.js.map +0 -1
- package/src/markdownParser.ts +0 -201
package/lib/globUtils.d.ts
CHANGED
|
@@ -4,9 +4,37 @@
|
|
|
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
|
+
/** A re-export of the globby instance. */
|
|
7
8
|
export { default as Globby } from 'globby';
|
|
9
|
+
/**
|
|
10
|
+
* The default glob patterns we ignore when sourcing content.
|
|
11
|
+
* - Ignore files and folders starting with `_` recursively
|
|
12
|
+
* - Ignore tests
|
|
13
|
+
*/
|
|
8
14
|
export declare const GlobExcludeDefault: string[];
|
|
9
15
|
declare type Matcher = (str: string) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* A very thin wrapper around `Micromatch.makeRe`.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link createAbsoluteFilePathMatcher}
|
|
20
|
+
* @param patterns A list of glob patterns. If the list is empty, it defaults to
|
|
21
|
+
* matching none.
|
|
22
|
+
* @returns A matcher handle that tells if a file path is matched by any of the
|
|
23
|
+
* patterns.
|
|
24
|
+
*/
|
|
10
25
|
export declare function createMatcher(patterns: string[]): Matcher;
|
|
26
|
+
/**
|
|
27
|
+
* We use match patterns like `"** /_* /**"` (ignore the spaces), where `"_*"`
|
|
28
|
+
* should only be matched within a subfolder. This function would:
|
|
29
|
+
* - Match `/user/sebastien/website/docs/_partials/xyz.md`
|
|
30
|
+
* - Ignore `/user/_sebastien/website/docs/partials/xyz.md`
|
|
31
|
+
*
|
|
32
|
+
* @param patterns A list of glob patterns.
|
|
33
|
+
* @param rootFolders A list of root folders to resolve the glob from.
|
|
34
|
+
* @returns A matcher handle that tells if a file path is matched by any of the
|
|
35
|
+
* patterns, resolved from the first root folder that contains the path.
|
|
36
|
+
* @throws Throws when the returned matcher receives a path that doesn't belong
|
|
37
|
+
* to any of the `rootFolders`.
|
|
38
|
+
*/
|
|
11
39
|
export declare function createAbsoluteFilePathMatcher(patterns: string[], rootFolders: string[]): Matcher;
|
|
12
40
|
//# sourceMappingURL=globUtils.d.ts.map
|
package/lib/globUtils.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"globUtils.d.ts","sourceRoot":"","sources":["../src/globUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,0CAA0C;AAC1C,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,QAAQ,CAAC;AAEzC;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,UAK9B,CAAC;AAEF,aAAK,OAAO,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;AAExC;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CASzD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,MAAM,EAAE,EAClB,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAmBT"}
|
package/lib/globUtils.js
CHANGED
|
@@ -9,36 +9,59 @@ 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
|
-
const micromatch_1 =
|
|
13
|
-
const path_1 =
|
|
12
|
+
const micromatch_1 = tslib_1.__importDefault(require("micromatch")); // Note: Micromatch is used by Globby
|
|
13
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
|
+
/** A re-export of the globby instance. */
|
|
14
15
|
var globby_1 = require("globby");
|
|
15
|
-
Object.defineProperty(exports, "Globby", { enumerable: true, get: function () { return
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
Object.defineProperty(exports, "Globby", { enumerable: true, get: function () { return tslib_1.__importDefault(globby_1).default; } });
|
|
17
|
+
/**
|
|
18
|
+
* The default glob patterns we ignore when sourcing content.
|
|
19
|
+
* - Ignore files and folders starting with `_` recursively
|
|
20
|
+
* - Ignore tests
|
|
21
|
+
*/
|
|
18
22
|
exports.GlobExcludeDefault = [
|
|
19
|
-
// Ignore files starting with _
|
|
20
23
|
'**/_*.{js,jsx,ts,tsx,md,mdx}',
|
|
21
|
-
// Ignore folders starting with _ (including folder content)
|
|
22
24
|
'**/_*/**',
|
|
23
|
-
// Ignore tests
|
|
24
25
|
'**/*.test.{js,jsx,ts,tsx}',
|
|
25
26
|
'**/__tests__/**',
|
|
26
27
|
];
|
|
28
|
+
/**
|
|
29
|
+
* A very thin wrapper around `Micromatch.makeRe`.
|
|
30
|
+
*
|
|
31
|
+
* @see {@link createAbsoluteFilePathMatcher}
|
|
32
|
+
* @param patterns A list of glob patterns. If the list is empty, it defaults to
|
|
33
|
+
* matching none.
|
|
34
|
+
* @returns A matcher handle that tells if a file path is matched by any of the
|
|
35
|
+
* patterns.
|
|
36
|
+
*/
|
|
27
37
|
function createMatcher(patterns) {
|
|
38
|
+
if (patterns.length === 0) {
|
|
39
|
+
// `/(?:)/.test("foo")` is `true`
|
|
40
|
+
return () => false;
|
|
41
|
+
}
|
|
28
42
|
const regexp = new RegExp(patterns.map((pattern) => micromatch_1.default.makeRe(pattern).source).join('|'));
|
|
29
43
|
return (str) => regexp.test(str);
|
|
30
44
|
}
|
|
31
45
|
exports.createMatcher = createMatcher;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
46
|
+
/**
|
|
47
|
+
* We use match patterns like `"** /_* /**"` (ignore the spaces), where `"_*"`
|
|
48
|
+
* should only be matched within a subfolder. This function would:
|
|
49
|
+
* - Match `/user/sebastien/website/docs/_partials/xyz.md`
|
|
50
|
+
* - Ignore `/user/_sebastien/website/docs/partials/xyz.md`
|
|
51
|
+
*
|
|
52
|
+
* @param patterns A list of glob patterns.
|
|
53
|
+
* @param rootFolders A list of root folders to resolve the glob from.
|
|
54
|
+
* @returns A matcher handle that tells if a file path is matched by any of the
|
|
55
|
+
* patterns, resolved from the first root folder that contains the path.
|
|
56
|
+
* @throws Throws when the returned matcher receives a path that doesn't belong
|
|
57
|
+
* to any of the `rootFolders`.
|
|
58
|
+
*/
|
|
36
59
|
function createAbsoluteFilePathMatcher(patterns, rootFolders) {
|
|
37
60
|
const matcher = createMatcher(patterns);
|
|
38
61
|
function getRelativeFilePath(absoluteFilePath) {
|
|
39
62
|
const rootFolder = rootFolders.find((folderPath) => absoluteFilePath.startsWith(folderPath));
|
|
40
63
|
if (!rootFolder) {
|
|
41
|
-
throw new Error(`createAbsoluteFilePathMatcher unexpected error, absoluteFilePath=${absoluteFilePath} was not contained in any of the root folders ${
|
|
64
|
+
throw new Error(`createAbsoluteFilePathMatcher unexpected error, absoluteFilePath=${absoluteFilePath} was not contained in any of the root folders: ${rootFolders.join(', ')}`);
|
|
42
65
|
}
|
|
43
66
|
return path_1.default.relative(rootFolder, absoluteFilePath);
|
|
44
67
|
}
|
package/lib/globUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globUtils.js","sourceRoot":"","sources":["../src/globUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,qEAAqE;AAErE,
|
|
1
|
+
{"version":3,"file":"globUtils.js","sourceRoot":"","sources":["../src/globUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,qEAAqE;AAErE,oEAAoC,CAAC,qCAAqC;AAC1E,wDAAwB;AAExB,0CAA0C;AAC1C,iCAAyC;AAAjC,yHAAA,OAAO,OAAU;AAEzB;;;;GAIG;AACU,QAAA,kBAAkB,GAAG;IAChC,8BAA8B;IAC9B,UAAU;IACV,2BAA2B;IAC3B,iBAAiB;CAClB,CAAC;AAIF;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAAC,QAAkB;IAC9C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;QACzB,iCAAiC;QACjC,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC;KACpB;IACD,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;AATD,sCASC;AAED;;;;;;;;;;;;GAYG;AACH,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,kDAAkD,WAAW,CAAC,IAAI,CACpJ,IAAI,CACL,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
|
@@ -4,13 +4,14 @@
|
|
|
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
|
+
/** Thin wrapper around `crypto.createHash("md5")`. */
|
|
7
8
|
export declare function md5Hash(str: string): string;
|
|
9
|
+
/** Creates an MD5 hash and truncates it to the given length. */
|
|
8
10
|
export declare function simpleHash(str: string, length: number): string;
|
|
9
11
|
/**
|
|
10
|
-
* Given an input string, convert to kebab-case and append a hash
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* filename per OS. Avoids ERRNAMETOOLONG error.
|
|
12
|
+
* Given an input string, convert to kebab-case and append a hash, avoiding name
|
|
13
|
+
* collision. Also removes part of the string if its larger than the allowed
|
|
14
|
+
* filename per OS, avoiding `ERRNAMETOOLONG` error.
|
|
14
15
|
*/
|
|
15
16
|
export declare function docuHash(str: string): string;
|
|
16
17
|
//# sourceMappingURL=hashUtils.d.ts.map
|
package/lib/hashUtils.d.ts.map
CHANGED
|
@@ -1 +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
|
|
1
|
+
{"version":3,"file":"hashUtils.d.ts","sourceRoot":"","sources":["../src/hashUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,sDAAsD;AACtD,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,gEAAgE;AAChE,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE9D;AAGD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAU5C"}
|
package/lib/hashUtils.js
CHANGED
|
@@ -9,22 +9,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.docuHash = exports.simpleHash = exports.md5Hash = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const crypto_1 = require("crypto");
|
|
12
|
-
const lodash_1 =
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
13
|
const pathUtils_1 = require("./pathUtils");
|
|
14
|
+
/** Thin wrapper around `crypto.createHash("md5")`. */
|
|
14
15
|
function md5Hash(str) {
|
|
15
16
|
return (0, crypto_1.createHash)('md5').update(str).digest('hex');
|
|
16
17
|
}
|
|
17
18
|
exports.md5Hash = md5Hash;
|
|
19
|
+
/** Creates an MD5 hash and truncates it to the given length. */
|
|
18
20
|
function simpleHash(str, length) {
|
|
19
|
-
return md5Hash(str).
|
|
21
|
+
return md5Hash(str).substring(0, length);
|
|
20
22
|
}
|
|
21
23
|
exports.simpleHash = simpleHash;
|
|
22
24
|
// Based on https://github.com/gatsbyjs/gatsby/pull/21518/files
|
|
23
25
|
/**
|
|
24
|
-
* Given an input string, convert to kebab-case and append a hash
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* filename per OS. Avoids ERRNAMETOOLONG error.
|
|
26
|
+
* Given an input string, convert to kebab-case and append a hash, avoiding name
|
|
27
|
+
* collision. Also removes part of the string if its larger than the allowed
|
|
28
|
+
* filename per OS, avoiding `ERRNAMETOOLONG` error.
|
|
28
29
|
*/
|
|
29
30
|
function docuHash(str) {
|
|
30
31
|
if (str === '/') {
|
package/lib/hashUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hashUtils.js","sourceRoot":"","sources":["../src/hashUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,mCAAkC;AAClC,
|
|
1
|
+
{"version":3,"file":"hashUtils.js","sourceRoot":"","sources":["../src/hashUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,mCAAkC;AAClC,4DAAuB;AACvB,2CAAqD;AAErD,sDAAsD;AACtD,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,gEAAgE;AAChE,SAAgB,UAAU,CAAC,GAAW,EAAE,MAAc;IACpD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAC3C,CAAC;AAFD,gCAEC;AAED,+DAA+D;AAC/D;;;;GAIG;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,gBAAC,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,SAAS,EAAE,CAAC;IACtD,IAAI,IAAA,yBAAa,EAAC,UAAU,CAAC,EAAE;QAC7B,OAAO,GAAG,IAAA,qBAAS,EAAC,gBAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC;KACtD;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAVD,4BAUC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { TranslationFileContent, TranslationFile, I18n } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* Takes a list of translation file contents, and shallow-merges them into one.
|
|
10
|
+
*/
|
|
11
|
+
export declare function mergeTranslations(contents: TranslationFileContent[]): TranslationFileContent;
|
|
12
|
+
/**
|
|
13
|
+
* Useful to update all the messages of a translation file. Used in tests to
|
|
14
|
+
* simulate translations.
|
|
15
|
+
*/
|
|
16
|
+
export declare function updateTranslationFileMessages(translationFile: TranslationFile, updateMessage: (message: string) => string): TranslationFile;
|
|
17
|
+
/**
|
|
18
|
+
* Takes everything needed and constructs a plugin i18n path. Plugins should
|
|
19
|
+
* expect everything it needs for translations to be found under this path.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getPluginI18nPath({ siteDir, locale, pluginName, pluginId, subPaths, }: {
|
|
22
|
+
siteDir: string;
|
|
23
|
+
locale: string;
|
|
24
|
+
pluginName: string;
|
|
25
|
+
pluginId?: string | undefined;
|
|
26
|
+
subPaths?: string[];
|
|
27
|
+
}): string;
|
|
28
|
+
/**
|
|
29
|
+
* Takes a path and returns a localized a version (which is basically `path +
|
|
30
|
+
* i18n.currentLocale`).
|
|
31
|
+
*/
|
|
32
|
+
export declare function localizePath({ pathType, path: originalPath, i18n, options, }: {
|
|
33
|
+
/**
|
|
34
|
+
* FS paths will treat Windows specially; URL paths will always have a
|
|
35
|
+
* trailing slash to make it a valid base URL.
|
|
36
|
+
*/
|
|
37
|
+
pathType: 'fs' | 'url';
|
|
38
|
+
/** The path, URL or file path, to be localized. */
|
|
39
|
+
path: string;
|
|
40
|
+
/** The current i18n context. */
|
|
41
|
+
i18n: I18n;
|
|
42
|
+
options?: {
|
|
43
|
+
/**
|
|
44
|
+
* By default, we don't localize the path of defaultLocale. This option
|
|
45
|
+
* would override that behavior. Setting `false` is useful for `yarn build
|
|
46
|
+
* -l zh-Hans` to always emit into the root build directory.
|
|
47
|
+
*/
|
|
48
|
+
localizePath?: boolean;
|
|
49
|
+
};
|
|
50
|
+
}): string;
|
|
51
|
+
//# sourceMappingURL=i18nUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18nUtils.d.ts","sourceRoot":"","sources":["../src/i18nUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EACf,IAAI,EACL,MAAM,mBAAmB,CAAC;AAI3B;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,sBAAsB,EAAE,GACjC,sBAAsB,CAExB;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GACzC,eAAe,CAQjB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,MAAM,EACN,UAAU,EACV,QAA4B,EAC5B,QAAa,GACd,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,GAAG,MAAM,CAYT;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,IAAI,EAAE,YAAY,EAClB,IAAI,EACJ,OAAY,GACb,EAAE;IACD;;;OAGG;IACH,QAAQ,EAAE,IAAI,GAAG,KAAK,CAAC;IACvB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,CAAC,EAAE;QACR;;;;WAIG;QACH,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB,CAAC;CACH,GAAG,MAAM,CAcT"}
|
package/lib/i18nUtils.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
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.localizePath = exports.getPluginI18nPath = exports.updateTranslationFileMessages = exports.mergeTranslations = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
|
+
const urlUtils_1 = require("./urlUtils");
|
|
15
|
+
/**
|
|
16
|
+
* Takes a list of translation file contents, and shallow-merges them into one.
|
|
17
|
+
*/
|
|
18
|
+
function mergeTranslations(contents) {
|
|
19
|
+
return contents.reduce((acc, content) => ({ ...acc, ...content }), {});
|
|
20
|
+
}
|
|
21
|
+
exports.mergeTranslations = mergeTranslations;
|
|
22
|
+
/**
|
|
23
|
+
* Useful to update all the messages of a translation file. Used in tests to
|
|
24
|
+
* simulate translations.
|
|
25
|
+
*/
|
|
26
|
+
function updateTranslationFileMessages(translationFile, updateMessage) {
|
|
27
|
+
return {
|
|
28
|
+
...translationFile,
|
|
29
|
+
content: lodash_1.default.mapValues(translationFile.content, (translation) => ({
|
|
30
|
+
...translation,
|
|
31
|
+
message: updateMessage(translation.message),
|
|
32
|
+
})),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.updateTranslationFileMessages = updateTranslationFileMessages;
|
|
36
|
+
/**
|
|
37
|
+
* Takes everything needed and constructs a plugin i18n path. Plugins should
|
|
38
|
+
* expect everything it needs for translations to be found under this path.
|
|
39
|
+
*/
|
|
40
|
+
function getPluginI18nPath({ siteDir, locale, pluginName, pluginId = constants_1.DEFAULT_PLUGIN_ID, subPaths = [], }) {
|
|
41
|
+
return path_1.default.join(siteDir, constants_1.I18N_DIR_NAME,
|
|
42
|
+
// Namespace first by locale: convenient to work in a single folder for a
|
|
43
|
+
// translator
|
|
44
|
+
locale,
|
|
45
|
+
// Make it convenient to use for single-instance
|
|
46
|
+
// ie: return "docs", not "docs-default" nor "docs/default"
|
|
47
|
+
`${pluginName}${pluginId === constants_1.DEFAULT_PLUGIN_ID ? '' : `-${pluginId}`}`, ...subPaths);
|
|
48
|
+
}
|
|
49
|
+
exports.getPluginI18nPath = getPluginI18nPath;
|
|
50
|
+
/**
|
|
51
|
+
* Takes a path and returns a localized a version (which is basically `path +
|
|
52
|
+
* i18n.currentLocale`).
|
|
53
|
+
*/
|
|
54
|
+
function localizePath({ pathType, path: originalPath, i18n, options = {}, }) {
|
|
55
|
+
const shouldLocalizePath =
|
|
56
|
+
//
|
|
57
|
+
options.localizePath ?? i18n.currentLocale !== i18n.defaultLocale;
|
|
58
|
+
if (!shouldLocalizePath) {
|
|
59
|
+
return originalPath;
|
|
60
|
+
}
|
|
61
|
+
// FS paths need special care, for Windows support
|
|
62
|
+
if (pathType === 'fs') {
|
|
63
|
+
return path_1.default.join(originalPath, i18n.currentLocale);
|
|
64
|
+
}
|
|
65
|
+
// Url paths; add a trailing slash so it's a valid base URL
|
|
66
|
+
return (0, urlUtils_1.normalizeUrl)([originalPath, i18n.currentLocale, '/']);
|
|
67
|
+
}
|
|
68
|
+
exports.localizePath = localizePath;
|
|
69
|
+
//# sourceMappingURL=i18nUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18nUtils.js","sourceRoot":"","sources":["../src/i18nUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AACxB,4DAAuB;AAMvB,2CAA6D;AAC7D,yCAAwC;AAExC;;GAEG;AACH,SAAgB,iBAAiB,CAC/B,QAAkC;IAElC,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,EAAC,GAAG,GAAG,EAAE,GAAG,OAAO,EAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACvE,CAAC;AAJD,8CAIC;AAED;;;GAGG;AACH,SAAgB,6BAA6B,CAC3C,eAAgC,EAChC,aAA0C;IAE1C,OAAO;QACL,GAAG,eAAe;QAClB,OAAO,EAAE,gBAAC,CAAC,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YAC9D,GAAG,WAAW;YACd,OAAO,EAAE,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC;SAC5C,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAXD,sEAWC;AAED;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,MAAM,EACN,UAAU,EACV,QAAQ,GAAG,6BAAiB,EAC5B,QAAQ,GAAG,EAAE,GAOd;IACC,OAAO,cAAI,CAAC,IAAI,CACd,OAAO,EACP,yBAAa;IACb,yEAAyE;IACzE,aAAa;IACb,MAAM;IACN,gDAAgD;IAChD,2DAA2D;IAC3D,GAAG,UAAU,GAAG,QAAQ,KAAK,6BAAiB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,EAAE,EACtE,GAAG,QAAQ,CACZ,CAAC;AACJ,CAAC;AAxBD,8CAwBC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,IAAI,EAAE,YAAY,EAClB,IAAI,EACJ,OAAO,GAAG,EAAE,GAmBb;IACC,MAAM,kBAAkB;IACtB,EAAE;IACF,OAAO,CAAC,YAAY,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,CAAC,aAAa,CAAC;IAEpE,IAAI,CAAC,kBAAkB,EAAE;QACvB,OAAO,YAAY,CAAC;KACrB;IACD,kDAAkD;IAClD,IAAI,QAAQ,KAAK,IAAI,EAAE;QACrB,OAAO,cAAI,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;KACpD;IACD,2DAA2D;IAC3D,OAAO,IAAA,uBAAY,EAAC,CAAC,YAAY,EAAE,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC,CAAC;AAC/D,CAAC;AArCD,oCAqCC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -4,63 +4,19 @@
|
|
|
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
|
-
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
7
|
+
export { NODE_MAJOR_VERSION, NODE_MINOR_VERSION, DOCUSAURUS_VERSION, DEFAULT_BUILD_DIR_NAME, DEFAULT_CONFIG_FILE_NAME, BABEL_CONFIG_FILE_NAME, GENERATED_FILES_DIR_NAME, SRC_DIR_NAME, DEFAULT_STATIC_DIR_NAME, OUTPUT_STATIC_ASSETS_DIR_NAME, THEME_PATH, I18N_DIR_NAME, CODE_TRANSLATIONS_FILE_NAME, DEFAULT_PORT, DEFAULT_PLUGIN_ID, WEBPACK_URL_LOADER_LIMIT, } from './constants';
|
|
8
|
+
export { generate, readOutputHTMLFile } from './emitUtils';
|
|
9
|
+
export { getFileCommitDate, FileNotTrackedError, GitNotFoundError, } from './gitUtils';
|
|
10
|
+
export { mergeTranslations, updateTranslationFileMessages, getPluginI18nPath, localizePath, } from './i18nUtils';
|
|
11
|
+
export { removeSuffix, removePrefix, mapAsyncSequential, findAsyncSequential, reportMessage, } from './jsUtils';
|
|
12
|
+
export { normalizeUrl, getEditUrl, fileToPath, encodePath, isValidPathname, resolvePathname, addLeadingSlash, addTrailingSlash, removeTrailingSlash, hasSSHProtocol, buildHttpsUrl, buildSshUrl, } from './urlUtils';
|
|
13
|
+
export { type Tag, type TagsListItem, type TagModule, type FrontMatterTag, normalizeFrontMatterTags, groupTaggedItems, } from './tags';
|
|
14
|
+
export { parseMarkdownHeadingId, createExcerpt, parseFrontMatter, parseMarkdownContentTitle, parseMarkdownString, writeMarkdownHeadingId, type WriteHeadingIDOptions, } from './markdownUtils';
|
|
15
|
+
export { type ContentPaths, type BrokenMarkdownLink, replaceMarkdownLinks, } from './markdownLinks';
|
|
15
16
|
export { type SluggerOptions, type Slugger, createSlugger } from './slugger';
|
|
16
|
-
export { isNameTooLong, shortName, posixPath, toMessageRelativeFilePath, aliasedSitePath, escapePath, } from './pathUtils';
|
|
17
|
+
export { isNameTooLong, shortName, posixPath, toMessageRelativeFilePath, aliasedSitePath, escapePath, addTrailingPathSeparator, } from './pathUtils';
|
|
17
18
|
export { md5Hash, simpleHash, docuHash } from './hashUtils';
|
|
18
19
|
export { Globby, GlobExcludeDefault, createMatcher, createAbsoluteFilePathMatcher, } from './globUtils';
|
|
19
20
|
export { getFileLoaderUtils } from './webpackUtils';
|
|
20
21
|
export { getDataFilePath, getDataFileData, getContentPathList, findFolderContainingFile, getFolderContainingFile, } from './dataFileUtils';
|
|
21
|
-
export declare function generate(generatedFilesDir: string, file: string, content: string, skipCache?: boolean): Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* Convert filepath to url path.
|
|
24
|
-
* Example: 'index.md' -> '/', 'foo/bar.js' -> '/foo/bar',
|
|
25
|
-
*/
|
|
26
|
-
export declare function fileToPath(file: string): string;
|
|
27
|
-
export declare function encodePath(userPath: string): string;
|
|
28
|
-
/**
|
|
29
|
-
* Generate unique chunk name given a module path.
|
|
30
|
-
*/
|
|
31
|
-
export declare function genChunkName(modulePath: string, prefix?: string, preferredName?: string, shortId?: boolean): string;
|
|
32
|
-
export declare function isValidPathname(str: string): boolean;
|
|
33
|
-
export declare function resolvePathname(to: string, from?: string): string;
|
|
34
|
-
export declare function addLeadingSlash(str: string): string;
|
|
35
|
-
export declare function addTrailingPathSeparator(str: string): string;
|
|
36
|
-
export declare function addTrailingSlash(str: string): string;
|
|
37
|
-
export declare function removeTrailingSlash(str: string): string;
|
|
38
|
-
export declare function removeSuffix(str: string, suffix: string): string;
|
|
39
|
-
export declare function removePrefix(str: string, prefix: string): string;
|
|
40
|
-
export declare function getElementsAround<T>(array: T[], aroundIndex: number): {
|
|
41
|
-
next: T | undefined;
|
|
42
|
-
previous: T | undefined;
|
|
43
|
-
};
|
|
44
|
-
export declare function getPluginI18nPath({ siteDir, locale, pluginName, pluginId, subPaths, }: {
|
|
45
|
-
siteDir: string;
|
|
46
|
-
locale: string;
|
|
47
|
-
pluginName: string;
|
|
48
|
-
pluginId?: string | undefined;
|
|
49
|
-
subPaths?: string[];
|
|
50
|
-
}): string;
|
|
51
|
-
/**
|
|
52
|
-
* @param permalink The URL that the HTML file corresponds to, without base URL
|
|
53
|
-
* @param outDir Full path to the output directory
|
|
54
|
-
* @param trailingSlash The site config option. If provided, only one path will
|
|
55
|
-
* be read.
|
|
56
|
-
* @returns This returns a buffer, which you have to decode string yourself if
|
|
57
|
-
* needed. (Not always necessary since the output isn't for human consumption
|
|
58
|
-
* anyways, and most HTML manipulation libs accept buffers)
|
|
59
|
-
*/
|
|
60
|
-
export declare function readOutputHTMLFile(permalink: string, outDir: string, trailingSlash: boolean | undefined): Promise<Buffer>;
|
|
61
|
-
export declare function mapAsyncSequential<T, R>(array: T[], action: (t: T) => Promise<R>): Promise<R[]>;
|
|
62
|
-
export declare function findAsyncSequential<T>(array: T[], predicate: (t: T) => Promise<boolean>): Promise<T | undefined>;
|
|
63
|
-
export declare function reportMessage(message: string, reportingSeverity: ReportingSeverity): void;
|
|
64
|
-
export declare function mergeTranslations(contents: TranslationFileContent[]): TranslationFileContent;
|
|
65
|
-
export declare function updateTranslationFileMessages(translationFile: TranslationFile, updateMessage: (message: string) => string): TranslationFile;
|
|
66
22
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,YAAY,EACZ,uBAAuB,EACvB,6BAA6B,EAC7B,UAAU,EACV,aAAa,EACb,2BAA2B,EAC3B,YAAY,EACZ,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,QAAQ,EAAE,kBAAkB,EAAC,MAAM,aAAa,CAAC;AACzD,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,iBAAiB,EACjB,6BAA6B,EAC7B,iBAAiB,EACjB,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,GACd,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EACV,eAAe,EACf,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,KAAK,GAAG,EACR,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,gBAAgB,EAChB,yBAAyB,EACzB,mBAAmB,EACnB,sBAAsB,EACtB,KAAK,qBAAqB,GAC3B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAC,KAAK,cAAc,EAAE,KAAK,OAAO,EAAE,aAAa,EAAC,MAAM,WAAW,CAAC;AAC3E,OAAO,EACL,aAAa,EACb,SAAS,EACT,SAAS,EACT,yBAAyB,EACzB,eAAe,EACf,UAAU,EACV,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAC,MAAM,aAAa,CAAC;AAC1D,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,aAAa,EACb,6BAA6B,GAC9B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAClD,OAAO,EACL,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC"}
|