From 5dccd552cd29325bf289496a61b1676d5c494601 Mon Sep 17 00:00:00 2001 From: Ayo Date: Sun, 8 Oct 2023 02:35:10 +0200 Subject: [PATCH] feat: initial auto insert of registry to head --- plugins/2-register-components.ts | 1 + routes/[...index].ts | 11 ++++------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/plugins/2-register-components.ts b/plugins/2-register-components.ts index de9668a..e413747 100644 --- a/plugins/2-register-components.ts +++ b/plugins/2-register-components.ts @@ -19,6 +19,7 @@ export default defineNitroPlugin(async () => { const customElementsDefine = `Object.keys(registry).forEach((key) => {if(window?.hasOwnProperty("customElements"))customElements.define(key, registry[key]);})`; + if (!fs.existsSync("./public/.output")) fs.mkdirSync("./public/.output"); fs.writeFileSync( "./public/.output/registry.js", [...imports, registryObject, customElementsDefine].join(";") diff --git a/routes/[...index].ts b/routes/[...index].ts index 4379f72..14c9c53 100644 --- a/routes/[...index].ts +++ b/routes/[...index].ts @@ -10,13 +10,10 @@ export default eventHandler(async (event) => { if (!html) html = await useStorage().getItem(fallback); if (!html) html = await useStorage().getItem(getPath("/404.html")); - // insert registry to head - html = html - .toString() - .replace( - "", - '' - ); + // temporary; use ultrahtml later + const registryScript = + ''; + html = html.toString().replace("", registryScript + ""); return html ?? new Response("Not found", { status: 404 }); });