@decocms/start 0.30.2 → 0.30.4
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/README.md +1 -1
- package/package.json +1 -1
- package/src/cms/resolve.ts +6 -4
- package/src/matchers/builtins.ts +22 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @decocms/start
|
|
1
|
+
# @decocms/start
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@decocms/start)
|
|
4
4
|
[](https://github.com/decocms/deco-start/blob/main/LICENSE)
|
package/package.json
CHANGED
package/src/cms/resolve.ts
CHANGED
|
@@ -228,10 +228,12 @@ if (!G.__deco._builtinMatchersRegistered) {
|
|
|
228
228
|
"website/matchers/never.ts": () => false,
|
|
229
229
|
"website/matchers/device.ts": (rule, ctx) => {
|
|
230
230
|
const ua = (ctx.userAgent || "").toLowerCase();
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
231
|
+
const isTablet = /ipad|android(?!.*mobile)|tablet/i.test(ua);
|
|
232
|
+
const isMobile = !isTablet && /mobile|android|iphone|ipod|webos|blackberry|opera mini|iemobile/i.test(ua);
|
|
233
|
+
const isDesktop = !isMobile && !isTablet;
|
|
234
|
+
// If no flags are set, match everything (permissive default)
|
|
235
|
+
if (!rule.mobile && !rule.tablet && !rule.desktop) return true;
|
|
236
|
+
return !!(rule.mobile && isMobile) || !!(rule.tablet && isTablet) || !!(rule.desktop && isDesktop);
|
|
235
237
|
},
|
|
236
238
|
"website/matchers/random.ts": (rule) => {
|
|
237
239
|
const traffic = typeof rule.traffic === "number" ? rule.traffic : 0.5;
|
package/src/matchers/builtins.ts
CHANGED
|
@@ -94,12 +94,29 @@ function isSafePattern(pattern: string): boolean {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
function pathnameMatcher(rule: Record<string, unknown>, ctx: MatcherContext): boolean {
|
|
97
|
+
const path = ctx.path ?? "";
|
|
98
|
+
|
|
99
|
+
// CMS "case" format: { type: "Includes" | "Equals" | "Not Includes" | "Starts With", pathname: "/..." }
|
|
100
|
+
const caseObj = rule.case as { type?: string; pathname?: string } | undefined;
|
|
101
|
+
if (caseObj?.pathname) {
|
|
102
|
+
switch (caseObj.type) {
|
|
103
|
+
case "Equals":
|
|
104
|
+
return path === caseObj.pathname;
|
|
105
|
+
case "Not Includes":
|
|
106
|
+
return !path.includes(caseObj.pathname);
|
|
107
|
+
case "Starts With":
|
|
108
|
+
return path.startsWith(caseObj.pathname);
|
|
109
|
+
case "Includes":
|
|
110
|
+
default:
|
|
111
|
+
return path.includes(caseObj.pathname);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Standard format: pattern (regex), includes (exact/glob), excludes (exact/glob)
|
|
97
116
|
const pattern = rule.pattern as string | undefined;
|
|
98
117
|
const includes = rule.includes as string[] | undefined;
|
|
99
118
|
const excludes = rule.excludes as string[] | undefined;
|
|
100
119
|
|
|
101
|
-
const path = ctx.path ?? "";
|
|
102
|
-
|
|
103
120
|
if (pattern) {
|
|
104
121
|
if (!isSafePattern(pattern)) {
|
|
105
122
|
console.warn(
|
|
@@ -137,6 +154,9 @@ function pathnameMatcher(rule: Record<string, unknown>, ctx: MatcherContext): bo
|
|
|
137
154
|
if (excluded) return false;
|
|
138
155
|
}
|
|
139
156
|
|
|
157
|
+
// No constraints specified — vacuously true
|
|
158
|
+
if (!pattern && !includes?.length && !excludes?.length) return false;
|
|
159
|
+
|
|
140
160
|
return true;
|
|
141
161
|
}
|
|
142
162
|
|