/* eslint-disable @typescript-eslint/require-await */
import { promises as fs } from "node:fs";
import path from "node:path";
const htmlEscape = (str) => str
.replace(/&/g, "&")
.replace(/"/g, """)
.replace(/'/g, "'")
.replace(//g, ">");
const buildHtmlTemplate = (title, script, nodesData, style) => `
${htmlEscape(title)}
`;
export const buildHtml = (template) => async ({ title, data }) => {
const [script, style] = await Promise.all([
fs.readFile(path.join(import.meta.dirname, "..", "..", "lib", `${template}.js`), "utf8"),
fs.readFile(path.join(import.meta.dirname, "..", "..", "lib", `${template}.css`), "utf8"),
]);
return buildHtmlTemplate(title, script, data, style);
};