import { FlatTemplatable, Templatable, tempstream } from "tempstream"; import { Readable } from "stream"; import { BaseContext } from "koa"; import { default as default_navbar } from "./routes/common/navbar.js"; import { toKebabCase } from "js-convert-case"; export const defaultHead = ( ctx: BaseContext, title: string, options: HTMLOptions ) => /* HTML */ `${title} ยท ${ctx.$app.manifest.name} ${options.morphing ? `` : ""} ${options.preserveScroll ? `` : ""}`; export type HTMLOptions = { preserveScroll?: boolean; morphing?: boolean; navbar?: (ctx: BaseContext) => FlatTemplatable; autoRefreshCSS?: boolean; }; export default function html( ctx: BaseContext, title: string, body: Templatable, htmlOptions: HTMLOptions = {}, makeHead: ( ctx: BaseContext, title: string, options: HTMLOptions ) => Templatable = defaultHead ): Readable { ctx.set("content-type", "text/html;charset=utf-8"); return tempstream/* HTML */ ` ${makeHead(ctx, title, htmlOptions)} ${(htmlOptions.navbar || default_navbar)(ctx)} ${body} ${htmlOptions.autoRefreshCSS ? /* HTML */ `` : ""} `; }