From b206b17dfffee47940d391dd8dfbcfd79cc6861e Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 25 Apr 2025 22:36:47 +0900 Subject: feat(blog/nuldoc): add `defer` attribute to some `script` tags --- vhosts/blog/nuldoc-src/components/StaticScript.tsx | 5 +++-- vhosts/blog/nuldoc-src/jsx/types.d.ts | 2 +- vhosts/blog/nuldoc-src/pages/AboutPage.tsx | 6 +++++- vhosts/blog/nuldoc-src/renderers/html.ts | 12 +++++++++--- vhosts/blog/public/about/index.html | 4 ++-- vhosts/blog/public/my-icon.js | 2 +- vhosts/blog/static/my-icon.js | 2 +- 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/vhosts/blog/nuldoc-src/components/StaticScript.tsx b/vhosts/blog/nuldoc-src/components/StaticScript.tsx index e3b103cc..0e3ab194 100644 --- a/vhosts/blog/nuldoc-src/components/StaticScript.tsx +++ b/vhosts/blog/nuldoc-src/components/StaticScript.tsx @@ -3,15 +3,16 @@ import { Config } from "../config.ts"; import { calculateFileHash } from "./utils.ts"; export default async function StaticScript( - { fileName, type, config }: { + { fileName, type, defer, config }: { fileName: string; type?: string; + defer?: "true"; config: Config; }, ) { const filePath = join(Deno.cwd(), config.locations.staticDir, fileName); const hash = await calculateFileHash(filePath); return ( - + ); } diff --git a/vhosts/blog/nuldoc-src/jsx/types.d.ts b/vhosts/blog/nuldoc-src/jsx/types.d.ts index cbf68a4c..0e5b223f 100644 --- a/vhosts/blog/nuldoc-src/jsx/types.d.ts +++ b/vhosts/blog/nuldoc-src/jsx/types.d.ts @@ -64,7 +64,7 @@ declare global { noscript: IntrinsicElementType; ol: IntrinsicElementType; p: IntrinsicElementType; - script: { src: string; type?: string }; + script: { src: string; type?: string; defer?: "true" }; section: IntrinsicElementType; time: IntrinsicElementType & { datetime?: string }; title: IntrinsicElementType; diff --git a/vhosts/blog/nuldoc-src/pages/AboutPage.tsx b/vhosts/blog/nuldoc-src/pages/AboutPage.tsx index 99953b3e..1fe6adac 100644 --- a/vhosts/blog/nuldoc-src/pages/AboutPage.tsx +++ b/vhosts/blog/nuldoc-src/pages/AboutPage.tsx @@ -25,8 +25,12 @@ export default function AboutPage(

nsfisis

-
+ diff --git a/vhosts/blog/nuldoc-src/renderers/html.ts b/vhosts/blog/nuldoc-src/renderers/html.ts index ec77eb4d..b9336b53 100644 --- a/vhosts/blog/nuldoc-src/renderers/html.ts +++ b/vhosts/blog/nuldoc-src/renderers/html.ts @@ -183,9 +183,14 @@ function elementNodeToHtmlText(e: Element, ctx: Context): string { s += " "; for (let i = 0; i < attributes.length; i++) { const [name, value] = attributes[i]; - s += `${name === "className" ? "class" : name}="${ - encodeSpecialCharacters(value) - }"`; + if (name === "defer" && value === "true") { + // TODO + s += "defer"; + } else { + s += `${name === "className" ? "class" : name}="${ + encodeSpecialCharacters(value) + }"`; + } if (i !== attributes.length - 1) { s += " "; } @@ -246,6 +251,7 @@ function indent(ctx: Context): string { function getElementAttributes(e: Element): [string, string][] { return [...e.attributes.entries()] .filter((a) => !a[0].startsWith("--")) + .filter((a) => a[1] !== undefined) .sort( (a, b) => { // Special rules: diff --git a/vhosts/blog/public/about/index.html b/vhosts/blog/public/about/index.html index 7ffe7f61..dd90ed32 100644 --- a/vhosts/blog/public/about/index.html +++ b/vhosts/blog/public/about/index.html @@ -42,10 +42,10 @@

nsfisis

-
+