初始化政体志子站
收录 zhengquan-site 前后端完整代码:24 朝数据、24 幅权力结构图、 5 条沿革(67 节点 / 269 条细释)、44 个词条,以及部署配置与接口测试。
This commit is contained in:
commit
aa12b9f910
58 files changed
+16253
No files matched your search
@@ -0,0 +1,56 @@
|
||||
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) =>
|
||||
`<a class="tab${x.slug === t.slug ? ' active' : ''}" href="#/thread/${esc(x.slug)}">${esc(x.title)}</a>`).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) => `
|
||||
<div class="jdetail">
|
||||
<dt>${esc(d.label)}</dt>
|
||||
<dd>${esc(d.text)}</dd>
|
||||
</div>`).join('');
|
||||
return `
|
||||
<li class="jnode">
|
||||
<div class="jnode-head">
|
||||
<span class="jyear">${esc(n.year)}</span>
|
||||
${n.era && n.era !== n.year ? `<span class="jera">${esc(n.era)}</span>` : ''}
|
||||
${n.when ? `<span class="jwhen">${esc(whenText(n.when))}</span>` : ''}
|
||||
</div>
|
||||
<div class="jcard">
|
||||
<h3 class="jtitle">${esc(n.title)}</h3>
|
||||
<p class="jtext">${esc(n.text)}</p>
|
||||
${details ? `<dl class="jdetails">${details}</dl>` : ''}
|
||||
${n.source ? `<p class="jsource"><span>依据</span>${esc(n.source)}</p>` : ''}
|
||||
${n.dynasty ? `<a class="jdyn" href="#/dynasty/${esc(n.dynasty)}">${esc(n.dynastyName)} · ${esc(n.period)} →</a>` : ''}
|
||||
</div>
|
||||
</li>`;
|
||||
}).join('');
|
||||
|
||||
const html = `
|
||||
<nav class="crumb"><a href="#/">总目</a><span>/</span><a href="#/threads">沿革</a><span>/</span>${esc(t.title)}</nav>
|
||||
<header class="thread-hero" style="--tc:${esc(t.color)}">
|
||||
<p class="kicker">沿革 · 按朝代分节 · ${t.nodes.length} 个节点 · ${detailCount} 条细释</p>
|
||||
<h1>${esc(t.title)}</h1>
|
||||
<p class="thread-q">${esc(t.question)}</p>
|
||||
<p class="thread-summary">${esc(t.summary)}</p>
|
||||
<nav class="thread-tabs" aria-label="沿革专线">${tabs}</nav>
|
||||
</header>
|
||||
<ol class="journey" style="--tc:${esc(t.color)}">${nodes}</ol>
|
||||
`;
|
||||
|
||||
return { html, title: `${t.title}沿革` };
|
||||
}
|
||||
Reference in new issue
Block a user