feat: delete server:script
This commit is contained in:
parent
3b246cb711
commit
69499d61ab
2 changed files with 17 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { ELEMENT_NODE, parse, walkSync } from "ultrahtml";
|
import { ELEMENT_NODE, parse, renderSync, walkSync } from "ultrahtml";
|
||||||
import { parseScript } from "esprima";
|
import { parseScript } from "esprima";
|
||||||
|
|
||||||
export default eventHandler(async (event) => {
|
export default eventHandler(async (event) => {
|
||||||
|
@ -14,7 +14,7 @@ export default eventHandler(async (event) => {
|
||||||
if (!html) html = await useStorage().getItem(getPath("/404.html"));
|
if (!html) html = await useStorage().getItem(getPath("/404.html"));
|
||||||
|
|
||||||
// transforms
|
// transforms
|
||||||
const transforms = [insertRegistry, doSetUp];
|
const transforms = [insertRegistry, doSetUp, deleteServerScripts];
|
||||||
if (html) {
|
if (html) {
|
||||||
for (const transform of transforms) {
|
for (const transform of transforms) {
|
||||||
html = transform(html.toString());
|
html = transform(html.toString());
|
||||||
|
@ -83,3 +83,17 @@ function doSetUp(html: string) {
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteServerScripts(html: string): string {
|
||||||
|
const ast = parse(html);
|
||||||
|
walkSync(ast, (node) => {
|
||||||
|
const { attributes } = node;
|
||||||
|
const attributeKeys = Object.keys(attributes ?? {});
|
||||||
|
const isServerScript = attributeKeys.some((key) => key.includes("server:"));
|
||||||
|
if (isServerScript) {
|
||||||
|
node.parent.children.splice(node.parent.children.indexOf(node), 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return renderSync(ast);
|
||||||
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<body>
|
<body>
|
||||||
<a href="/about">{{ count }}</a>
|
<a href="/about">{{ count }}</a>
|
||||||
<div>
|
<div>
|
||||||
<hello-world name="{{name}}"></hello-world>
|
<hello-world name="{{name }}"></hello-world>
|
||||||
</div>
|
</div>
|
||||||
<p>some text: {{greeting}}</p>
|
<p>some text: {{greeting}}</p>
|
||||||
<clickable-text></clickable-text>
|
<clickable-text></clickable-text>
|
||||||
|
|
Loading…
Reference in a new issue