import type { SunsetConfig } from "./db"; function esc(s: string): string { return s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]!)); } export function renderSunsetPage(opts: { domain: string; target: string; preservePath: boolean; reqPath: string; cfg: SunsetConfig; }): string { const title = opts.cfg.title || "Diese Domain wird abgeschaltet"; const message = opts.cfg.message || `Die Domain ${opts.domain} wird abgeschaltet. Bitte aktualisiere deine Lesezeichen.`; const button = opts.cfg.button_label || "Weiter"; const date = opts.cfg.sunset_date ? `Geplante Abschaltung: ${opts.cfg.sunset_date}` : ""; const continueUrl = (() => { const sep = opts.target.includes("?") ? "&" : "?"; const base = opts.preservePath ? opts.target + (opts.reqPath || "") : opts.target; // Avoid mangling paths that already have query — only append nothing extra; just go to target as-is return base; })(); return ` ${esc(title)}

${esc(title)}

${esc(message)}

${date ? `

${esc(date)}

` : ""} ${esc(button)}

${esc(opts.domain)} → ${esc(opts.target)}

`; }