From 1b7e1144600de21d3356b3bcecda7bee8911cf9b Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Sun, 11 Feb 2024 14:11:14 +0100 Subject: [PATCH] Fix old styles being visible, remove flash of unstyled content --- src/back/html.ts | 70 ++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/src/back/html.ts b/src/back/html.ts index 2c8c77e..bb2d07e 100644 --- a/src/back/html.ts +++ b/src/back/html.ts @@ -4,12 +4,24 @@ 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) => /* HTML */ ` - ${title} · ${ctx.$app.manifest.name} - +export const defaultHead = ( + ctx: BaseContext, + title: string, + options: HTMLOptions +) => /* HTML */ `${title} · ${ctx.$app.manifest.name} - `; + + ${options.morphing ? `` : ""} + ${options.preserveScroll + ? `` + : ""}`; export type HTMLOptions = { preserveScroll?: boolean; @@ -22,22 +34,22 @@ export default function html( ctx: BaseContext, title: string, body: Templatable, - { preserveScroll, morphing, navbar, autoRefreshCSS }: HTMLOptions = {}, - makeHead: (ctx: BaseContext, title: string) => Templatable = defaultHead + 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)} - ${morphing ? `` : ""} - ${preserveScroll - ? `` - : ""} + ${makeHead(ctx, title, htmlOptions)} - ${(navbar || default_navbar)(ctx)} ${body} - ${autoRefreshCSS + ${(htmlOptions.navbar || default_navbar)(ctx)} ${body} + ${htmlOptions.autoRefreshCSS ? /* HTML */ `` : ""}