@easy-cms/plugin-redirects 1.4.1 → 1.4.2
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/dist/index.d.ts +3 -2
- package/dist/index.js +20 -4
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -111,8 +111,9 @@ interface Redirect {
|
|
|
111
111
|
readonly status: 301 | 302 | 307 | 308;
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
|
-
* A path as redirects store it: the pathname only (no query or fragment), no trailing slash
|
|
115
|
-
*
|
|
114
|
+
* A path as redirects store it: the pathname only (no query or fragment), no trailing slash,
|
|
115
|
+
* percent-encoded with uppercase escapes. `/ข่าว`, `/%e0%b8%82…` and `/%E0%B8%82…` are the same
|
|
116
|
+
* path. `null` when it isn't a path.
|
|
116
117
|
*/
|
|
117
118
|
declare function normalizePath(input: string): string | null;
|
|
118
119
|
interface ResolveRedirectOptions {
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var INFO = {
|
|
|
9
9
|
name: "@easy-cms/plugin-redirects",
|
|
10
10
|
// The plugin API it is written for (`PLUGIN_API_VERSION` of @easy-cms/core).
|
|
11
11
|
apiVersion: 1,
|
|
12
|
-
...true ? { version: "1.4.
|
|
12
|
+
...true ? { version: "1.4.2" } : {}
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
// src/shared.ts
|
|
@@ -28,7 +28,23 @@ function normalizePath(input) {
|
|
|
28
28
|
return null;
|
|
29
29
|
}
|
|
30
30
|
if (!/^(\/|https?:\/\/)/i.test(value)) return null;
|
|
31
|
-
return url.pathname.replace(/\/+$/, "") || "/";
|
|
31
|
+
return canonicalEscapes(url.pathname.replace(/\/+$/, "")) || "/";
|
|
32
|
+
}
|
|
33
|
+
function canonicalEscapes(value) {
|
|
34
|
+
return value.replace(/%([0-9a-f]{2})/gi, (_, hex) => {
|
|
35
|
+
const char = String.fromCharCode(Number.parseInt(hex, 16));
|
|
36
|
+
return /[A-Za-z0-9\-._~]/.test(char) ? char : `%${hex.toUpperCase()}`;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function encodeLocation(location) {
|
|
40
|
+
if (!/[^\x21-\x7e]/.test(location)) return location;
|
|
41
|
+
try {
|
|
42
|
+
if (/^https?:\/\//i.test(location)) return new URL(location).href;
|
|
43
|
+
const url = new URL(location, "http://site.invalid");
|
|
44
|
+
return canonicalEscapes(url.pathname) + url.search + url.hash;
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
32
48
|
}
|
|
33
49
|
var CACHE = /* @__PURE__ */ Symbol.for("easy-cms.plugin-redirects.cache");
|
|
34
50
|
function clearRedirects(cms) {
|
|
@@ -101,7 +117,7 @@ async function load(cms, source, scope) {
|
|
|
101
117
|
return map;
|
|
102
118
|
}
|
|
103
119
|
async function target(cms, source, doc) {
|
|
104
|
-
if (typeof doc.to === "string" && doc.to.trim()) return doc.to.trim();
|
|
120
|
+
if (typeof doc.to === "string" && doc.to.trim()) return encodeLocation(doc.to.trim());
|
|
105
121
|
for (const collection of source.collections) {
|
|
106
122
|
const ref = doc[targetField(collection)];
|
|
107
123
|
const id = typeof ref === "object" && ref !== null ? ref.id : ref;
|
|
@@ -113,7 +129,7 @@ async function target(cms, source, doc) {
|
|
|
113
129
|
});
|
|
114
130
|
if (!page || page.status !== void 0 && page.status !== "published") return null;
|
|
115
131
|
const url = await source.url?.({ collection, doc: page, locale });
|
|
116
|
-
return typeof url === "string" && url.trim() ? url.trim() : null;
|
|
132
|
+
return typeof url === "string" && url.trim() ? encodeLocation(url.trim()) : null;
|
|
117
133
|
}
|
|
118
134
|
return null;
|
|
119
135
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-cms/plugin-redirects",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Redirects for Easy CMS: 301s managed in the admin, automatic redirects when a page's address changes",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"@easy-cms/core": "^1.4.
|
|
19
|
+
"@easy-cms/core": "^1.4.2"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@easy-cms/core": "^1.4.
|
|
23
|
-
"@easy-cms/db-sqlite": "^1.4.
|
|
22
|
+
"@easy-cms/core": "^1.4.2",
|
|
23
|
+
"@easy-cms/db-sqlite": "^1.4.2"
|
|
24
24
|
},
|
|
25
25
|
"engines": {
|
|
26
26
|
"node": ">=22.12"
|