@docusaurus/plugin-client-redirects 0.0.0-4518 → 0.0.0-4524
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/collectRedirects.js
CHANGED
|
@@ -23,9 +23,12 @@ function collectRedirects(pluginContext, trailingSlash) {
|
|
|
23
23
|
}
|
|
24
24
|
exports.default = collectRedirects;
|
|
25
25
|
// If users wants to redirect to=/abc and they enable trailingSlash=true then
|
|
26
|
-
// => we don't want to reject the to=/abc (as only /abc/ is an existing/valid
|
|
27
|
-
//
|
|
28
|
-
//
|
|
26
|
+
// => we don't want to reject the to=/abc (as only /abc/ is an existing/valid
|
|
27
|
+
// path now)
|
|
28
|
+
// => we want to redirect to=/abc/ without the user having to change all its
|
|
29
|
+
// redirect plugin options
|
|
30
|
+
// It should be easy to toggle siteConfig.trailingSlash option without having to
|
|
31
|
+
// change other configs
|
|
29
32
|
function applyRedirectsTrailingSlash(redirects, params) {
|
|
30
33
|
return redirects.map((redirect) => ({
|
|
31
34
|
...redirect,
|
|
@@ -52,18 +52,12 @@ function createFromExtensionsRedirects(paths, extensions) {
|
|
|
52
52
|
if (path === '' || path === '/' || alreadyEndsWithAnExtension(path)) {
|
|
53
53
|
return [];
|
|
54
54
|
}
|
|
55
|
-
// /path => /path.html
|
|
56
|
-
// /path/ => /path.html/
|
|
57
|
-
function getFrom(ext) {
|
|
58
|
-
if (path.endsWith('/')) {
|
|
59
|
-
return (0, utils_1.addTrailingSlash)(`${(0, utils_1.removeTrailingSlash)(path)}.${ext}`);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
return `${path}.${ext}`;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
55
|
return extensions.map((ext) => ({
|
|
66
|
-
|
|
56
|
+
// /path => /path.html
|
|
57
|
+
// /path/ => /path.html/
|
|
58
|
+
from: path.endsWith('/')
|
|
59
|
+
? (0, utils_1.addTrailingSlash)(`${(0, utils_1.removeTrailingSlash)(path)}.${ext}`)
|
|
60
|
+
: `${path}.${ext}`,
|
|
67
61
|
to: path,
|
|
68
62
|
}));
|
|
69
63
|
};
|
|
@@ -18,7 +18,8 @@ function createToUrl(baseUrl, to) {
|
|
|
18
18
|
}
|
|
19
19
|
exports.createToUrl = createToUrl;
|
|
20
20
|
// Create redirect file path
|
|
21
|
-
// Make sure this path has lower precedence over the original file path when
|
|
21
|
+
// Make sure this path has lower precedence over the original file path when
|
|
22
|
+
// served by host providers!
|
|
22
23
|
// Otherwise it can produce infinite redirect loops!
|
|
23
24
|
//
|
|
24
25
|
// See https://github.com/facebook/docusaurus/issues/5055
|
|
@@ -29,17 +30,19 @@ function getRedirectFilePath(fromPath, trailingSlash) {
|
|
|
29
30
|
const filePath = path_1.default.dirname(fromPath);
|
|
30
31
|
// Edge case for https://github.com/facebook/docusaurus/pull/5102
|
|
31
32
|
// If the redirect source path is /xyz, with file /xyz.html
|
|
32
|
-
// We can't write the redirect file at /xyz.html/index.html because for Unix
|
|
33
|
-
//
|
|
33
|
+
// We can't write the redirect file at /xyz.html/index.html because for Unix
|
|
34
|
+
// FS, a file/folder can't have the same name "xyz.html"
|
|
35
|
+
// The only possible solution for a redirect file is thus /xyz.html.html (I
|
|
36
|
+
// know, looks suspicious)
|
|
34
37
|
if (trailingSlash === false && fileName.endsWith('.html')) {
|
|
35
38
|
return path_1.default.join(filePath, `${fileName}.html`);
|
|
36
39
|
}
|
|
37
|
-
// If the target path is /xyz, with file /xyz/index.html, we don't want the
|
|
38
|
-
// otherwise it would be picked in priority and
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
40
|
+
// If the target path is /xyz, with file /xyz/index.html, we don't want the
|
|
41
|
+
// redirect file to be /xyz.html, otherwise it would be picked in priority and
|
|
42
|
+
// the redirect file would redirect to itself. We prefer the redirect file to
|
|
43
|
+
// be /xyz.html/index.html, served with lower priority for most static hosting
|
|
44
|
+
// tools
|
|
45
|
+
return path_1.default.join(filePath, `${fileName}/index.html`);
|
|
43
46
|
}
|
|
44
47
|
function toRedirectFilesMetadata(redirects, pluginContext, trailingSlash) {
|
|
45
48
|
// Perf: avoid rendering the template twice with the exact same "props"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-client-redirects",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4524",
|
|
4
4
|
"description": "Client redirects plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-client-redirects.d.ts",
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/core": "0.0.0-
|
|
22
|
-
"@docusaurus/logger": "0.0.0-
|
|
23
|
-
"@docusaurus/utils": "0.0.0-
|
|
24
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
25
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
21
|
+
"@docusaurus/core": "0.0.0-4524",
|
|
22
|
+
"@docusaurus/logger": "0.0.0-4524",
|
|
23
|
+
"@docusaurus/utils": "0.0.0-4524",
|
|
24
|
+
"@docusaurus/utils-common": "0.0.0-4524",
|
|
25
|
+
"@docusaurus/utils-validation": "0.0.0-4524",
|
|
26
26
|
"eta": "^1.12.3",
|
|
27
27
|
"fs-extra": "^10.0.0",
|
|
28
28
|
"lodash": "^4.17.20",
|
|
29
29
|
"tslib": "^2.3.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@docusaurus/types": "0.0.0-
|
|
32
|
+
"@docusaurus/types": "0.0.0-4524"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": "^16.8.4 || ^17.0.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"engines": {
|
|
39
39
|
"node": ">=14"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "41a6bff3a67446f7d2a2972cbe4d05fec7378a15"
|
|
42
42
|
}
|
package/src/collectRedirects.ts
CHANGED
|
@@ -39,9 +39,12 @@ export default function collectRedirects(
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
// If users wants to redirect to=/abc and they enable trailingSlash=true then
|
|
42
|
-
// => we don't want to reject the to=/abc (as only /abc/ is an existing/valid
|
|
43
|
-
//
|
|
44
|
-
//
|
|
42
|
+
// => we don't want to reject the to=/abc (as only /abc/ is an existing/valid
|
|
43
|
+
// path now)
|
|
44
|
+
// => we want to redirect to=/abc/ without the user having to change all its
|
|
45
|
+
// redirect plugin options
|
|
46
|
+
// It should be easy to toggle siteConfig.trailingSlash option without having to
|
|
47
|
+
// change other configs
|
|
45
48
|
function applyRedirectsTrailingSlash(
|
|
46
49
|
redirects: RedirectMetadata[],
|
|
47
50
|
params: ApplyTrailingSlashParams,
|
|
@@ -81,19 +81,12 @@ export function createFromExtensionsRedirects(
|
|
|
81
81
|
if (path === '' || path === '/' || alreadyEndsWithAnExtension(path)) {
|
|
82
82
|
return [];
|
|
83
83
|
}
|
|
84
|
-
|
|
85
|
-
// /path => /path.html
|
|
86
|
-
// /path/ => /path.html/
|
|
87
|
-
function getFrom(ext: string) {
|
|
88
|
-
if (path.endsWith('/')) {
|
|
89
|
-
return addTrailingSlash(`${removeTrailingSlash(path)}.${ext}`);
|
|
90
|
-
} else {
|
|
91
|
-
return `${path}.${ext}`;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
84
|
return extensions.map((ext) => ({
|
|
96
|
-
|
|
85
|
+
// /path => /path.html
|
|
86
|
+
// /path/ => /path.html/
|
|
87
|
+
from: path.endsWith('/')
|
|
88
|
+
? addTrailingSlash(`${removeTrailingSlash(path)}.${ext}`)
|
|
89
|
+
: `${path}.${ext}`,
|
|
97
90
|
to: path,
|
|
98
91
|
}));
|
|
99
92
|
};
|
|
@@ -25,7 +25,8 @@ export function createToUrl(baseUrl: string, to: string): string {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// Create redirect file path
|
|
28
|
-
// Make sure this path has lower precedence over the original file path when
|
|
28
|
+
// Make sure this path has lower precedence over the original file path when
|
|
29
|
+
// served by host providers!
|
|
29
30
|
// Otherwise it can produce infinite redirect loops!
|
|
30
31
|
//
|
|
31
32
|
// See https://github.com/facebook/docusaurus/issues/5055
|
|
@@ -39,17 +40,19 @@ function getRedirectFilePath(
|
|
|
39
40
|
const filePath = path.dirname(fromPath);
|
|
40
41
|
// Edge case for https://github.com/facebook/docusaurus/pull/5102
|
|
41
42
|
// If the redirect source path is /xyz, with file /xyz.html
|
|
42
|
-
// We can't write the redirect file at /xyz.html/index.html because for Unix
|
|
43
|
-
//
|
|
43
|
+
// We can't write the redirect file at /xyz.html/index.html because for Unix
|
|
44
|
+
// FS, a file/folder can't have the same name "xyz.html"
|
|
45
|
+
// The only possible solution for a redirect file is thus /xyz.html.html (I
|
|
46
|
+
// know, looks suspicious)
|
|
44
47
|
if (trailingSlash === false && fileName.endsWith('.html')) {
|
|
45
48
|
return path.join(filePath, `${fileName}.html`);
|
|
46
49
|
}
|
|
47
|
-
// If the target path is /xyz, with file /xyz/index.html, we don't want the
|
|
48
|
-
// otherwise it would be picked in priority and
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
50
|
+
// If the target path is /xyz, with file /xyz/index.html, we don't want the
|
|
51
|
+
// redirect file to be /xyz.html, otherwise it would be picked in priority and
|
|
52
|
+
// the redirect file would redirect to itself. We prefer the redirect file to
|
|
53
|
+
// be /xyz.html/index.html, served with lower priority for most static hosting
|
|
54
|
+
// tools
|
|
55
|
+
return path.join(filePath, `${fileName}/index.html`);
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
export function toRedirectFilesMetadata(
|