From 88ba6cfe220216f371f8756921059fac51a21262 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 23 Dec 2022 23:27:09 +0900 Subject: AsciiDoc to DocBook --- nuldoc-src/templates/utils.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 nuldoc-src/templates/utils.ts (limited to 'nuldoc-src/templates/utils.ts') diff --git a/nuldoc-src/templates/utils.ts b/nuldoc-src/templates/utils.ts new file mode 100644 index 0000000..a86803d --- /dev/null +++ b/nuldoc-src/templates/utils.ts @@ -0,0 +1,34 @@ +import { join } from "std/path/mod.ts"; +import { crypto, toHashString } from "std/crypto/mod.ts"; +import { Element, Node, Text } from "../dom.ts"; +import { Config } from "../config.ts"; + +export function text(content: string): Text { + return { + kind: "text", + content: content, + }; +} + +export function el( + name: string, + attrs: [string, string][], + ...children: Node[] +): Element { + return { + kind: "element", + name: name, + attributes: new Map(attrs), + children: children, + }; +} + +export async function stylesheetLinkElement( + fileName: string, + config: Config, +): Promise { + const filePath = join(Deno.cwd(), config.locations.staticDir, fileName); + const content = (await Deno.readFile(filePath)).buffer; + const hash = toHashString(await crypto.subtle.digest("MD5", content), "hex"); + return el("link", [["rel", "stylesheet"], ["href", `${fileName}?h=${hash}`]]); +} -- cgit v1.2.3-70-g09d2