feat: replace all matches

This commit is contained in:
Ayo 2023-10-10 22:20:16 +02:00
parent 03bfab0163
commit 6d6921aa64
3 changed files with 13 additions and 4 deletions

View file

@ -1,6 +1,6 @@
//https://nitro.unjs.io/config //https://nitro.unjs.io/config
export default defineNitroConfig({ export default defineNitroConfig({
preset: "node", preset: "vercel",
devServer: { devServer: {
watch: ["./src/pages", "./src/components"], watch: ["./src/pages", "./src/components"],
}, },

View file

@ -67,5 +67,14 @@ function doSetUp(html: string) {
Object.assign(setupMap, new evalStore()); Object.assign(setupMap, new evalStore());
}); });
return html.replace("{{name}}", setupMap["name"]); const regex = /{{(.*?)}}/g;
var match;
let matches = [];
while ((match = regex.exec(html)) != null) {
console.log(match[0], match[1]);
html = html.replace(match[0], setupMap[match[1]]);
}
return html;
} }

View file

@ -6,7 +6,7 @@
<title>Hello Nitro</title> <title>Hello Nitro</title>
<script server:setup> <script server:setup>
const name = "AYOs"; const name = "AYOs";
return { name }; // TODO: this is illegal! figure out a way to build an object in the route intercept return { name, greeting: "hey" }; // TODO: this is illegal! figure out a way to build an object in the route intercept
</script> </script>
</head> </head>
<body> <body>
@ -14,7 +14,7 @@
<div> <div>
<hello-world name="{{name}}"></hello-world> <hello-world name="{{name}}"></hello-world>
</div> </div>
<span>some text</span> <span>some text: {{greeting}}</span>
<clickable-text></clickable-text> <clickable-text></clickable-text>
<script> <script>
const helloWorld = document.querySelector("hello-world"); const helloWorld = document.querySelector("hello-world");