From 994e0114d76ae19768d5c303874a968cf6369fd0 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 7 Sep 2023 22:27:48 +0900 Subject: meta: migrate to monorepo --- vhosts/blog/nuldoc-src/components/utils.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 vhosts/blog/nuldoc-src/components/utils.ts (limited to 'vhosts/blog/nuldoc-src/components/utils.ts') diff --git a/vhosts/blog/nuldoc-src/components/utils.ts b/vhosts/blog/nuldoc-src/components/utils.ts new file mode 100644 index 00000000..f0de71f1 --- /dev/null +++ b/vhosts/blog/nuldoc-src/components/utils.ts @@ -0,0 +1,30 @@ +import { crypto, toHashString } from "std/crypto/mod.ts"; +import { join } from "std/path/mod.ts"; +import { Config } from "../config.ts"; +import { el, Element } from "../dom.ts"; + +export async function stylesheetLinkElement( + fileName: string, + config: Config, +): Promise { + const filePath = join(Deno.cwd(), config.locations.staticDir, fileName); + const hash = await calculateFileHash(filePath); + return el("link", [["rel", "stylesheet"], ["href", `${fileName}?h=${hash}`]]); +} + +export async function staticScriptElement( + fileName: string, + attrs: [string, string][], + config: Config, +): Promise { + const filePath = join(Deno.cwd(), config.locations.staticDir, fileName); + const hash = await calculateFileHash(filePath); + return el("script", [["src", `${fileName}?h=${hash}`], ...attrs]); +} + +async function calculateFileHash( + filePath: string, +): Promise { + const content = (await Deno.readFile(filePath)).buffer; + return toHashString(await crypto.subtle.digest("MD5", content), "hex"); +} -- cgit v1.2.3-70-g09d2