/** * Default handler for returning HTML with SSI support * @module */ import * as fs from "@std/fs"; import * as path from "@std/path"; import { md_to_html } from "./markdown.ts"; // https://stackoverflow.com/a/75205316 const replaceAsync = async ( str: string, regex: RegExp, asyncFn: (match: any, ...args: any) => Promise, ) => { const promises: Promise[] = []; str.replace(regex, (match, ...args) => { promises.push(asyncFn(match, ...args)); return match; }); const data = await Promise.all(promises); return str.replace(regex, () => data.shift()); }; export async function load_html_with_ssi(html_file: string): Promise { const directory = path.dirname(html_file); const html_file_content: string = await Deno.readTextFile(html_file); const processed: string = await replaceAsync( html_file_content, /\<\!--\s+#include\s+(?.*?)\s*-->/gm, async (_match, directive, index): Promise => { const file_include_options = Array.from( directive.matchAll(/(?