aboutsummaryrefslogtreecommitdiffhomepage
path: root/services/nuldoc/nuldoc-src/components/StaticScript.ts
blob: 7df40fd990ed0e8b4867365474823658b3678ff0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { join } from "@std/path";
import { Config } from "../config.ts";
import { elem, Element } from "../dom.ts";
import { calculateFileHash } from "./utils.ts";

export default async function StaticScript(
  { fileName, type, defer, config }: {
    fileName: string;
    type?: string;
    defer?: "true";
    config: Config;
  },
): Promise<Element> {
  const filePath = join(Deno.cwd(), config.locations.staticDir, fileName);
  const hash = await calculateFileHash(filePath);
  const attrs: Record<string, string> = { src: `${fileName}?h=${hash}` };
  if (type) attrs.type = type;
  if (defer) attrs.defer = defer;
  return elem("script", attrs);
}