我最近正在玩新的 deno 框架,它非常棒,但在某些时候我意识到不可能向页面头标签添加任何额外的元数据。基本上我想做两件事:
您知道如何实现这一目标吗?在理想的世界中,我希望能够提供我自己的 html 模板,或者至少有一些灵活的方式来操作提供的固定模板。我确实在 Fresh 源文件中找到了一些代码片段,基本上是前面提到的固定 html 模板,但不幸的是,它对我来说看起来不可自定义 - 只有变量元素是opts.headComponents,但我不确定是否可以影响它。
export interface TemplateOptions {
bodyHtml: string;
headComponents: ComponentChildren[];
imports: (readonly [string, string])[];
styles: string[];
preloads: string[];
lang: string;
}
export function template(opts: TemplateOptions): string {
const page = (
<html lang={opts.lang}>
<head>
<meta charSet="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
{opts.preloads.map((src) => <link rel="modulepreload" href={src} />)}
{opts.imports.map(([src, nonce]) => (
<script src={src} nonce={nonce} type="module"></script>
))}
<style
id="__FRSH_STYLE"
dangerouslySetInnerHTML={{ …Run Code Online (Sandbox Code Playgroud)