From 6d6921aa645561f1a150c63e060a3693e97b8f54 Mon Sep 17 00:00:00 2001 From: Ayo Date: Tue, 10 Oct 2023 22:20:16 +0200 Subject: [PATCH] feat: replace all matches --- nitro.config.ts | 2 +- routes/[...index].ts | 11 ++++++++++- src/pages/index.html | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/nitro.config.ts b/nitro.config.ts index 7b20fb7..030cdae 100644 --- a/nitro.config.ts +++ b/nitro.config.ts @@ -1,6 +1,6 @@ //https://nitro.unjs.io/config export default defineNitroConfig({ - preset: "node", + preset: "vercel", devServer: { watch: ["./src/pages", "./src/components"], }, diff --git a/routes/[...index].ts b/routes/[...index].ts index eb41dfc..e5ba753 100644 --- a/routes/[...index].ts +++ b/routes/[...index].ts @@ -67,5 +67,14 @@ function doSetUp(html: string) { 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; } diff --git a/src/pages/index.html b/src/pages/index.html index b71e1cb..8e41f96 100644 --- a/src/pages/index.html +++ b/src/pages/index.html @@ -6,7 +6,7 @@ Hello Nitro @@ -14,7 +14,7 @@
- some text + some text: {{greeting}}