@vojtaholik/static-kit-core 2.1.11 → 2.1.13
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/package.json +1 -1
- package/src/html-renderer.ts +12 -0
- package/src/template-compiler.ts +4 -3
package/package.json
CHANGED
package/src/html-renderer.ts
CHANGED
|
@@ -166,6 +166,11 @@ export async function renderPage(
|
|
|
166
166
|
data: `__REGION_CONTENT_${regionName}__`,
|
|
167
167
|
} as Node,
|
|
168
168
|
];
|
|
169
|
+
|
|
170
|
+
// Strip data-region in production
|
|
171
|
+
if (!options.isDev) {
|
|
172
|
+
removeAttr(node, "data-region");
|
|
173
|
+
}
|
|
169
174
|
}
|
|
170
175
|
}
|
|
171
176
|
});
|
|
@@ -293,6 +298,13 @@ function setAttr(node: Node, name: string, value: string): void {
|
|
|
293
298
|
}
|
|
294
299
|
}
|
|
295
300
|
|
|
301
|
+
function removeAttr(node: Node, name: string): void {
|
|
302
|
+
const element = node as Element;
|
|
303
|
+
if (element.attrs) {
|
|
304
|
+
element.attrs = element.attrs.filter((a) => a.name !== name);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
296
308
|
/**
|
|
297
309
|
* Strip dev-only attributes (data-block-id, data-schema-address) from production HTML
|
|
298
310
|
*/
|
package/src/template-compiler.ts
CHANGED
|
@@ -255,9 +255,10 @@ function compileElement(element: Element, indent: number): string {
|
|
|
255
255
|
continue;
|
|
256
256
|
}
|
|
257
257
|
// Conditionally render attribute only if value is truthy
|
|
258
|
-
|
|
259
|
-
code += `${pad}
|
|
260
|
-
code += `${pad}
|
|
258
|
+
const varName = attrName.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
259
|
+
code += `${pad}const _${varName}Val = ${attr.value};\n`;
|
|
260
|
+
code += `${pad}if (_${varName}Val) {\n`;
|
|
261
|
+
code += `${pad} out += " ${attrName}=\\"" + escapeAttr(_${varName}Val) + "\\"";\n`;
|
|
261
262
|
code += `${pad}}\n`;
|
|
262
263
|
}
|
|
263
264
|
}
|