import { getThread } from '../api.js'; import { threads } from '../store.js'; import { esc } from '../util.js'; export async function renderThread({ params }) { const t = await getThread(params.slug); const tabs = threads().map((x) => `${esc(x.title)}`).join(''); const detailCount = t.nodes.reduce((sum, n) => sum + (n.details?.length || 0), 0); const whenText = (value) => { if (!value) return ''; if (/^\d+$/.test(value)) return `${value} 年`; if (/^前\d+$/.test(value)) return `公元前 ${value.slice(1)} 年`; return value; }; const nodes = t.nodes.map((n) => { const details = (n.details || []).map((d) => `
${esc(n.text)}
${details ? `依据${esc(n.source)}
` : ''} ${n.dynasty ? `${esc(n.dynastyName)} · ${esc(n.period)} →` : ''}沿革 · 按朝代分节 · ${t.nodes.length} 个节点 · ${detailCount} 条细释
${esc(t.question)}
${esc(t.summary)}