@docusaurus/utils 3.3.2 → 3.5.0
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/cliUtils.js +1 -2
- package/lib/cliUtils.js.map +1 -1
- package/lib/contentVisibilityUtils.js +2 -3
- package/lib/contentVisibilityUtils.js.map +1 -1
- package/lib/dataFileUtils.d.ts +6 -7
- package/lib/dataFileUtils.d.ts.map +1 -1
- package/lib/dataFileUtils.js +14 -14
- package/lib/dataFileUtils.js.map +1 -1
- package/lib/emitUtils.d.ts +0 -1
- package/lib/emitUtils.d.ts.map +1 -1
- package/lib/emitUtils.js +2 -3
- package/lib/emitUtils.js.map +1 -1
- package/lib/gitUtils.js +2 -2
- package/lib/gitUtils.js.map +1 -1
- package/lib/globUtils.js +3 -3
- package/lib/globUtils.js.map +1 -1
- package/lib/hashUtils.d.ts +4 -1
- package/lib/hashUtils.d.ts.map +1 -1
- package/lib/hashUtils.js +12 -7
- package/lib/hashUtils.js.map +1 -1
- package/lib/i18nUtils.js +4 -5
- package/lib/i18nUtils.js.map +1 -1
- package/lib/index.d.ts +5 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +10 -5
- package/lib/index.js.map +1 -1
- package/lib/jsUtils.js +2 -3
- package/lib/jsUtils.js.map +1 -1
- package/lib/lastUpdateUtils.js +4 -4
- package/lib/lastUpdateUtils.js.map +1 -1
- package/lib/markdownLinks.d.ts +7 -34
- package/lib/markdownLinks.d.ts.map +1 -1
- package/lib/markdownLinks.js +21 -104
- package/lib/markdownLinks.js.map +1 -1
- package/lib/markdownUtils.js +12 -12
- package/lib/markdownUtils.js.map +1 -1
- package/lib/moduleUtils.js +1 -2
- package/lib/moduleUtils.js.map +1 -1
- package/lib/pathUtils.js +8 -8
- package/lib/pathUtils.js.map +1 -1
- package/lib/regExpUtils.js +1 -2
- package/lib/regExpUtils.js.map +1 -1
- package/lib/routeUtils.js +1 -2
- package/lib/routeUtils.js.map +1 -1
- package/lib/shellUtils.js +1 -2
- package/lib/shellUtils.js.map +1 -1
- package/lib/slugger.js +1 -2
- package/lib/slugger.js.map +1 -1
- package/lib/tags.d.ts +35 -18
- package/lib/tags.d.ts.map +1 -1
- package/lib/tags.js +58 -30
- package/lib/tags.js.map +1 -1
- package/lib/urlUtils.d.ts +14 -0
- package/lib/urlUtils.d.ts.map +1 -1
- package/lib/urlUtils.js +76 -30
- package/lib/urlUtils.js.map +1 -1
- package/lib/webpackUtils.js +2 -3
- package/lib/webpackUtils.js.map +1 -1
- package/package.json +6 -5
- package/src/dataFileUtils.ts +12 -14
- package/src/hashUtils.ts +20 -3
- package/src/index.ts +12 -4
- package/src/markdownLinks.ts +32 -151
- package/src/markdownUtils.ts +2 -2
- package/src/tags.ts +122 -36
- package/src/urlUtils.ts +76 -22
package/lib/tags.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,
|
|
1
|
+
{"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AAE5C,MAAM,MAAM,GAAG,GAAG;IAChB,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,SAAS,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;AAEhE,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAG3C,MAAM,MAAM,iBAAiB,GAAG;IAE9B,6BAA6B;IAC7B,IAAI,EAAE,MAAM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MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,iBAAiB,CAAC;CAC5B,GAAG,IAAI,CAcP;AAED,KAAK,eAAe,CAAC,IAAI,IAAI;IAC3B,GAAG,EAAE,WAAW,CAAC;IACjB,KAAK,EAAE,IAAI,EAAE,CAAC;CACf,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EACnC,KAAK,EAAE,SAAS,IAAI,EAAE;AACtB;;;GAGG;AACH,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,SAAS,WAAW,EAAE,GAClD;IAAC,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,CAAA;CAAC,CA0B9C;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,EACrC,KAAK,EACL,UAAU,GACX,EAAE;IACD,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;CACrC,GAAG;IACF,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,IAAI,EAAE,CAAC;CACrB,CAaA"}
|
package/lib/tags.js
CHANGED
|
@@ -6,50 +6,80 @@
|
|
|
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.normalizeTag = normalizeTag;
|
|
10
|
+
exports.normalizeTags = normalizeTags;
|
|
11
|
+
exports.reportInlineTags = reportInlineTags;
|
|
12
|
+
exports.groupTaggedItems = groupTaggedItems;
|
|
13
|
+
exports.getTagVisibility = getTagVisibility;
|
|
10
14
|
const tslib_1 = require("tslib");
|
|
11
15
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
16
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
17
|
const urlUtils_1 = require("./urlUtils");
|
|
13
|
-
|
|
18
|
+
// We always apply tagsBaseRoutePath on purpose. For versioned docs, v1/doc.md
|
|
19
|
+
// and v2/doc.md tags with custom permalinks don't lead to the same created
|
|
20
|
+
// page. tagsBaseRoutePath is different for each doc version
|
|
21
|
+
function normalizeTagPermalink({ tagsBaseRoutePath, permalink, }) {
|
|
22
|
+
return (0, urlUtils_1.normalizeUrl)([tagsBaseRoutePath, permalink]);
|
|
23
|
+
}
|
|
24
|
+
function normalizeInlineTag(tagsBaseRoutePath, frontMatterTag) {
|
|
14
25
|
function toTagObject(tagString) {
|
|
15
26
|
return {
|
|
27
|
+
inline: true,
|
|
16
28
|
label: tagString,
|
|
17
29
|
permalink: lodash_1.default.kebabCase(tagString),
|
|
30
|
+
description: undefined,
|
|
18
31
|
};
|
|
19
32
|
}
|
|
20
|
-
// TODO maybe make ensure the permalink is valid url path?
|
|
21
|
-
function normalizeTagPermalink(permalink) {
|
|
22
|
-
// Note: we always apply tagsPath on purpose. For versioned docs, v1/doc.md
|
|
23
|
-
// and v2/doc.md tags with custom permalinks don't lead to the same created
|
|
24
|
-
// page. tagsPath is different for each doc version
|
|
25
|
-
return (0, urlUtils_1.normalizeUrl)([tagsPath, permalink]);
|
|
26
|
-
}
|
|
27
33
|
const tag = typeof frontMatterTag === 'string'
|
|
28
34
|
? toTagObject(frontMatterTag)
|
|
29
|
-
: frontMatterTag;
|
|
35
|
+
: { ...frontMatterTag, description: frontMatterTag.description };
|
|
30
36
|
return {
|
|
37
|
+
inline: true,
|
|
31
38
|
label: tag.label,
|
|
32
|
-
permalink: normalizeTagPermalink(
|
|
39
|
+
permalink: normalizeTagPermalink({
|
|
40
|
+
permalink: tag.permalink,
|
|
41
|
+
tagsBaseRoutePath,
|
|
42
|
+
}),
|
|
43
|
+
description: tag.description,
|
|
33
44
|
};
|
|
34
45
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
function normalizeTag({ tag, tagsFile, tagsBaseRoutePath, }) {
|
|
47
|
+
if (typeof tag === 'string') {
|
|
48
|
+
const tagDescription = tagsFile?.[tag];
|
|
49
|
+
if (tagDescription) {
|
|
50
|
+
// pre-defined tag from tags.yml
|
|
51
|
+
return {
|
|
52
|
+
inline: false,
|
|
53
|
+
label: tagDescription.label,
|
|
54
|
+
permalink: normalizeTagPermalink({
|
|
55
|
+
permalink: tagDescription.permalink,
|
|
56
|
+
tagsBaseRoutePath,
|
|
57
|
+
}),
|
|
58
|
+
description: tagDescription.description,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// legacy inline tag object, always inline, unknown because isn't a string
|
|
63
|
+
return normalizeInlineTag(tagsBaseRoutePath, tag);
|
|
64
|
+
}
|
|
65
|
+
function normalizeTags({ options, source, frontMatterTags, tagsBaseRoutePath, tagsFile, }) {
|
|
66
|
+
const tags = (frontMatterTags ?? []).map((tag) => normalizeTag({ tag, tagsBaseRoutePath, tagsFile }));
|
|
67
|
+
if (tagsFile !== null) {
|
|
68
|
+
reportInlineTags({ tags, source, options });
|
|
69
|
+
}
|
|
70
|
+
return tags;
|
|
71
|
+
}
|
|
72
|
+
function reportInlineTags({ tags, source, options, }) {
|
|
73
|
+
if (options.onInlineTags === 'ignore') {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const inlineTags = tags.filter((tag) => tag.inline);
|
|
77
|
+
if (inlineTags.length > 0) {
|
|
78
|
+
const uniqueUnknownTags = [...new Set(inlineTags.map((tag) => tag.label))];
|
|
79
|
+
const tagListString = uniqueUnknownTags.join(', ');
|
|
80
|
+
logger_1.default.report(options.onInlineTags)(`Tags [${tagListString}] used in ${source} are not defined in ${options.tags ?? 'tags.yml'}`);
|
|
81
|
+
}
|
|
51
82
|
}
|
|
52
|
-
exports.normalizeFrontMatterTags = normalizeFrontMatterTags;
|
|
53
83
|
/**
|
|
54
84
|
* Permits to group docs/blog posts by tag (provided by front matter).
|
|
55
85
|
*
|
|
@@ -87,7 +117,6 @@ getItemTags) {
|
|
|
87
117
|
});
|
|
88
118
|
return result;
|
|
89
119
|
}
|
|
90
|
-
exports.groupTaggedItems = groupTaggedItems;
|
|
91
120
|
/**
|
|
92
121
|
* Permits to get the "tag visibility" (hard to find a better name)
|
|
93
122
|
* IE, is this tag listed or unlisted
|
|
@@ -107,5 +136,4 @@ function getTagVisibility({ items, isUnlisted, }) {
|
|
|
107
136
|
listedItems: items.filter((item) => !isUnlisted(item)),
|
|
108
137
|
};
|
|
109
138
|
}
|
|
110
|
-
exports.getTagVisibility = getTagVisibility;
|
|
111
139
|
//# sourceMappingURL=tags.js.map
|
package/lib/tags.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":";AAAA;;;;;GAKG
|
|
1
|
+
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AA4FH,oCA0BC;AAED,sCAoBC;AAED,4CAsBC;AAeD,4CAiCC;AAOD,4CAsBC;;AA/OD,4DAAuB;AACvB,wEAAwC;AACxC,yCAAwC;AA8CxC,8EAA8E;AAC9E,2EAA2E;AAC3E,4DAA4D;AAC5D,SAAS,qBAAqB,CAAC,EAC7B,iBAAiB,EACjB,SAAS,GAIV;IACC,OAAO,IAAA,uBAAY,EAAC,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,kBAAkB,CACzB,iBAAyB,EACzB,cAA8B;IAE9B,SAAS,WAAW,CAAC,SAAiB;QACpC,OAAO;YACL,MAAM,EAAE,IAAI;YACZ,KAAK,EAAE,SAAS;YAChB,SAAS,EAAE,gBAAC,CAAC,SAAS,CAAC,SA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AC,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;AAED;;;;GAIG;AACH,SAAgB,gBAAgB,CAAO,EACrC,KAAK,EACL,UAAU,GAIX;IAIC,MAAM,gBAAgB,GAAG,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACjD,iEAAiE;IACjE,uDAAuD;IACvD,IAAI,gBAAgB,EAAE,CAAC;QACrB,OAAO,EAAC,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAC,CAAC;IAC9C,CAAC;IACD,2DAA2D;IAC3D,mCAAmC;IACnC,OAAO;QACL,QAAQ,EAAE,KAAK;QACf,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;KACvD,CAAC;AACJ,CAAC"}
|
package/lib/urlUtils.d.ts
CHANGED
|
@@ -41,12 +41,26 @@ export declare function encodePath(userPath: string): string;
|
|
|
41
41
|
* special characters.
|
|
42
42
|
*/
|
|
43
43
|
export declare function isValidPathname(str: string): boolean;
|
|
44
|
+
export declare function parseURLOrPath(url: string, base?: string | URL): URL;
|
|
44
45
|
export type URLPath = {
|
|
45
46
|
pathname: string;
|
|
46
47
|
search?: string;
|
|
47
48
|
hash?: string;
|
|
48
49
|
};
|
|
50
|
+
export declare function toURLPath(url: URL): URLPath;
|
|
51
|
+
/**
|
|
52
|
+
* Let's name the concept of (pathname + search + hash) as URLPath
|
|
53
|
+
* See also https://twitter.com/kettanaito/status/1741768992866308120
|
|
54
|
+
* Note: this function also resolves relative pathnames while parsing!
|
|
55
|
+
*/
|
|
49
56
|
export declare function parseURLPath(urlPath: string, fromPath?: string): URLPath;
|
|
57
|
+
/**
|
|
58
|
+
* This returns results for strings like "foo", "../foo", "./foo.mdx?qs#hash"
|
|
59
|
+
* Unlike "parseURLPath()" above, this will not resolve the pathnames
|
|
60
|
+
* Te returned pathname of "../../foo.mdx" will be "../../foo.mdx", not "/foo"
|
|
61
|
+
* This returns null if the url is not "local" (contains domain/protocol etc)
|
|
62
|
+
*/
|
|
63
|
+
export declare function parseLocalURLPath(urlPath: string): URLPath | null;
|
|
50
64
|
export declare function serializeURLPath(urlPath: URLPath): string;
|
|
51
65
|
/**
|
|
52
66
|
* Resolve pathnames and fail-fast if resolution fails. Uses standard URL
|
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;AAIH;;;;;;;;;;;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,G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AAI,CAwCjE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAIzD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAIjE;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,7 +6,20 @@
|
|
|
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.normalizeUrl = normalizeUrl;
|
|
10
|
+
exports.getEditUrl = getEditUrl;
|
|
11
|
+
exports.fileToPath = fileToPath;
|
|
12
|
+
exports.encodePath = encodePath;
|
|
13
|
+
exports.isValidPathname = isValidPathname;
|
|
14
|
+
exports.parseURLOrPath = parseURLOrPath;
|
|
15
|
+
exports.toURLPath = toURLPath;
|
|
16
|
+
exports.parseURLPath = parseURLPath;
|
|
17
|
+
exports.parseLocalURLPath = parseLocalURLPath;
|
|
18
|
+
exports.serializeURLPath = serializeURLPath;
|
|
19
|
+
exports.resolvePathname = resolvePathname;
|
|
20
|
+
exports.buildSshUrl = buildSshUrl;
|
|
21
|
+
exports.buildHttpsUrl = buildHttpsUrl;
|
|
22
|
+
exports.hasSSHProtocol = hasSSHProtocol;
|
|
10
23
|
const tslib_1 = require("tslib");
|
|
11
24
|
const resolve_pathname_1 = tslib_1.__importDefault(require("resolve-pathname"));
|
|
12
25
|
/**
|
|
@@ -77,7 +90,7 @@ function normalizeUrl(rawUrls) {
|
|
|
77
90
|
// Each input component is now separated by a single slash except the possible
|
|
78
91
|
// first plain protocol part.
|
|
79
92
|
// Remove trailing slash before parameters or hash.
|
|
80
|
-
str = str.replace(/\/(?<search>\?|&|#[
|
|
93
|
+
str = str.replace(/\/(?<search>\?|&|#[^!/])/g, '$1');
|
|
81
94
|
// Replace ? in parameters with &.
|
|
82
95
|
const parts = str.split('?');
|
|
83
96
|
str = parts.shift() + (parts.length > 0 ? '?' : '') + parts.join('&');
|
|
@@ -87,7 +100,6 @@ function normalizeUrl(rawUrls) {
|
|
|
87
100
|
str = str.replace(/^\/+/g, '/');
|
|
88
101
|
return str;
|
|
89
102
|
}
|
|
90
|
-
exports.normalizeUrl = normalizeUrl;
|
|
91
103
|
/**
|
|
92
104
|
* Takes a file's path, relative to its content folder, and computes its edit
|
|
93
105
|
* URL. If `editUrl` is `undefined`, this returns `undefined`, as is the case
|
|
@@ -99,7 +111,6 @@ function getEditUrl(fileRelativePath, editUrl) {
|
|
|
99
111
|
normalizeUrl([editUrl, fileRelativePath.replace(/\\/g, '/')])
|
|
100
112
|
: undefined;
|
|
101
113
|
}
|
|
102
|
-
exports.getEditUrl = getEditUrl;
|
|
103
114
|
/**
|
|
104
115
|
* Converts file path to a reasonable URL path, e.g. `'index.md'` -> `'/'`,
|
|
105
116
|
* `'foo/bar.js'` -> `'/foo/bar'`
|
|
@@ -112,7 +123,6 @@ function fileToPath(file) {
|
|
|
112
123
|
}
|
|
113
124
|
return `/${file.replace(extRE, '').replace(/\\/g, '/')}`;
|
|
114
125
|
}
|
|
115
|
-
exports.fileToPath = fileToPath;
|
|
116
126
|
/**
|
|
117
127
|
* Similar to `encodeURI`, but uses `encodeURIComponent` and assumes there's no
|
|
118
128
|
* query.
|
|
@@ -126,7 +136,6 @@ function encodePath(userPath) {
|
|
|
126
136
|
.map((item) => encodeURIComponent(item))
|
|
127
137
|
.join('/');
|
|
128
138
|
}
|
|
129
|
-
exports.encodePath = encodePath;
|
|
130
139
|
/**
|
|
131
140
|
* Whether `str` is a valid pathname. It must be absolute, and not contain
|
|
132
141
|
* special characters.
|
|
@@ -143,22 +152,17 @@ function isValidPathname(str) {
|
|
|
143
152
|
return false;
|
|
144
153
|
}
|
|
145
154
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
//
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return new URL(url, base ?? 'https://example.com');
|
|
155
|
-
}
|
|
156
|
-
catch (e) {
|
|
157
|
-
throw new Error(`Can't parse URL ${url}${base ? ` with base ${base}` : ''}`, { cause: e });
|
|
158
|
-
}
|
|
155
|
+
function parseURLOrPath(url, base) {
|
|
156
|
+
try {
|
|
157
|
+
// TODO when Node supports it, use URL.parse could be faster?
|
|
158
|
+
// see https://kilianvalkhof.com/2024/javascript/the-problem-with-new-url-and-how-url-parse-fixes-that/
|
|
159
|
+
return new URL(url, base ?? 'https://example.com');
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
throw new Error(`Can't parse URL ${url}${base ? ` with base ${base}` : ''}`, { cause: e });
|
|
159
163
|
}
|
|
160
|
-
|
|
161
|
-
|
|
164
|
+
}
|
|
165
|
+
function toURLPath(url) {
|
|
162
166
|
const { pathname } = url;
|
|
163
167
|
// Fixes annoying url.search behavior
|
|
164
168
|
// "" => undefined
|
|
@@ -166,16 +170,16 @@ function parseURLPath(urlPath, fromPath) {
|
|
|
166
170
|
// "?param => "param"
|
|
167
171
|
const search = url.search
|
|
168
172
|
? url.search.slice(1)
|
|
169
|
-
:
|
|
173
|
+
: url.href.includes('?')
|
|
170
174
|
? ''
|
|
171
175
|
: undefined;
|
|
172
176
|
// Fixes annoying url.hash behavior
|
|
173
177
|
// "" => undefined
|
|
174
178
|
// "#" => ""
|
|
175
|
-
// "
|
|
179
|
+
// "#param => "param"
|
|
176
180
|
const hash = url.hash
|
|
177
181
|
? url.hash.slice(1)
|
|
178
|
-
:
|
|
182
|
+
: url.href.includes('#')
|
|
179
183
|
? ''
|
|
180
184
|
: undefined;
|
|
181
185
|
return {
|
|
@@ -184,13 +188,59 @@ function parseURLPath(urlPath, fromPath) {
|
|
|
184
188
|
hash,
|
|
185
189
|
};
|
|
186
190
|
}
|
|
187
|
-
|
|
191
|
+
/**
|
|
192
|
+
* Let's name the concept of (pathname + search + hash) as URLPath
|
|
193
|
+
* See also https://twitter.com/kettanaito/status/1741768992866308120
|
|
194
|
+
* Note: this function also resolves relative pathnames while parsing!
|
|
195
|
+
*/
|
|
196
|
+
function parseURLPath(urlPath, fromPath) {
|
|
197
|
+
const base = fromPath ? parseURLOrPath(fromPath) : undefined;
|
|
198
|
+
const url = parseURLOrPath(urlPath, base);
|
|
199
|
+
return toURLPath(url);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* This returns results for strings like "foo", "../foo", "./foo.mdx?qs#hash"
|
|
203
|
+
* Unlike "parseURLPath()" above, this will not resolve the pathnames
|
|
204
|
+
* Te returned pathname of "../../foo.mdx" will be "../../foo.mdx", not "/foo"
|
|
205
|
+
* This returns null if the url is not "local" (contains domain/protocol etc)
|
|
206
|
+
*/
|
|
207
|
+
function parseLocalURLPath(urlPath) {
|
|
208
|
+
// Workaround because URL("") requires a protocol
|
|
209
|
+
const unspecifiedProtocol = 'unspecified:';
|
|
210
|
+
const url = parseURLOrPath(urlPath, `${unspecifiedProtocol}//`);
|
|
211
|
+
// Ignore links with specified protocol / host
|
|
212
|
+
// (usually fully qualified links starting with https://)
|
|
213
|
+
if (url.protocol !== unspecifiedProtocol ||
|
|
214
|
+
url.host !== '' ||
|
|
215
|
+
url.username !== '' ||
|
|
216
|
+
url.password !== '') {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
// We can't use "new URL()" result because it always tries to resolve urls
|
|
220
|
+
// IE it will remove any "./" or "../" in the pathname, which we don't want
|
|
221
|
+
// We have to parse it manually...
|
|
222
|
+
let localUrlPath = urlPath;
|
|
223
|
+
// Extract and remove the #hash part
|
|
224
|
+
const hashIndex = localUrlPath.indexOf('#');
|
|
225
|
+
const hash = hashIndex !== -1 ? localUrlPath.substring(hashIndex + 1) : undefined;
|
|
226
|
+
localUrlPath =
|
|
227
|
+
hashIndex !== -1 ? localUrlPath.substring(0, hashIndex) : localUrlPath;
|
|
228
|
+
// Extract and remove ?search part
|
|
229
|
+
const searchIndex = localUrlPath.indexOf('?');
|
|
230
|
+
const search = searchIndex !== -1 ? localUrlPath.substring(searchIndex + 1) : undefined;
|
|
231
|
+
localUrlPath =
|
|
232
|
+
searchIndex !== -1 ? localUrlPath.substring(0, searchIndex) : localUrlPath;
|
|
233
|
+
return {
|
|
234
|
+
pathname: localUrlPath,
|
|
235
|
+
search,
|
|
236
|
+
hash,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
188
239
|
function serializeURLPath(urlPath) {
|
|
189
240
|
const search = urlPath.search === undefined ? '' : `?${urlPath.search}`;
|
|
190
241
|
const hash = urlPath.hash === undefined ? '' : `#${urlPath.hash}`;
|
|
191
242
|
return `${urlPath.pathname}${search}${hash}`;
|
|
192
243
|
}
|
|
193
|
-
exports.serializeURLPath = serializeURLPath;
|
|
194
244
|
/**
|
|
195
245
|
* Resolve pathnames and fail-fast if resolution fails. Uses standard URL
|
|
196
246
|
* semantics (provided by `resolve-pathname` which is used internally by React
|
|
@@ -201,7 +251,6 @@ function resolvePathname(to, from) {
|
|
|
201
251
|
// possible alternative: decodeURI(parseURLPath(to, from).pathname);
|
|
202
252
|
return (0, resolve_pathname_1.default)(to, from);
|
|
203
253
|
}
|
|
204
|
-
exports.resolvePathname = resolvePathname;
|
|
205
254
|
/** Constructs an SSH URL that can be used to push to GitHub. */
|
|
206
255
|
function buildSshUrl(githubHost, organizationName, projectName, githubPort) {
|
|
207
256
|
if (githubPort) {
|
|
@@ -209,7 +258,6 @@ function buildSshUrl(githubHost, organizationName, projectName, githubPort) {
|
|
|
209
258
|
}
|
|
210
259
|
return `git@${githubHost}:${organizationName}/${projectName}.git`;
|
|
211
260
|
}
|
|
212
|
-
exports.buildSshUrl = buildSshUrl;
|
|
213
261
|
/** Constructs an HTTP URL that can be used to push to GitHub. */
|
|
214
262
|
function buildHttpsUrl(gitCredentials, githubHost, organizationName, projectName, githubPort) {
|
|
215
263
|
if (githubPort) {
|
|
@@ -217,7 +265,6 @@ function buildHttpsUrl(gitCredentials, githubHost, organizationName, projectName
|
|
|
217
265
|
}
|
|
218
266
|
return `https://${gitCredentials}@${githubHost}/${organizationName}/${projectName}.git`;
|
|
219
267
|
}
|
|
220
|
-
exports.buildHttpsUrl = buildHttpsUrl;
|
|
221
268
|
/**
|
|
222
269
|
* Whether the current URL is an SSH protocol. In addition to looking for
|
|
223
270
|
* `ssh:`, it will also allow protocol-less URLs like
|
|
@@ -235,5 +282,4 @@ function hasSSHProtocol(sourceRepoUrl) {
|
|
|
235
282
|
return /^(?:[\w-]+@)?[\w.-]+:[\w./-]+/.test(sourceRepoUrl);
|
|
236
283
|
}
|
|
237
284
|
}
|
|
238
|
-
exports.hasSSHProtocol = hasSSHProtocol;
|
|
239
285
|
//# 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
|
|
1
|
+
{"version":3,"file":"urlUtils.js","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAgBH,oCAoFC;AAOD,gCAQC;AAMD,gCAQC;AASD,gCAKC;AAMD,0CAUC;AAED,wCAWC;AAID,8BA4BC;AAOD,oCAIC;AAQD,8CAwCC;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6,7 +6,8 @@
|
|
|
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.getWebpackLoaderCompilerName = getWebpackLoaderCompilerName;
|
|
10
|
+
exports.getFileLoaderUtils = getFileLoaderUtils;
|
|
10
11
|
const tslib_1 = require("tslib");
|
|
11
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
13
|
const pathUtils_1 = require("./pathUtils");
|
|
@@ -22,7 +23,6 @@ function getWebpackLoaderCompilerName(context) {
|
|
|
22
23
|
throw new Error(`Cannot get valid Docusaurus webpack compiler name. Found compilerName=${compilerName}`);
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
exports.getWebpackLoaderCompilerName = getWebpackLoaderCompilerName;
|
|
26
26
|
/**
|
|
27
27
|
* Returns unified loader configurations to be used for various file types.
|
|
28
28
|
*
|
|
@@ -124,5 +124,4 @@ function getFileLoaderUtils() {
|
|
|
124
124
|
};
|
|
125
125
|
return { loaders, rules };
|
|
126
126
|
}
|
|
127
|
-
exports.getFileLoaderUtils = getFileLoaderUtils;
|
|
128
127
|
//# sourceMappingURL=webpackUtils.js.map
|
package/lib/webpackUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpackUtils.js","sourceRoot":"","sources":["../src/webpackUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG
|
|
1
|
+
{"version":3,"file":"webpackUtils.js","sourceRoot":"","sources":["../src/webpackUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAYH,oEAcC;AA0BD,gDAqHC;;AAvKD,wDAAwB;AACxB,2CAAuC;AACvC,2CAGqB;AAKrB,SAAgB,4BAA4B,CAC1C,OAA+B;IAE/B,gDAAgD;IAChD,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC;IAC7C,QAAQ,YAAY,EAAE,CAA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E,IAAI;gCACf,GAAG,EAAE,CAAC,CAAC,cAAI,CAAC;6BACb;yBACF;qBACF;oBACD,6DAA6D;oBAC7D,gDAAgD;oBAChD,MAAM,EAAE;wBACN,GAAG,EAAE,CAAC,wBAAwB,CAAC;qBAChC;iBACF;gBACD;oBACE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAC,MAAM,EAAE,QAAQ,EAAC,CAAC,CAAC;iBACvC;aACF;SACF,CAAC;QAEF,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC;YAClB,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC,CAAC;YACtC,IAAI,EAAE,iCAAiC;SACxC,CAAC;KACH,CAAC;IAEF,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,CAAC;AAC1B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Node utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "3.
|
|
22
|
-
"@docusaurus/utils-common": "3.
|
|
21
|
+
"@docusaurus/logger": "3.5.0",
|
|
22
|
+
"@docusaurus/utils-common": "3.5.0",
|
|
23
23
|
"@svgr/webpack": "^8.1.0",
|
|
24
24
|
"escape-string-regexp": "^4.0.0",
|
|
25
25
|
"file-loader": "^6.2.0",
|
|
@@ -36,13 +36,14 @@
|
|
|
36
36
|
"shelljs": "^0.8.5",
|
|
37
37
|
"tslib": "^2.6.0",
|
|
38
38
|
"url-loader": "^4.1.1",
|
|
39
|
+
"utility-types": "^3.10.0",
|
|
39
40
|
"webpack": "^5.88.1"
|
|
40
41
|
},
|
|
41
42
|
"engines": {
|
|
42
43
|
"node": ">=18.0"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
|
-
"@docusaurus/types": "3.
|
|
46
|
+
"@docusaurus/types": "3.5.0",
|
|
46
47
|
"@types/dedent": "^0.7.0",
|
|
47
48
|
"@types/github-slugger": "^1.3.0",
|
|
48
49
|
"@types/micromatch": "^4.0.2",
|
|
@@ -58,5 +59,5 @@
|
|
|
58
59
|
"optional": true
|
|
59
60
|
}
|
|
60
61
|
},
|
|
61
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "cb5829f3c34b26d798b869e38ee25073488140bd"
|
|
62
63
|
}
|
package/src/dataFileUtils.ts
CHANGED
|
@@ -43,30 +43,28 @@ export async function getDataFilePath({
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* Looks up for a data file in the content paths
|
|
47
|
-
*
|
|
46
|
+
* Looks up for a data file in the content paths
|
|
47
|
+
* Favors the localized content path over the base content path
|
|
48
|
+
* Currently supports Yaml and JSON data files
|
|
49
|
+
* It is the caller responsibility to validate and normalize the resulting data
|
|
48
50
|
*
|
|
49
51
|
* @returns `undefined` when file not found
|
|
50
|
-
* @throws Throws when
|
|
52
|
+
* @throws Throws when data file can't be parsed
|
|
51
53
|
*/
|
|
52
|
-
export async function
|
|
53
|
-
params: DataFileParams & {
|
|
54
|
-
/** Used for the "The X file looks invalid" message. */
|
|
55
|
-
fileType: string;
|
|
56
|
-
},
|
|
57
|
-
validate: (content: unknown) => T,
|
|
58
|
-
): Promise<T | undefined> {
|
|
54
|
+
export async function readDataFile(params: DataFileParams): Promise<unknown> {
|
|
59
55
|
const filePath = await getDataFilePath(params);
|
|
60
56
|
if (!filePath) {
|
|
61
57
|
return undefined;
|
|
62
58
|
}
|
|
63
59
|
try {
|
|
64
60
|
const contentString = await fs.readFile(filePath, {encoding: 'utf8'});
|
|
65
|
-
|
|
66
|
-
return validate(unsafeContent);
|
|
61
|
+
return Yaml.load(contentString);
|
|
67
62
|
} catch (err) {
|
|
68
|
-
logger.
|
|
69
|
-
|
|
63
|
+
const msg = logger.interpolate`The file at path=${path.relative(
|
|
64
|
+
process.cwd(),
|
|
65
|
+
filePath,
|
|
66
|
+
)} looks invalid (not Yaml nor JSON).`;
|
|
67
|
+
throw new Error(msg, {cause: err as Error});
|
|
70
68
|
}
|
|
71
69
|
}
|
|
72
70
|
|
package/src/hashUtils.ts
CHANGED
|
@@ -25,11 +25,28 @@ export function simpleHash(str: string, length: number): string {
|
|
|
25
25
|
* collision. Also removes part of the string if its larger than the allowed
|
|
26
26
|
* filename per OS, avoiding `ERRNAMETOOLONG` error.
|
|
27
27
|
*/
|
|
28
|
-
export function docuHash(
|
|
29
|
-
|
|
28
|
+
export function docuHash(
|
|
29
|
+
strInput: string,
|
|
30
|
+
options?: {
|
|
31
|
+
// String that contributes to the hash value
|
|
32
|
+
// but does not contribute to the returned string
|
|
33
|
+
hashExtra?: string;
|
|
34
|
+
// Length of the hash to append
|
|
35
|
+
hashLength?: number;
|
|
36
|
+
},
|
|
37
|
+
): string {
|
|
38
|
+
// TODO check this historical behavior
|
|
39
|
+
// I'm not sure it makes sense to keep it...
|
|
40
|
+
if (strInput === '/' && typeof options?.hashExtra === 'undefined') {
|
|
30
41
|
return 'index';
|
|
31
42
|
}
|
|
32
|
-
const
|
|
43
|
+
const str = strInput === '/' ? 'index' : strInput;
|
|
44
|
+
|
|
45
|
+
const hashExtra = options?.hashExtra ?? '';
|
|
46
|
+
const hashLength = options?.hashLength ?? 3;
|
|
47
|
+
|
|
48
|
+
const stringToHash = str + hashExtra;
|
|
49
|
+
const shortHash = simpleHash(stringToHash, hashLength);
|
|
33
50
|
const parsedPath = `${_.kebabCase(str)}-${shortHash}`;
|
|
34
51
|
if (isNameTooLong(parsedPath)) {
|
|
35
52
|
return `${shortName(_.kebabCase(str))}-${shortHash}`;
|
package/src/index.ts
CHANGED
|
@@ -44,6 +44,9 @@ export {
|
|
|
44
44
|
isValidPathname,
|
|
45
45
|
resolvePathname,
|
|
46
46
|
parseURLPath,
|
|
47
|
+
parseLocalURLPath,
|
|
48
|
+
parseURLOrPath,
|
|
49
|
+
toURLPath,
|
|
47
50
|
serializeURLPath,
|
|
48
51
|
hasSSHProtocol,
|
|
49
52
|
buildHttpsUrl,
|
|
@@ -52,10 +55,13 @@ export {
|
|
|
52
55
|
export type {URLPath} from './urlUtils';
|
|
53
56
|
export {
|
|
54
57
|
type Tag,
|
|
58
|
+
type TagsFile,
|
|
59
|
+
type TagsFileInput,
|
|
60
|
+
type TagMetadata,
|
|
55
61
|
type TagsListItem,
|
|
56
62
|
type TagModule,
|
|
57
63
|
type FrontMatterTag,
|
|
58
|
-
|
|
64
|
+
type TagsPluginOptions,
|
|
59
65
|
groupTaggedItems,
|
|
60
66
|
getTagVisibility,
|
|
61
67
|
} from './tags';
|
|
@@ -73,8 +79,8 @@ export {
|
|
|
73
79
|
} from './markdownUtils';
|
|
74
80
|
export {
|
|
75
81
|
type ContentPaths,
|
|
76
|
-
type
|
|
77
|
-
|
|
82
|
+
type SourceToPermalink,
|
|
83
|
+
resolveMarkdownLinkPathname,
|
|
78
84
|
} from './markdownLinks';
|
|
79
85
|
export {type SluggerOptions, type Slugger, createSlugger} from './slugger';
|
|
80
86
|
export {
|
|
@@ -103,7 +109,7 @@ export {escapeShellArg} from './shellUtils';
|
|
|
103
109
|
export {loadFreshModule} from './moduleUtils';
|
|
104
110
|
export {
|
|
105
111
|
getDataFilePath,
|
|
106
|
-
|
|
112
|
+
readDataFile,
|
|
107
113
|
getContentPathList,
|
|
108
114
|
findFolderContainingFile,
|
|
109
115
|
getFolderContainingFile,
|
|
@@ -121,3 +127,5 @@ export {
|
|
|
121
127
|
type LastUpdateData,
|
|
122
128
|
type FrontMatterLastUpdate,
|
|
123
129
|
} from './lastUpdateUtils';
|
|
130
|
+
|
|
131
|
+
export {normalizeTags, reportInlineTags} from './tags';
|