import type { RuntimeConfig, SeoData } from '../../types.ts' import { deviceClassBootScript } from '../../utilities/device.ts' import { editorSizeBootScript } from '../../utilities/editor-size.ts' import { escapeHtml } from '../../utilities/html.ts' import { toText } from '../../utilities/string.ts' import { themeBootScript } from '../../utilities/theme.ts' interface HeadOptions { title: string seo: SeoData themeEnabled: boolean themeDefault: unknown i18nRedirectScript: string cssHref: string stylesheets?: string[] faviconHref: string config?: RuntimeConfig } function renderSeoMeta(seo: SeoData = {}): string { return ['keywords', 'description'] .map((name) => { const content = toText(seo[name]).trim() return content ? ` ` : '' }) .filter(Boolean) .join('\n') } export function renderHead({ title, seo, themeEnabled, themeDefault, i18nRedirectScript, cssHref, stylesheets = [], faviconHref, config, }: HeadOptions): string { const seoMeta = renderSeoMeta(seo) const deviceBootScript = deviceClassBootScript() const editorBootScript = editorSizeBootScript(config) const pageStylesheets = stylesheets .map((href) => ` `) .join('\n') return ` ${escapeHtml(title)} ${seoMeta ? `${seoMeta}\n` : ''} ${pageStylesheets ? `${pageStylesheets}\n` : ''} ` }