From 71aba3df235dc9a8acbee0e33980b30ba4ce44d4 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 18 Mar 2023 18:53:05 +0900 Subject: refactor: add components/*.ts for shared components --- nuldoc-src/pages/utils.ts | 51 ----------------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 nuldoc-src/pages/utils.ts (limited to 'nuldoc-src/pages/utils.ts') diff --git a/nuldoc-src/pages/utils.ts b/nuldoc-src/pages/utils.ts deleted file mode 100644 index 018c460..0000000 --- a/nuldoc-src/pages/utils.ts +++ /dev/null @@ -1,51 +0,0 @@ -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, - raw: false, - }; -} - -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}`]]); -} - -export function metaElement(attrs: [string, string][]): Element { - return el("meta", attrs); -} - -export function linkElement( - rel: string, - href: string, - type: string | null, -): Element { - const attrs: [string, string][] = [["rel", rel], ["href", href]]; - if (type !== null) { - attrs.push(["type", type]); - } - return el("link", attrs); -} -- cgit v1.2.3-70-g09d2