@docusaurus/utils-common 3.10.1 → 4.0.0-canary-6808
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.
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
import type { DocusaurusConfig } from '@docusaurus/types';
|
|
8
8
|
export type ApplyTrailingSlashParams = Pick<DocusaurusConfig, 'trailingSlash' | 'baseUrl'>;
|
|
9
9
|
export declare function addTrailingSlash(str: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Apply/remove a trailing slash on an URL path according to site config options
|
|
12
|
+
* Usually applied on permalinks / URL paths, but also works with absolute URL
|
|
13
|
+
*/
|
|
10
14
|
export default function applyTrailingSlash(path: string, options: ApplyTrailingSlashParams): string;
|
|
11
15
|
/** Appends a leading slash to `str`, if one doesn't exist. */
|
|
12
16
|
export declare function addLeadingSlash(str: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyTrailingSlash.d.ts","sourceRoot":"","sources":["../src/applyTrailingSlash.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAExD,MAAM,MAAM,wBAAwB,GAAG,IAAI,CACzC,gBAAgB,EAChB,eAAe,GAAG,SAAS,CAC5B,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;
|
|
1
|
+
{"version":3,"file":"applyTrailingSlash.d.ts","sourceRoot":"","sources":["../src/applyTrailingSlash.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAExD,MAAM,MAAM,wBAAwB,GAAG,IAAI,CACzC,gBAAgB,EAChB,eAAe,GAAG,SAAS,CAC5B,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CACxC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,wBAAwB,GAChC,MAAM,CAgCR;AAED,8DAA8D;AAC9D,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,6CAA6C;AAC7C,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD"}
|
|
@@ -14,7 +14,10 @@ const stringUtils_1 = require("./stringUtils");
|
|
|
14
14
|
function addTrailingSlash(str) {
|
|
15
15
|
return str.endsWith('/') ? str : `${str}/`;
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Apply/remove a trailing slash on an URL path according to site config options
|
|
19
|
+
* Usually applied on permalinks / URL paths, but also works with absolute URL
|
|
20
|
+
*/
|
|
18
21
|
function applyTrailingSlash(path, options) {
|
|
19
22
|
const { trailingSlash, baseUrl } = options;
|
|
20
23
|
if (path.startsWith('#')) {
|
|
@@ -30,6 +33,7 @@ function applyTrailingSlash(path, options) {
|
|
|
30
33
|
}
|
|
31
34
|
// The trailing slash should be handled before the ?search#hash !
|
|
32
35
|
const [pathname] = path.split(/[#?]/);
|
|
36
|
+
const queryHash = path.slice(pathname.length);
|
|
33
37
|
// Never transform '/' to ''
|
|
34
38
|
// Never remove the baseUrl trailing slash!
|
|
35
39
|
// If baseUrl = /myBase/, we want to emit /myBase/index.html and not
|
|
@@ -38,7 +42,7 @@ function applyTrailingSlash(path, options) {
|
|
|
38
42
|
const newPathname = shouldNotApply
|
|
39
43
|
? pathname
|
|
40
44
|
: handleTrailingSlash(pathname, trailingSlash);
|
|
41
|
-
return
|
|
45
|
+
return `${newPathname}${queryHash}`;
|
|
42
46
|
}
|
|
43
47
|
/** Appends a leading slash to `str`, if one doesn't exist. */
|
|
44
48
|
function addLeadingSlash(str) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyTrailingSlash.js","sourceRoot":"","sources":["../src/applyTrailingSlash.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAUH,4CAEC;
|
|
1
|
+
{"version":3,"file":"applyTrailingSlash.js","sourceRoot":"","sources":["../src/applyTrailingSlash.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAUH,4CAEC;AAMD,qCAmCC;AAGD,0CAEC;AAGD,kDAEC;AA7DD,+CAAsD;AAQtD,SAAgB,gBAAgB,CAAC,GAAW;IAC1C,OAAO,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;AAC7C,CAAC;AAED;;;GAGG;AACH,SAAwB,kBAAkB,CACxC,IAAY,EACZ,OAAiC;IAEjC,MAAM,EAAC,aAAa,EAAE,OAAO,EAAC,GAAG,OAAO,CAAC;IAEzC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,+CAA+C;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,SAAS,mBAAmB,CAAC,GAAW,EAAE,QAAiB;QACzD,OAAO,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IACrE,CAAC;IAED,8CAA8C;IAC9C,IAAI,OAAO,aAAa,KAAK,WAAW,EAAE,CAAC;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iEAAiE;IACjE,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAA0B,CAAC;IAC/D,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAE9C,4BAA4B;IAC5B,2CAA2C;IAC3C,oEAAoE;IACpE,uEAAuE;IACvE,MAAM,cAAc,GAAG,QAAQ,KAAK,GAAG,IAAI,QAAQ,KAAK,OAAO,CAAC;IAEhE,MAAM,WAAW,GAAG,cAAc;QAChC,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,mBAAmB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IAEjD,OAAO,GAAG,WAAW,GAAG,SAAS,EAAE,CAAC;AACtC,CAAC;AAED,8DAA8D;AAC9D,SAAgB,eAAe,CAAC,GAAW;IACzC,OAAO,IAAA,uBAAS,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAC7B,CAAC;AAED,6CAA6C;AAC7C,SAAgB,mBAAmB,CAAC,GAAW;IAC7C,OAAO,IAAA,0BAAY,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAChC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils-common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-canary-6808",
|
|
4
4
|
"description": "Common (Node/Browser) utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
},
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@docusaurus/types": "
|
|
23
|
-
"tslib": "^2.
|
|
22
|
+
"@docusaurus/types": "4.0.0-canary-6808",
|
|
23
|
+
"tslib": "^2.8.1"
|
|
24
24
|
},
|
|
25
25
|
"engines": {
|
|
26
|
-
"node": ">=
|
|
26
|
+
"node": ">=24.14"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "91e445730a91fbe20dd5fefae560303a0c655aa7"
|
|
29
29
|
}
|
|
@@ -17,7 +17,10 @@ export function addTrailingSlash(str: string): string {
|
|
|
17
17
|
return str.endsWith('/') ? str : `${str}/`;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Apply/remove a trailing slash on an URL path according to site config options
|
|
22
|
+
* Usually applied on permalinks / URL paths, but also works with absolute URL
|
|
23
|
+
*/
|
|
21
24
|
export default function applyTrailingSlash(
|
|
22
25
|
path: string,
|
|
23
26
|
options: ApplyTrailingSlashParams,
|
|
@@ -40,6 +43,7 @@ export default function applyTrailingSlash(
|
|
|
40
43
|
|
|
41
44
|
// The trailing slash should be handled before the ?search#hash !
|
|
42
45
|
const [pathname] = path.split(/[#?]/) as [string, ...string[]];
|
|
46
|
+
const queryHash = path.slice(pathname.length);
|
|
43
47
|
|
|
44
48
|
// Never transform '/' to ''
|
|
45
49
|
// Never remove the baseUrl trailing slash!
|
|
@@ -51,7 +55,7 @@ export default function applyTrailingSlash(
|
|
|
51
55
|
? pathname
|
|
52
56
|
: handleTrailingSlash(pathname, trailingSlash);
|
|
53
57
|
|
|
54
|
-
return
|
|
58
|
+
return `${newPathname}${queryHash}`;
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
/** Appends a leading slash to `str`, if one doesn't exist. */
|