Refine admin editor around static content
This commit is contained in:
+17
-2
@@ -48,8 +48,19 @@ function escapeAttr(value) {
|
||||
return escapeHtml(value).replaceAll('"', """).replaceAll("'", "'");
|
||||
}
|
||||
|
||||
function escapeJsString(value) {
|
||||
return String(value)
|
||||
.replaceAll("\\", "\\\\")
|
||||
.replaceAll('"', '\\"')
|
||||
.replaceAll("\n", "\\n")
|
||||
.replaceAll("\r", "\\r")
|
||||
.replaceAll("\u2028", "\\u2028")
|
||||
.replaceAll("\u2029", "\\u2029")
|
||||
.replaceAll("</script", "<\\/script");
|
||||
}
|
||||
|
||||
function renderTemplateTokens(html, block) {
|
||||
return html.replace(/\{\{\s*(text|html|attr):([a-zA-Z0-9_.-]+)\s*\}\}/g, (_match, mode, path) => {
|
||||
return html.replace(/\{\{\s*(text|html|attr|js):([a-zA-Z0-9_.-]+)\s*\}\}/g, (_match, mode, path) => {
|
||||
const value = getByPath(block, path);
|
||||
|
||||
if (value === undefined) {
|
||||
@@ -64,6 +75,10 @@ function renderTemplateTokens(html, block) {
|
||||
return value == null ? "" : escapeAttr(value);
|
||||
}
|
||||
|
||||
if (mode === "js") {
|
||||
return value == null ? "" : escapeJsString(value);
|
||||
}
|
||||
|
||||
return value == null ? "" : escapeHtml(value);
|
||||
});
|
||||
}
|
||||
@@ -117,7 +132,7 @@ async function renderRegion(region) {
|
||||
return blocks.join("");
|
||||
}
|
||||
|
||||
let output = shell;
|
||||
let output = renderTemplateTokens(shell, { id: page.slug, ...page });
|
||||
for (const region of page.regions ?? []) {
|
||||
const token = REGION_TOKEN[region.id];
|
||||
if (!token) {
|
||||
|
||||
Reference in New Issue
Block a user