Summary: -- Reviewers: #reviewers Subscribers: jenkins-user Differential Revision: https://hub.sealcode.org/D1606
68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import type { HTMLArgs, HTMLOptions } from "@sealcode/sealgen";
|
|
import { tempstreamAsync } from "tempstream";
|
|
import type { Readable } from "stream";
|
|
import { toKebabCase } from "js-convert-case";
|
|
import { DEFAULT_HTML_LANG } from "./config.js";
|
|
import { default_navbar } from "./routes/common/navbar.js";
|
|
import { defaultHead } from "./defaultHead.js";
|
|
|
|
const default_html_options: Partial<HTMLOptions> = {
|
|
showFooter: true,
|
|
showBottomNavbar: true,
|
|
loadHamburgerMenu: true,
|
|
loadSearchModal: true,
|
|
};
|
|
|
|
export default function html({
|
|
ctx,
|
|
title,
|
|
body,
|
|
htmlOptions = {},
|
|
makeHead = defaultHead,
|
|
metaImage,
|
|
canonicalPath,
|
|
css_clumps = [],
|
|
description,
|
|
hideNavigation = false,
|
|
}: HTMLArgs): Readable {
|
|
htmlOptions = { ...default_html_options, ...htmlOptions };
|
|
ctx.set(
|
|
"content-type",
|
|
htmlOptions.canHaveStreams &&
|
|
ctx.get("accept").includes("text/vnd.turbo-stream.html")
|
|
? "text/vnd.turbo-stream.html"
|
|
: "text/html;charset=utf-8"
|
|
);
|
|
|
|
const controllers: string[] = [];
|
|
if (htmlOptions.autoRefreshCSS) {
|
|
controllers.push("refresh-styles");
|
|
controllers.push("refresh-on-ts-changes");
|
|
}
|
|
|
|
return tempstreamAsync /* HTML */ ` <!DOCTYPE html>
|
|
<html
|
|
lang="${htmlOptions.language || DEFAULT_HTML_LANG}"
|
|
class="title--${typeof title == "string" ? toKebabCase(title) : ""}"
|
|
>
|
|
<head>
|
|
${makeHead({
|
|
ctx,
|
|
title: title,
|
|
htmlOptions: { ...htmlOptions },
|
|
metaImage,
|
|
canonicalPath,
|
|
css_clumps,
|
|
description,
|
|
})}
|
|
</head>
|
|
<body
|
|
data-controller="${controllers.join(" ")}"
|
|
class="${(htmlOptions?.bodyClasses || []).join(" ")}"
|
|
>
|
|
${!hideNavigation ? (htmlOptions?.navbar || default_navbar)(ctx) : ""}
|
|
${body}
|
|
</body>
|
|
</html>`;
|
|
}
|