diff options
Diffstat (limited to 'nuldoc-src')
| -rw-r--r-- | nuldoc-src/components/page_layout.ts | 13 | ||||
| -rw-r--r-- | nuldoc-src/components/utils.ts | 30 | ||||
| -rw-r--r-- | nuldoc-src/pages/slide.ts | 14 |
3 files changed, 34 insertions, 23 deletions
diff --git a/nuldoc-src/components/page_layout.ts b/nuldoc-src/components/page_layout.ts index 7dc6a43..50ed45d 100644 --- a/nuldoc-src/components/page_layout.ts +++ b/nuldoc-src/components/page_layout.ts @@ -1,7 +1,6 @@ -import { crypto, toHashString } from "std/crypto/mod.ts"; -import { join } from "std/path/mod.ts"; import { Config } from "../config.ts"; import { el, Element, text } from "../dom.ts"; +import { stylesheetLinkElement } from "./utils.ts"; type Params = { metaCopyrightYear: number; @@ -62,16 +61,6 @@ export async function pageLayout( ); } -async function stylesheetLinkElement( - fileName: string, - config: Config, -): Promise<Element> { - 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}`]]); -} - function metaElement(attrs: [string, string][]): Element { return el("meta", attrs); } diff --git a/nuldoc-src/components/utils.ts b/nuldoc-src/components/utils.ts new file mode 100644 index 0000000..f0de71f --- /dev/null +++ b/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<Element> { + 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<Element> { + 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<string> { + const content = (await Deno.readFile(filePath)).buffer; + return toHashString(await crypto.subtle.digest("MD5", content), "hex"); +} diff --git a/nuldoc-src/pages/slide.ts b/nuldoc-src/pages/slide.ts index f2955af..e5f40a0 100644 --- a/nuldoc-src/pages/slide.ts +++ b/nuldoc-src/pages/slide.ts @@ -2,6 +2,7 @@ import { join } from "std/path/mod.ts"; import { globalFooter } from "../components/global_footer.ts"; import { globalHeader } from "../components/global_header.ts"; import { pageLayout } from "../components/page_layout.ts"; +import { staticScriptElement } from "../components/utils.ts"; import { Config } from "../config.ts"; import { el, text } from "../dom.ts"; import { Page } from "../page.ts"; @@ -100,17 +101,8 @@ export async function generateSlidePage( el("button", [["id", "prev"]], text("Prev")), el("button", [["id", "next"]], text("Next")), ), - el( - "script", - [[ - "src", - "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.4.120/pdf.min.js", - ]], - ), - el( - "script", - [["src", "/slide.js"], ["type", "module"]], - ), + await staticScriptElement("/pdf.min.js", [], config), + await staticScriptElement("/slide.js", [["type", "module"]], config), ), ), ), |
