import { escapeHtml, escapeAttr, formatDateTime, cleanText, stripMarkdown, b64EncodeUtf8 } from "./utils.js"; const DEFAULT_SITE_NAME_ZH = "萌芽小窝"; const DEFAULT_SITE_NAME_EN = "SproutBlog"; export function siteNameZh(env) { return cleanText(env?.SITE_TITLE) || DEFAULT_SITE_NAME_ZH; } export function siteNameEn(env) { return cleanText(env?.SITE_TITLE_EN) || DEFAULT_SITE_NAME_EN; } export function pageTitle(env, suffix = "") { const site = siteNameZh(env); return suffix ? `${site} - ${suffix}` : site; } export function renderLayout(title, body, env, options = {}) { const siteZh = siteNameZh(env); const siteEn = siteNameEn(env); const cwdPostSlug = options.cwdPostSlug ? String(options.cwdPostSlug) : ""; const cwdApiBase = cleanText(env?.CWD_API_BASE) || "https://cwd.api.smyhub.com"; const cwdSiteId = cleanText(env?.CWD_SITE_ID); const cwdSection = cwdPostSlug ? `

评论

` : ""; const mdHead = options.markdownPage ? ` ` : ""; const mdScript = options.markdownPage ? `\n ` : ""; const cwdScripts = cwdPostSlug ? ` ` : ""; return ` ${escapeHtml(title)} ${mdHead}
${body} ${cwdSection}
${mdScript}${cwdScripts} `; } export function renderPostCard(post) { const excerpt = post.excerpt || stripMarkdown(post.content).slice(0, 180); const views = Number(post.view_count) || 0; return `

${escapeHtml(post.title)}

${escapeHtml(excerpt)}${excerpt.length >= 180 ? "…" : ""}

创建于:${formatDateTime(post.created_at)} 最后更新于:${formatDateTime(post.updated_at)} 浏览 ${views}

`; } export function renderAdminCard(post) { return `

${escapeHtml(post.title)}

ID: ${post.id} | Slug: ${escapeHtml(post.slug)} | ${post.published ? "已发布" : "草稿"} | ${formatDateTime(post.updated_at)}

编辑
`; } export function markdownPlaceholder(raw) { const src = String(raw ?? ""); if (!src.trim()) return ""; const b64 = b64EncodeUtf8(src); return `

加载中…

`; }