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(d.label)}
${esc(d.text)}
`).join(''); return `
  • ${esc(n.year)} ${n.era && n.era !== n.year ? `${esc(n.era)}` : ''} ${n.when ? `${esc(whenText(n.when))}` : ''}

    ${esc(n.title)}

    ${esc(n.text)}

    ${details ? `
    ${details}
    ` : ''} ${n.source ? `

    依据${esc(n.source)}

    ` : ''} ${n.dynasty ? `${esc(n.dynastyName)} · ${esc(n.period)} →` : ''}
  • `; }).join(''); const html = `

    沿革 · 按朝代分节 · ${t.nodes.length} 个节点 · ${detailCount} 条细释

    ${esc(t.title)}

    ${esc(t.question)}

    ${esc(t.summary)}

      ${nodes}
    `; return { html, title: `${t.title}沿革` }; }