diff --git a/routes/[...index].ts b/routes/[...index].ts index 8b61487..a2a6cf1 100644 --- a/routes/[...index].ts +++ b/routes/[...index].ts @@ -39,13 +39,22 @@ function insertRegistry(html: string): string { const ast = parse(html); - // insert registry script to head + let hasCustomElements = false; + walkSync(ast, (node) => { - if (node.type === ELEMENT_NODE && node.name === "head") { - node.children.push(parse(registryScript)); + if (node.type === ELEMENT_NODE && node.name.includes("-")) { + hasCustomElements = true; } }); + // insert registry script to head + if (hasCustomElements) + walkSync(ast, (node) => { + if (node.type === ELEMENT_NODE && node.name === "head") { + node.children.push(parse(registryScript)); + } + }); + return renderSync(ast); } @@ -82,10 +91,10 @@ function doSetUp(html: string) { 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].trim()]); + while ((match = regex.exec(html))) { + let [key, value] = match; + value = value.replace(/\s/g, ""); + html = html.replace(key, setupMap[value]); } console.log("---------"); diff --git a/src/pages/404.html b/src/pages/404.html index 9aa023d..2ea680f 100644 --- a/src/pages/404.html +++ b/src/pages/404.html @@ -1,8 +1,18 @@ - + + +
+ + +