brf/server/templates/public.ts
2025-12-13 21:12:08 +01:00

44 lines
1.4 KiB
TypeScript

import html from '../lib/html.ts'
interface Options {
content: string
css: string[]
head: Promise<{
title?: string
tags?: {
type: string
attributes: Record<string, string>
}[]
}>
preload?: string[]
script: string
state: Promise<Record<string, any>>
}
export default ({ content, css, head, preload, script, state }: Options) => html`<!DOCTYPE html>
<html lang='sv-SE'>
<head>
<link rel="icon" href="/favicon.svg" />
<script type="module" src="${script}"></script>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="robots" content="index, follow" />
${css?.map((href) => `<link rel='stylesheet' crossorigin href='${href}'>`)}
${preload?.map((href) => `<link rel='modulepreload' crossorigin href='${href}'>`)}
<title>${head?.then((head) => head.title)}</title>
${head?.then((head) =>
head.tags?.map(
(tag) =>
`<${tag.type} ${Object.entries(tag.attributes)
.map(([name, content]) => `${name}='${content}'`)
.join(' ')}/>`,
),
)}
</head>
<body>
${content}
${state?.then((state) => `<script>window.__STATE__ = ${JSON.stringify(state)}</script>`)}
<script>var offset=window.history.state&&window.history.state.scrollTop||0;if(offset)window.scrollTo(0,offset)</script>
</body>
</html>`