strona-czynna/src/back/defaultHead.tsx
Kuba Orlik ee2368c686 add a11y css to project when not in prod mode
Summary: Ref T3078

Reviewers: kuba-orlik

Maniphest Tasks: T3078

Differential Revision: https://hub.sealcode.org/D1687
2026-03-26 18:58:03 +01:00

64 lines
2.0 KiB
TypeScript

import { tempstream } from "tempstream";
import type { Readable } from "stream";
import type { Context } from "koa";
import type { HTMLOptions } from "@sealcode/sealgen";
import { htmlEscape } from "escape-goat";
import { SCAN_A11Y } from "./config.js";
export const start_timestamp = Date.now();
export function defaultHead({
ctx,
title,
htmlOptions,
metaImage,
canonicalPath,
css_clumps = [],
description = "",
}: {
ctx: Context;
title: string | Promise<string | Readable>;
htmlOptions: Partial<HTMLOptions>;
metaImage?: string;
canonicalPath?: string;
css_clumps: string[];
description: string;
}): JSX.Element | Readable {
const origin = ctx.URL.origin;
return tempstream /* HTML */ `<meta charset="utf-8" /> <title>${title}</title>
${SCAN_A11Y ? `<link rel="stylesheet" href="/dist/a11y.css/a11y-en.css">` : ""}
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="${htmlEscape(description)}" />
${ctx.$app.getFeedHTMLMetatags(ctx)}
<script defer src="/dist/bundle.js?v=${start_timestamp}"></script>
${metaImage
? `<meta property="og:image" content="${metaImage.startsWith("/") ? origin + metaImage : metaImage}" />`
: ""}
${[
"default",
"page",
...(ctx.url.includes("/dowodzenie/") ? ["admin"] : []),
...css_clumps,
].map(
(clump_name) =>
/* HTML */ `<link
href="/dist/${clump_name}.entrypoint.css?v=${start_timestamp}${htmlOptions.autoRefreshCSS
? `?${Math.random()}${Math.random()}`
: ""}"
rel="stylesheet"
type="text/css"
/>`
)}
<link href="/dist/fonts/fonts.css" rel="stylesheet" type="text/css" />
${canonicalPath
? `<link rel="canonical" href="${origin}${canonicalPath}" />`
: ""}
${htmlOptions.morphing
? `<meta name="turbo-refresh-method" content="morph" />`
: ""}
${htmlOptions.preserveScroll
? `<meta name="turbo-refresh-scroll" content="preserve">`
: ""} `;
}