@docusaurus/utils 2.0.0-beta.17 → 2.0.0-beta.18
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 +49 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +53 -8
- 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 +34 -8
- package/lib/dataFileUtils.js.map +1 -1
- package/lib/emitUtils.d.ts +12 -0
- package/lib/emitUtils.d.ts.map +1 -1
- package/lib/emitUtils.js +24 -7
- package/lib/emitUtils.js.map +1 -1
- package/lib/gitUtils.d.ts +54 -5
- package/lib/gitUtils.d.ts.map +1 -1
- package/lib/gitUtils.js +14 -11
- package/lib/gitUtils.js.map +1 -1
- package/lib/globUtils.d.ts +27 -0
- package/lib/globUtils.d.ts.map +1 -1
- package/lib/globUtils.js +28 -10
- 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 +6 -5
- package/lib/hashUtils.js.map +1 -1
- package/lib/i18nUtils.d.ts +11 -0
- package/lib/i18nUtils.d.ts.map +1 -1
- package/lib/i18nUtils.js +12 -3
- package/lib/i18nUtils.js.map +1 -1
- package/lib/index.d.ts +7 -7
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +16 -11
- package/lib/index.js.map +1 -1
- package/lib/jsUtils.d.ts +32 -4
- package/lib/jsUtils.d.ts.map +1 -1
- package/lib/jsUtils.js +35 -13
- package/lib/jsUtils.js.map +1 -1
- package/lib/markdownLinks.d.ts +48 -5
- package/lib/markdownLinks.d.ts.map +1 -1
- package/lib/markdownLinks.js +21 -11
- 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 +1 -1
- package/lib/pathUtils.d.ts.map +1 -1
- package/lib/pathUtils.js +2 -2
- 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 +4 -0
- package/lib/slugger.js.map +1 -1
- package/lib/tags.d.ts +31 -10
- package/lib/tags.d.ts.map +1 -1
- package/lib/tags.js +38 -23
- package/lib/tags.js.map +1 -1
- package/lib/urlUtils.d.ts +48 -2
- package/lib/urlUtils.d.ts.map +1 -1
- package/lib/urlUtils.js +81 -9
- 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 +6 -2
- package/lib/webpackUtils.js.map +1 -1
- package/package.json +9 -9
- package/src/constants.ts +61 -9
- package/src/dataFileUtils.ts +43 -11
- package/src/emitUtils.ts +26 -9
- package/src/gitUtils.ts +76 -16
- package/src/globUtils.ts +29 -13
- package/src/hashUtils.ts +6 -5
- package/src/i18nUtils.ts +13 -4
- package/src/index.ts +14 -8
- package/src/jsUtils.ts +34 -20
- package/src/markdownLinks.ts +64 -27
- package/src/markdownUtils.ts +354 -0
- package/src/pathUtils.ts +2 -2
- package/src/slugger.ts +13 -1
- package/src/tags.ts +39 -27
- package/src/urlUtils.ts +96 -10
- package/src/webpackUtils.ts +10 -2
- package/lib/markdownParser.d.ts +0 -32
- package/lib/markdownParser.d.ts.map +0 -1
- package/lib/markdownParser.js +0 -160
- package/lib/markdownParser.js.map +0 -1
- package/src/markdownParser.ts +0 -201
package/lib/tags.js
CHANGED
|
@@ -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.groupTaggedItems = exports.normalizeFrontMatterTags =
|
|
9
|
+
exports.groupTaggedItems = exports.normalizeFrontMatterTags = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
12
|
const urlUtils_1 = require("./urlUtils");
|
|
@@ -32,37 +32,52 @@ function normalizeFrontMatterTag(tagsPath, frontMatterTag) {
|
|
|
32
32
|
permalink: normalizeTagPermalink(tag.permalink),
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Takes tag objects as they are defined in front matter, and normalizes each
|
|
37
|
+
* into a standard tag object. The permalink is created by appending the
|
|
38
|
+
* sluggified label to `tagsPath`. Front matter tags already containing
|
|
39
|
+
* permalinks would still have `tagsPath` prepended.
|
|
40
|
+
*
|
|
41
|
+
* The result will always be unique by permalinks. The behavior with colliding
|
|
42
|
+
* permalinks is undetermined.
|
|
43
|
+
*/
|
|
44
|
+
function normalizeFrontMatterTags(
|
|
45
|
+
/** Base path to append the tag permalinks to. */
|
|
46
|
+
tagsPath,
|
|
47
|
+
/** Can be `undefined`, so that we can directly pipe in `frontMatter.tags`. */
|
|
48
|
+
frontMatterTags = []) {
|
|
37
49
|
const tags = frontMatterTags.map((tag) => normalizeFrontMatterTag(tagsPath, tag));
|
|
38
50
|
return lodash_1.default.uniqBy(tags, (tag) => tag.permalink);
|
|
39
51
|
}
|
|
40
52
|
exports.normalizeFrontMatterTags = normalizeFrontMatterTags;
|
|
41
53
|
/**
|
|
42
|
-
* Permits to group docs/
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
54
|
+
* Permits to group docs/blog posts by tag (provided by front matter).
|
|
55
|
+
*
|
|
56
|
+
* @returns a map from tag permalink to the items and other relevant tag data.
|
|
57
|
+
* The record is indexed by permalink, because routes must be unique in the end.
|
|
58
|
+
* Labels may vary on 2 MD files but they are normalized. Docs with
|
|
59
|
+
* label='some label' and label='some-label' should end up in the same page.
|
|
60
|
+
*/
|
|
61
|
+
function groupTaggedItems(items,
|
|
62
|
+
/**
|
|
63
|
+
* A callback telling me how to get the tags list of the current item. Usually
|
|
64
|
+
* simply getting it from some metadata of the current item.
|
|
48
65
|
*/
|
|
49
|
-
|
|
66
|
+
getItemTags) {
|
|
50
67
|
const result = {};
|
|
51
|
-
function handleItemTag(item, tag) {
|
|
52
|
-
// Init missing tag groups
|
|
53
|
-
// TODO: it's not really clear what should be the behavior if 2 items have
|
|
54
|
-
// the same tag but the permalink is different for each
|
|
55
|
-
// For now, the first tag found wins
|
|
56
|
-
result[tag.permalink] = result[tag.permalink] ?? {
|
|
57
|
-
tag,
|
|
58
|
-
items: [],
|
|
59
|
-
};
|
|
60
|
-
// Add item to group
|
|
61
|
-
result[tag.permalink].items.push(item);
|
|
62
|
-
}
|
|
63
68
|
items.forEach((item) => {
|
|
64
69
|
getItemTags(item).forEach((tag) => {
|
|
65
|
-
|
|
70
|
+
var _a;
|
|
71
|
+
// Init missing tag groups
|
|
72
|
+
// TODO: it's not really clear what should be the behavior if 2 tags have
|
|
73
|
+
// the same permalink but the label is different for each
|
|
74
|
+
// For now, the first tag found wins
|
|
75
|
+
result[_a = tag.permalink] ?? (result[_a] = {
|
|
76
|
+
tag,
|
|
77
|
+
items: [],
|
|
78
|
+
});
|
|
79
|
+
// Add item to group
|
|
80
|
+
result[tag.permalink].items.push(item);
|
|
66
81
|
});
|
|
67
82
|
});
|
|
68
83
|
// If user add twice the same tag to a md doc (weird but possible),
|
package/lib/tags.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,4DAAuB;AACvB,yCAAwC;
|
|
1
|
+
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,4DAAuB;AACvB,yCAAwC;AAUxC,SAAS,uBAAuB,CAC9B,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1B,yEAAyE;YACzE,yDAAyD;YACzD,oCAAoC;YACpC,MAAM,MAAC,GAAG,CAAC,SAAS,MAApB,MAAM,OAAoB;gBACxB,GAAG;gBACH,KAAK,EAAE,EAAE;aACV,EAAC;YAEF,oBAAoB;YACpB,MAAM,CAAC,GAAG,CAAC,SAAS,CAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,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,gBAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAjCD,4CAiCC"}
|
package/lib/urlUtils.d.ts
CHANGED
|
@@ -4,17 +4,63 @@
|
|
|
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
|
+
* Much like `path.join`, but much better. Takes an array of URL segments, and
|
|
9
|
+
* joins them into a reasonable URL.
|
|
10
|
+
*
|
|
11
|
+
* - `["file:", "/home", "/user/", "website"]` => `file:///home/user/website`
|
|
12
|
+
* - `["file://", "home", "/user/", "website"]` => `file://home/user/website` (relative!)
|
|
13
|
+
* - Remove trailing slash before parameters or hash.
|
|
14
|
+
* - Replace `?` in query parameters with `&`.
|
|
15
|
+
* - Dedupe forward slashes in the entire path, avoiding protocol slashes.
|
|
16
|
+
*
|
|
17
|
+
* @throws {TypeError} If any of the URL segment is not a string, this throws.
|
|
18
|
+
*/
|
|
7
19
|
export declare function normalizeUrl(rawUrls: string[]): string;
|
|
20
|
+
/**
|
|
21
|
+
* Takes a file's path, relative to its content folder, and computes its edit
|
|
22
|
+
* URL. If `editUrl` is `undefined`, this returns `undefined`, as is the case
|
|
23
|
+
* when the user doesn't want an edit URL in her config.
|
|
24
|
+
*/
|
|
8
25
|
export declare function getEditUrl(fileRelativePath: string, editUrl?: string): string | undefined;
|
|
9
26
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
27
|
+
* Converts file path to a reasonable URL path, e.g. `'index.md'` -> `'/'`,
|
|
28
|
+
* `'foo/bar.js'` -> `'/foo/bar'`
|
|
12
29
|
*/
|
|
13
30
|
export declare function fileToPath(file: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Similar to `encodeURI`, but uses `encodeURIComponent` and assumes there's no
|
|
33
|
+
* query.
|
|
34
|
+
*
|
|
35
|
+
* `encodeURI("/question?/answer")` => `"/question?/answer#section"`;
|
|
36
|
+
* `encodePath("/question?/answer#section")` => `"/question%3F/answer%23foo"`
|
|
37
|
+
*/
|
|
14
38
|
export declare function encodePath(userPath: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Whether `str` is a valid pathname. It must be absolute, and not contain
|
|
41
|
+
* special characters.
|
|
42
|
+
*/
|
|
15
43
|
export declare function isValidPathname(str: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Resolve pathnames and fail-fast if resolution fails. Uses standard URL
|
|
46
|
+
* semantics (provided by `resolve-pathname` which is used internally by React
|
|
47
|
+
* router)
|
|
48
|
+
*/
|
|
16
49
|
export declare function resolvePathname(to: string, from?: string): string;
|
|
50
|
+
/** Appends a leading slash to `str`, if one doesn't exist. */
|
|
17
51
|
export declare function addLeadingSlash(str: string): string;
|
|
52
|
+
/** Appends a trailing slash to `str`, if one doesn't exist. */
|
|
18
53
|
export declare function addTrailingSlash(str: string): string;
|
|
54
|
+
/** Removes the trailing slash from `str`. */
|
|
19
55
|
export declare function removeTrailingSlash(str: string): string;
|
|
56
|
+
/** Constructs an SSH URL that can be used to push to GitHub. */
|
|
57
|
+
export declare function buildSshUrl(githubHost: string, organizationName: string, projectName: string, githubPort?: string): string;
|
|
58
|
+
/** Constructs an HTTP URL that can be used to push to GitHub. */
|
|
59
|
+
export declare function buildHttpsUrl(gitCredentials: string, githubHost: string, organizationName: string, projectName: string, githubPort?: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Whether the current URL is an SSH protocol. In addition to looking for
|
|
62
|
+
* `ssh:`, it will also allow protocol-less URLs like
|
|
63
|
+
* `git@github.com:facebook/docusaurus.git`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function hasSSHProtocol(sourceRepoUrl: string): boolean;
|
|
20
66
|
//# sourceMappingURL=urlUtils.d.ts.map
|
package/lib/urlUtils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlUtils.d.ts","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"urlUtils.d.ts","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAoFtD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,gBAAgB,EAAE,MAAM,EACxB,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,GAAG,SAAS,CAKpB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ/C;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKnD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAWpD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAEjE;AACD,8DAA8D;AAC9D,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEnD;AAGD,+DAA+D;AAC/D,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,6CAA6C;AAC7C,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,gEAAgE;AAChE,wBAAgB,WAAW,CACzB,UAAU,EAAE,MAAM,EAClB,gBAAgB,EAAE,MAAM,EACxB,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,CAKR;AAED,iEAAiE;AACjE,wBAAgB,aAAa,CAC3B,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,gBAAgB,EAAE,MAAM,EACxB,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,CAKR;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAU7D"}
|
package/lib/urlUtils.js
CHANGED
|
@@ -6,15 +6,31 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.removeTrailingSlash = exports.addTrailingSlash = exports.addLeadingSlash = exports.resolvePathname = exports.isValidPathname = exports.encodePath = exports.fileToPath = exports.getEditUrl = exports.normalizeUrl = void 0;
|
|
9
|
+
exports.hasSSHProtocol = exports.buildHttpsUrl = exports.buildSshUrl = exports.removeTrailingSlash = exports.addTrailingSlash = exports.addLeadingSlash = exports.resolvePathname = exports.isValidPathname = exports.encodePath = exports.fileToPath = exports.getEditUrl = exports.normalizeUrl = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const jsUtils_1 = require("./jsUtils");
|
|
12
12
|
const resolve_pathname_1 = tslib_1.__importDefault(require("resolve-pathname"));
|
|
13
|
+
/**
|
|
14
|
+
* Much like `path.join`, but much better. Takes an array of URL segments, and
|
|
15
|
+
* joins them into a reasonable URL.
|
|
16
|
+
*
|
|
17
|
+
* - `["file:", "/home", "/user/", "website"]` => `file:///home/user/website`
|
|
18
|
+
* - `["file://", "home", "/user/", "website"]` => `file://home/user/website` (relative!)
|
|
19
|
+
* - Remove trailing slash before parameters or hash.
|
|
20
|
+
* - Replace `?` in query parameters with `&`.
|
|
21
|
+
* - Dedupe forward slashes in the entire path, avoiding protocol slashes.
|
|
22
|
+
*
|
|
23
|
+
* @throws {TypeError} If any of the URL segment is not a string, this throws.
|
|
24
|
+
*/
|
|
13
25
|
function normalizeUrl(rawUrls) {
|
|
14
26
|
const urls = [...rawUrls];
|
|
15
27
|
const resultArray = [];
|
|
16
28
|
let hasStartingSlash = false;
|
|
17
29
|
let hasEndingSlash = false;
|
|
30
|
+
const isNonEmptyArray = (arr) => arr.length > 0;
|
|
31
|
+
if (!isNonEmptyArray(urls)) {
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
18
34
|
// If the first part is a plain protocol, we combine it with the next part.
|
|
19
35
|
if (urls[0].match(/^[^/:]+:\/*$/) && urls.length > 1) {
|
|
20
36
|
const first = urls.shift();
|
|
@@ -40,13 +56,12 @@ function normalizeUrl(rawUrls) {
|
|
|
40
56
|
if (i === urls.length - 1 && hasEndingSlash) {
|
|
41
57
|
resultArray.push('/');
|
|
42
58
|
}
|
|
43
|
-
// eslint-disable-next-line no-continue
|
|
44
59
|
continue;
|
|
45
60
|
}
|
|
46
61
|
if (component !== '/') {
|
|
47
62
|
if (i > 0) {
|
|
48
63
|
// Removing the starting slashes for each component but the first.
|
|
49
|
-
component = component.replace(
|
|
64
|
+
component = component.replace(/^\/+/,
|
|
50
65
|
// Special case where the first element of rawUrls is empty
|
|
51
66
|
// ["", "/hello"] => /hello
|
|
52
67
|
component[0] === '/' && !hasStartingSlash ? '/' : '');
|
|
@@ -54,14 +69,14 @@ function normalizeUrl(rawUrls) {
|
|
|
54
69
|
hasEndingSlash = component[component.length - 1] === '/';
|
|
55
70
|
// Removing the ending slashes for each component but the last. For the
|
|
56
71
|
// last component we will combine multiple slashes to a single one.
|
|
57
|
-
component = component.replace(
|
|
72
|
+
component = component.replace(/\/+$/, i < urls.length - 1 ? '' : '/');
|
|
58
73
|
}
|
|
59
74
|
hasStartingSlash = true;
|
|
60
75
|
resultArray.push(component);
|
|
61
76
|
}
|
|
62
77
|
let str = resultArray.join('/');
|
|
63
|
-
// Each input component is now separated by a single slash
|
|
64
|
-
//
|
|
78
|
+
// Each input component is now separated by a single slash except the possible
|
|
79
|
+
// first plain protocol part.
|
|
65
80
|
// Remove trailing slash before parameters or hash.
|
|
66
81
|
str = str.replace(/\/(?<search>\?|&|#[^!])/g, '$1');
|
|
67
82
|
// Replace ? in parameters with &.
|
|
@@ -74,6 +89,11 @@ function normalizeUrl(rawUrls) {
|
|
|
74
89
|
return str;
|
|
75
90
|
}
|
|
76
91
|
exports.normalizeUrl = normalizeUrl;
|
|
92
|
+
/**
|
|
93
|
+
* Takes a file's path, relative to its content folder, and computes its edit
|
|
94
|
+
* URL. If `editUrl` is `undefined`, this returns `undefined`, as is the case
|
|
95
|
+
* when the user doesn't want an edit URL in her config.
|
|
96
|
+
*/
|
|
77
97
|
function getEditUrl(fileRelativePath, editUrl) {
|
|
78
98
|
return editUrl
|
|
79
99
|
? // Don't use posixPath for this: we need to force a forward slash path
|
|
@@ -82,8 +102,8 @@ function getEditUrl(fileRelativePath, editUrl) {
|
|
|
82
102
|
}
|
|
83
103
|
exports.getEditUrl = getEditUrl;
|
|
84
104
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
105
|
+
* Converts file path to a reasonable URL path, e.g. `'index.md'` -> `'/'`,
|
|
106
|
+
* `'foo/bar.js'` -> `'/foo/bar'`
|
|
87
107
|
*/
|
|
88
108
|
function fileToPath(file) {
|
|
89
109
|
const indexRE = /(?<dirname>^|.*\/)index\.(?:mdx?|jsx?|tsx?)$/i;
|
|
@@ -94,6 +114,13 @@ function fileToPath(file) {
|
|
|
94
114
|
return `/${file.replace(extRE, '').replace(/\\/g, '/')}`;
|
|
95
115
|
}
|
|
96
116
|
exports.fileToPath = fileToPath;
|
|
117
|
+
/**
|
|
118
|
+
* Similar to `encodeURI`, but uses `encodeURIComponent` and assumes there's no
|
|
119
|
+
* query.
|
|
120
|
+
*
|
|
121
|
+
* `encodeURI("/question?/answer")` => `"/question?/answer#section"`;
|
|
122
|
+
* `encodePath("/question?/answer#section")` => `"/question%3F/answer%23foo"`
|
|
123
|
+
*/
|
|
97
124
|
function encodePath(userPath) {
|
|
98
125
|
return userPath
|
|
99
126
|
.split('/')
|
|
@@ -101,6 +128,10 @@ function encodePath(userPath) {
|
|
|
101
128
|
.join('/');
|
|
102
129
|
}
|
|
103
130
|
exports.encodePath = encodePath;
|
|
131
|
+
/**
|
|
132
|
+
* Whether `str` is a valid pathname. It must be absolute, and not contain
|
|
133
|
+
* special characters.
|
|
134
|
+
*/
|
|
104
135
|
function isValidPathname(str) {
|
|
105
136
|
if (!str.startsWith('/')) {
|
|
106
137
|
return false;
|
|
@@ -115,22 +146,63 @@ function isValidPathname(str) {
|
|
|
115
146
|
}
|
|
116
147
|
}
|
|
117
148
|
exports.isValidPathname = isValidPathname;
|
|
118
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Resolve pathnames and fail-fast if resolution fails. Uses standard URL
|
|
151
|
+
* semantics (provided by `resolve-pathname` which is used internally by React
|
|
152
|
+
* router)
|
|
153
|
+
*/
|
|
119
154
|
function resolvePathname(to, from) {
|
|
120
155
|
return (0, resolve_pathname_1.default)(to, from);
|
|
121
156
|
}
|
|
122
157
|
exports.resolvePathname = resolvePathname;
|
|
158
|
+
/** Appends a leading slash to `str`, if one doesn't exist. */
|
|
123
159
|
function addLeadingSlash(str) {
|
|
124
160
|
return str.startsWith('/') ? str : `/${str}`;
|
|
125
161
|
}
|
|
126
162
|
exports.addLeadingSlash = addLeadingSlash;
|
|
127
163
|
// TODO deduplicate: also present in @docusaurus/utils-common
|
|
164
|
+
/** Appends a trailing slash to `str`, if one doesn't exist. */
|
|
128
165
|
function addTrailingSlash(str) {
|
|
129
166
|
return str.endsWith('/') ? str : `${str}/`;
|
|
130
167
|
}
|
|
131
168
|
exports.addTrailingSlash = addTrailingSlash;
|
|
169
|
+
/** Removes the trailing slash from `str`. */
|
|
132
170
|
function removeTrailingSlash(str) {
|
|
133
171
|
return (0, jsUtils_1.removeSuffix)(str, '/');
|
|
134
172
|
}
|
|
135
173
|
exports.removeTrailingSlash = removeTrailingSlash;
|
|
174
|
+
/** Constructs an SSH URL that can be used to push to GitHub. */
|
|
175
|
+
function buildSshUrl(githubHost, organizationName, projectName, githubPort) {
|
|
176
|
+
if (githubPort) {
|
|
177
|
+
return `ssh://git@${githubHost}:${githubPort}/${organizationName}/${projectName}.git`;
|
|
178
|
+
}
|
|
179
|
+
return `git@${githubHost}:${organizationName}/${projectName}.git`;
|
|
180
|
+
}
|
|
181
|
+
exports.buildSshUrl = buildSshUrl;
|
|
182
|
+
/** Constructs an HTTP URL that can be used to push to GitHub. */
|
|
183
|
+
function buildHttpsUrl(gitCredentials, githubHost, organizationName, projectName, githubPort) {
|
|
184
|
+
if (githubPort) {
|
|
185
|
+
return `https://${gitCredentials}@${githubHost}:${githubPort}/${organizationName}/${projectName}.git`;
|
|
186
|
+
}
|
|
187
|
+
return `https://${gitCredentials}@${githubHost}/${organizationName}/${projectName}.git`;
|
|
188
|
+
}
|
|
189
|
+
exports.buildHttpsUrl = buildHttpsUrl;
|
|
190
|
+
/**
|
|
191
|
+
* Whether the current URL is an SSH protocol. In addition to looking for
|
|
192
|
+
* `ssh:`, it will also allow protocol-less URLs like
|
|
193
|
+
* `git@github.com:facebook/docusaurus.git`.
|
|
194
|
+
*/
|
|
195
|
+
function hasSSHProtocol(sourceRepoUrl) {
|
|
196
|
+
try {
|
|
197
|
+
if (new URL(sourceRepoUrl).protocol === 'ssh:') {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
// Fails when there isn't a protocol
|
|
204
|
+
return /^(?:[\w-]+@)?[\w.-]+:[\w./-]+/.test(sourceRepoUrl);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.hasSSHProtocol = hasSSHProtocol;
|
|
136
208
|
//# sourceMappingURL=urlUtils.js.map
|
package/lib/urlUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlUtils.js","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,uCAAuC;AACvC,gFAAqD;AAErD,SAAgB,YAAY,CAAC,OAAiB;IAC5C,MAAM,IAAI,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;IAC1B,MAAM,WAAW,GAAG,EAAE,CAAC;IAEvB,IAAI,gBAAgB,GAAG,KAAK,CAAC;IAC7B,IAAI,cAAc,GAAG,KAAK,CAAC;IAE3B,2EAA2E;IAC3E,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;QACpD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"urlUtils.js","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,uCAAuC;AACvC,gFAAqD;AAErD;;;;;;;;;;;GAWG;AACH,SAAgB,YAAY,CAAC,OAAiB;IAC5C,MAAM,IAAI,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;IAC1B,MAAM,WAAW,GAAG,EAAE,CAAC;IAEvB,IAAI,gBAAgB,GAAG,KAAK,CAAC;IAC7B,IAAI,cAAc,GAAG,KAAK,CAAC;IAE3B,MAAM,eAAe,GAAG,CAAC,GAAa,EAAgC,EAAE,CACtE,GAAG,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ED,iEAAiE;AACjE,SAAgB,aAAa,CAC3B,cAAsB,EACtB,UAAkB,EAClB,gBAAwB,EACxB,WAAmB,EACnB,UAAmB;IAEnB,IAAI,UAAU,EAAE;QACd,OAAO,WAAW,cAAc,IAAI,UAAU,IAAI,UAAU,IAAI,gBAAgB,IAAI,WAAW,MAAM,CAAC;KACvG;IACD,OAAO,WAAW,cAAc,IAAI,UAAU,IAAI,gBAAgB,IAAI,WAAW,MAAM,CAAC;AAC1F,CAAC;AAXD,sCAWC;AAED;;;;GAIG;AACH,SAAgB,cAAc,CAAC,aAAqB;IAClD,IAAI;QACF,IAAI,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC,QAAQ,KAAK,MAAM,EAAE;YAC9C,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;KACd;IAAC,MAAM;QACN,oCAAoC;QACpC,OAAO,+BAA+B,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;KAC5D;AACH,CAAC;AAVD,wCAUC"}
|
package/lib/webpackUtils.d.ts
CHANGED
|
@@ -25,6 +25,11 @@ declare type FileLoaderUtils = {
|
|
|
25
25
|
otherAssets: () => RuleSetRule;
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* Returns unified loader configurations to be used for various file types.
|
|
30
|
+
*
|
|
31
|
+
* Inspired by https://github.com/gatsbyjs/gatsby/blob/8e6e021014da310b9cc7d02e58c9b3efe938c665/packages/gatsby/src/utils/webpack-utils.ts#L447
|
|
32
|
+
*/
|
|
28
33
|
export declare function getFileLoaderUtils(): FileLoaderUtils;
|
|
29
34
|
export {};
|
|
30
35
|
//# sourceMappingURL=webpackUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpackUtils.d.ts","sourceRoot":"","sources":["../src/webpackUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAQzC,a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WAAW,CAAC;QACzB,GAAG,EAAE,MAAM,WAAW,CAAC;QACvB,WAAW,EAAE,MAAM,WAAW,CAAC;KAChC,CAAC;CACH,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,eAAe,CAmHpD"}
|
package/lib/webpackUtils.js
CHANGED
|
@@ -11,13 +11,17 @@ const tslib_1 = require("tslib");
|
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const pathUtils_1 = require("./pathUtils");
|
|
13
13
|
const constants_1 = require("./constants");
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Returns unified loader configurations to be used for various file types.
|
|
16
|
+
*
|
|
17
|
+
* Inspired by https://github.com/gatsbyjs/gatsby/blob/8e6e021014da310b9cc7d02e58c9b3efe938c665/packages/gatsby/src/utils/webpack-utils.ts#L447
|
|
18
|
+
*/
|
|
15
19
|
function getFileLoaderUtils() {
|
|
16
20
|
// files/images < urlLoaderLimit will be inlined as base64 strings directly in
|
|
17
21
|
// the html
|
|
18
22
|
const urlLoaderLimit = constants_1.WEBPACK_URL_LOADER_LIMIT;
|
|
19
23
|
// defines the path/pattern of the assets handled by webpack
|
|
20
|
-
const fileLoaderFileName = (folder) =>
|
|
24
|
+
const fileLoaderFileName = (folder) => path_1.default.posix.join(constants_1.OUTPUT_STATIC_ASSETS_DIR_NAME, folder, '[name]-[contenthash].[ext]');
|
|
21
25
|
const loaders = {
|
|
22
26
|
file: (options) => ({
|
|
23
27
|
loader: require.resolve(`file-loader`),
|
package/lib/webpackUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpackUtils.js","sourceRoot":"","sources":["../src/webpackUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAGH,wDAAwB;AACxB,2CAAuC;AACvC,2CAGqB;AAoBrB
|
|
1
|
+
{"version":3,"file":"webpackUtils.js","sourceRoot":"","sources":["../src/webpackUtils.ts"],"names":[],"mappings":";AAA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AAC,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,iCAAiC;SACxC,CAAC;KACH,CAAC;IAEF,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,CAAC;AAC1B,CAAC;AAnHD,gDAmHC"}
|
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.18",
|
|
4
4
|
"description": "Node utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,32 +18,32 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "2.0.0-beta.
|
|
22
|
-
"@svgr/webpack": "^6.
|
|
21
|
+
"@docusaurus/logger": "2.0.0-beta.18",
|
|
22
|
+
"@svgr/webpack": "^6.2.1",
|
|
23
23
|
"file-loader": "^6.2.0",
|
|
24
24
|
"fs-extra": "^10.0.1",
|
|
25
25
|
"github-slugger": "^1.4.0",
|
|
26
|
-
"globby": "^11.0
|
|
26
|
+
"globby": "^11.1.0",
|
|
27
27
|
"gray-matter": "^4.0.3",
|
|
28
28
|
"js-yaml": "^4.1.0",
|
|
29
29
|
"lodash": "^4.17.21",
|
|
30
|
-
"micromatch": "^4.0.
|
|
30
|
+
"micromatch": "^4.0.5",
|
|
31
31
|
"resolve-pathname": "^3.0.0",
|
|
32
32
|
"shelljs": "^0.8.5",
|
|
33
33
|
"tslib": "^2.3.1",
|
|
34
34
|
"url-loader": "^4.1.1",
|
|
35
|
-
"webpack": "^5.
|
|
35
|
+
"webpack": "^5.70.0"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": ">=14"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@docusaurus/types": "2.0.0-beta.
|
|
41
|
+
"@docusaurus/types": "2.0.0-beta.18",
|
|
42
42
|
"@types/dedent": "^0.7.0",
|
|
43
43
|
"@types/github-slugger": "^1.3.0",
|
|
44
44
|
"@types/micromatch": "^4.0.2",
|
|
45
|
-
"@types/react-dom": "^17.0.
|
|
45
|
+
"@types/react-dom": "^17.0.14",
|
|
46
46
|
"dedent": "^0.7.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "1a945d06993d53376e61bed2c942799fe07dc336"
|
|
49
49
|
}
|
package/src/constants.ts
CHANGED
|
@@ -5,34 +5,86 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
/** Node major version, directly read from env. */
|
|
8
9
|
export const NODE_MAJOR_VERSION = parseInt(
|
|
9
|
-
process.versions.node.split('.')[0]
|
|
10
|
+
process.versions.node.split('.')[0]!,
|
|
10
11
|
10,
|
|
11
12
|
);
|
|
13
|
+
/** Node minor version, directly read from env. */
|
|
12
14
|
export const NODE_MINOR_VERSION = parseInt(
|
|
13
|
-
process.versions.node.split('.')[1]
|
|
15
|
+
process.versions.node.split('.')[1]!,
|
|
14
16
|
10,
|
|
15
17
|
);
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Can be overridden with cli option `--out-dir`. Code should generally use
|
|
21
|
+
* `context.outDir` instead (which is always absolute and localized).
|
|
22
|
+
*/
|
|
18
23
|
export const DEFAULT_BUILD_DIR_NAME = 'build';
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Can be overridden with cli option `--config`. Code should generally use
|
|
27
|
+
* `context.siteConfigPath` instead (which is always absolute).
|
|
28
|
+
*/
|
|
21
29
|
export const DEFAULT_CONFIG_FILE_NAME = 'docusaurus.config.js';
|
|
22
30
|
|
|
31
|
+
/** Can be absolute or relative to site directory. */
|
|
23
32
|
export const BABEL_CONFIG_FILE_NAME =
|
|
24
|
-
process.env.DOCUSAURUS_BABEL_CONFIG_FILE_NAME
|
|
33
|
+
process.env.DOCUSAURUS_BABEL_CONFIG_FILE_NAME ?? 'babel.config.js';
|
|
25
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Can be absolute or relative to site directory. Code should generally use
|
|
37
|
+
* `context.generatedFilesDir` instead (which is always absolute).
|
|
38
|
+
*/
|
|
26
39
|
export const GENERATED_FILES_DIR_NAME =
|
|
27
|
-
process.env.DOCUSAURUS_GENERATED_FILES_DIR_NAME
|
|
40
|
+
process.env.DOCUSAURUS_GENERATED_FILES_DIR_NAME ?? '.docusaurus';
|
|
28
41
|
|
|
42
|
+
/**
|
|
43
|
+
* We would assume all of the site's JS code lives in here and not outside.
|
|
44
|
+
* Relative to the site directory.
|
|
45
|
+
*/
|
|
29
46
|
export const SRC_DIR_NAME = 'src';
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Can be overridden with `config.staticDirectories`. Code should use
|
|
50
|
+
* `context.siteConfig.staticDirectories` instead (which is always absolute).
|
|
51
|
+
*/
|
|
52
|
+
export const DEFAULT_STATIC_DIR_NAME = 'static';
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Files here are handled by webpack, hashed (can be cached aggressively).
|
|
56
|
+
* Relative to the build output folder.
|
|
57
|
+
*/
|
|
58
|
+
export const OUTPUT_STATIC_ASSETS_DIR_NAME = 'assets';
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Components in this directory will receive the `@theme` alias and be able to
|
|
62
|
+
* shadow default theme components.
|
|
63
|
+
*/
|
|
32
64
|
export const THEME_PATH = `${SRC_DIR_NAME}/theme`;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* All translation-related data live here, relative to site directory. Content
|
|
68
|
+
* will be namespaced by locale.
|
|
69
|
+
*/
|
|
70
|
+
export const I18N_DIR_NAME = 'i18n';
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Translations for React code.
|
|
74
|
+
*/
|
|
75
|
+
export const CODE_TRANSLATIONS_FILE_NAME = 'code.json';
|
|
76
|
+
|
|
77
|
+
/** Dev server opens on this port by default. */
|
|
33
78
|
export const DEFAULT_PORT = 3000;
|
|
79
|
+
|
|
80
|
+
/** Default plugin ID. */
|
|
34
81
|
export const DEFAULT_PLUGIN_ID = 'default';
|
|
35
82
|
|
|
36
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Allow overriding the limit after which the url loader will no longer inline
|
|
85
|
+
* assets.
|
|
86
|
+
*
|
|
87
|
+
* @see https://github.com/facebook/docusaurus/issues/5493
|
|
88
|
+
*/
|
|
37
89
|
export const WEBPACK_URL_LOADER_LIMIT =
|
|
38
90
|
process.env.WEBPACK_URL_LOADER_LIMIT ?? 10000;
|