初始化政体志子站
收录 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,48 @@
|
||||
const BASE = '/api';
|
||||
const detailCache = new Map();
|
||||
|
||||
async function request(path, { ttl = 0 } = {}) {
|
||||
if (ttl && detailCache.has(path)) {
|
||||
const hit = detailCache.get(path);
|
||||
if (Date.now() - hit.at < ttl) return hit.value;
|
||||
}
|
||||
const res = await fetch(BASE + path, { headers: { Accept: 'application/json' } });
|
||||
let body = null;
|
||||
try {
|
||||
body = await res.json();
|
||||
} catch {
|
||||
body = null;
|
||||
}
|
||||
if (!res.ok) {
|
||||
const err = new Error(body?.message || `请求失败(${res.status})`);
|
||||
err.status = res.status;
|
||||
throw err;
|
||||
}
|
||||
if (ttl) detailCache.set(path, { at: Date.now(), value: body });
|
||||
return body;
|
||||
}
|
||||
|
||||
let bootPromise = null;
|
||||
|
||||
export function getBootstrap() {
|
||||
if (!bootPromise) {
|
||||
bootPromise = request('/bootstrap').catch((err) => {
|
||||
bootPromise = null;
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
return bootPromise;
|
||||
}
|
||||
|
||||
export const getDynasty = (slug) => request(`/dynasties/${encodeURIComponent(slug)}`, { ttl: 10 * 60 * 1000 });
|
||||
export const getThread = (slug) => request(`/threads/${encodeURIComponent(slug)}`, { ttl: 10 * 60 * 1000 });
|
||||
export const getThreads = () => request('/threads');
|
||||
export const getGlossary = (params = {}) => {
|
||||
const q = new URLSearchParams();
|
||||
if (params.q) q.set('q', params.q);
|
||||
if (params.category) q.set('category', params.category);
|
||||
const s = q.toString();
|
||||
return request(`/glossary${s ? `?${s}` : ''}`);
|
||||
};
|
||||
export const search = (q, limit = 24) =>
|
||||
request(`/search?q=${encodeURIComponent(q)}&limit=${limit}`);
|
||||
@@ -0,0 +1,119 @@
|
||||
import { getBootstrap } from './api.js';
|
||||
import { setBootstrap } from './store.js';
|
||||
import { shell } from './layout.js';
|
||||
import { parseHash, setTitle, scrollTop } from './util.js';
|
||||
import { renderHome } from './views/home.js';
|
||||
import { renderDynasty } from './views/dynasty.js';
|
||||
import { renderThreads } from './views/threads.js';
|
||||
import { renderThread } from './views/thread.js';
|
||||
import { renderGlossary } from './views/glossary.js';
|
||||
import { renderSearch } from './views/search.js';
|
||||
|
||||
const ROUTES = [
|
||||
{ re: /^\/$/, view: renderHome },
|
||||
{ re: /^\/dynasty\/([\w-]+)$/, view: renderDynasty, keys: ['slug'] },
|
||||
{ re: /^\/threads$/, view: renderThreads },
|
||||
{ re: /^\/thread\/([\w-]+)$/, view: renderThread, keys: ['slug'] },
|
||||
{ re: /^\/glossary$/, view: renderGlossary },
|
||||
{ re: /^\/search$/, view: renderSearch },
|
||||
];
|
||||
|
||||
const app = document.getElementById('app');
|
||||
let token = 0;
|
||||
|
||||
function notFound() {
|
||||
return `
|
||||
<div class="error-box">
|
||||
<h1>此卷不存</h1>
|
||||
<p>所寻的页面没有找到。可回到总目,或从检索入手。</p>
|
||||
<a class="btn" href="#/">回到总目</a>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function errorView(message) {
|
||||
return `
|
||||
<div class="error-box">
|
||||
<h1>展卷未成</h1>
|
||||
<p>${message}</p>
|
||||
<a class="btn" href="#/">回到总目</a>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
async function render() {
|
||||
const my = ++token;
|
||||
const { path, query } = parseHash();
|
||||
|
||||
let match = null;
|
||||
for (const route of ROUTES) {
|
||||
const m = path.match(route.re);
|
||||
if (m) {
|
||||
match = { route, m };
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
app.innerHTML = shell(notFound(), path);
|
||||
setTitle(['此卷不存']);
|
||||
scrollTop();
|
||||
return;
|
||||
}
|
||||
|
||||
const params = {};
|
||||
(match.route.keys || []).forEach((key, i) => {
|
||||
params[key] = decodeURIComponent(match.m[i + 1]);
|
||||
});
|
||||
|
||||
app.style.opacity = '.55';
|
||||
try {
|
||||
const result = await match.route.view({ params, query });
|
||||
if (my !== token) return;
|
||||
app.innerHTML = shell(result.html, path);
|
||||
app.style.opacity = '';
|
||||
setTitle([result.title]);
|
||||
if (typeof result.mount === 'function') result.mount();
|
||||
scrollTop();
|
||||
} catch (err) {
|
||||
if (my !== token) return;
|
||||
console.error(err);
|
||||
app.style.opacity = '';
|
||||
app.innerHTML = shell(errorView(err.status === 404 ? '这一卷尚付阙如,或已被移置别处。' : '数据读取失败,请稍后再试。'), path);
|
||||
setTitle(['展卷未成']);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('submit', (e) => {
|
||||
const form = e.target.closest('[data-quick-search]');
|
||||
if (!form) return;
|
||||
e.preventDefault();
|
||||
const q = form.querySelector('input[name="q"]')?.value.trim();
|
||||
if (q) location.hash = `#/search?q=${encodeURIComponent(q)}`;
|
||||
else location.hash = '#/search';
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', (e) => {
|
||||
const typing = /^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement?.tagName || '');
|
||||
if ((e.key === '/' && !typing) || ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k')) {
|
||||
e.preventDefault();
|
||||
const input = document.querySelector('[data-quick-search] input');
|
||||
input?.focus();
|
||||
input?.select();
|
||||
}
|
||||
if (e.key === 'Escape' && document.activeElement?.matches('[data-quick-search] input')) {
|
||||
document.activeElement.blur();
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('hashchange', render);
|
||||
|
||||
(async function boot() {
|
||||
try {
|
||||
const data = await getBootstrap();
|
||||
setBootstrap(data);
|
||||
await render();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
app.innerHTML = shell(errorView('与数据服务的连接中断。请确认后端已启动,然后刷新页面。'), '/');
|
||||
setTitle(['连接中断']);
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,68 @@
|
||||
import { site } from './store.js';
|
||||
import { esc } from './util.js';
|
||||
|
||||
const NAV = [
|
||||
{ key: '', href: '#/', label: '总览' },
|
||||
{ key: 'threads', href: '#/threads', label: '沿革' },
|
||||
{ key: 'glossary', href: '#/glossary', label: '词典' },
|
||||
];
|
||||
|
||||
function activeKey(path) {
|
||||
const seg = path.split('/').filter(Boolean)[0] || '';
|
||||
if (seg === 'dynasty') return '';
|
||||
if (seg === 'thread') return 'threads';
|
||||
return seg;
|
||||
}
|
||||
|
||||
export function header(path) {
|
||||
const s = site();
|
||||
const key = activeKey(path);
|
||||
const nav = NAV.map((item) => {
|
||||
const cls = item.key === key ? ' class="active"' : '';
|
||||
return `<a href="${item.href}"${cls}>${item.label}</a>`;
|
||||
}).join('');
|
||||
|
||||
return `
|
||||
<header class="topbar">
|
||||
<div class="topbar-inner">
|
||||
<a class="brand" href="#/" aria-label="${esc(s.brand)} ${esc(s.name)} 首页">
|
||||
<span class="seal" aria-hidden="true">${esc(s.seal)}</span>
|
||||
<span class="brand-text"><b>${esc(s.brand)}</b><i>${esc(s.name)}</i></span>
|
||||
</a>
|
||||
<nav class="nav" aria-label="主导航">${nav}</nav>
|
||||
<div class="top-actions">
|
||||
<form class="quick-search" data-quick-search role="search">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>
|
||||
<input name="q" type="search" placeholder="检索全志" aria-label="检索朝代、机构、制度与词条" autocomplete="off" />
|
||||
<kbd>/</kbd>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</header>`;
|
||||
}
|
||||
|
||||
export function footer() {
|
||||
return `
|
||||
<footer class="site-foot">
|
||||
<div class="foot-inner">
|
||||
<div>
|
||||
<p class="fslogan">国体为本,官制为骨</p>
|
||||
<p class="fmeta">
|
||||
舆纪历史 编 · © 2026 incarnation.cn ·
|
||||
<a href="https://beian.miit.gov.cn" target="_blank" rel="noopener">冀ICP备2026017366号-1</a> ·
|
||||
<a href="https://incarnation.cn/terms.html" target="_blank" rel="noopener">版权与条款</a>
|
||||
</p>
|
||||
</div>
|
||||
<nav class="foot-links" aria-label="舆纪各站">
|
||||
<a href="https://incarnation.cn/" target="_blank" rel="noopener">总站</a>
|
||||
<a href="https://lishi.incarnation.cn" target="_blank" rel="noopener">历史事件地图</a>
|
||||
<a href="https://wenwu.incarnation.cn" target="_blank" rel="noopener">流失文物档案</a>
|
||||
<a href="https://ditu.incarnation.cn" target="_blank" rel="noopener">历史地图</a>
|
||||
</nav>
|
||||
</div>
|
||||
</footer>`;
|
||||
}
|
||||
|
||||
export function shell(inner, path) {
|
||||
return header(path) + `<main class="wrap page fade-in">${inner}</main>` + footer();
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
import { esc } from './util.js';
|
||||
|
||||
const NAME = 15;
|
||||
const ROOT_NAME = 17;
|
||||
const NOTE = 11;
|
||||
const CHIP = 11.5;
|
||||
const CHIP_H = 17;
|
||||
const CHIP_GAP = 4;
|
||||
const ROW_H = 19;
|
||||
const PAD_TOP = 9;
|
||||
const MAX_W = 268;
|
||||
const MIN_W = 92;
|
||||
const MIN_ROOT = 150;
|
||||
const GAP_X = 18;
|
||||
const GAP_Y = 46;
|
||||
const CANVAS = 18;
|
||||
|
||||
function textWidth(text, size) {
|
||||
let w = 0;
|
||||
for (const ch of String(text)) {
|
||||
if (/[\u4e00-\u9fa5]/.test(ch)) w += size;
|
||||
else if (/[A-Za-z0-9]/.test(ch)) w += size * 0.56;
|
||||
else if (ch === '·' || ch === '—' || ch === '(' || ch === ')') w += size * 0.92;
|
||||
else w += size * 0.46;
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
function build(raw, depth, isRoot) {
|
||||
const node = {
|
||||
...raw,
|
||||
depth,
|
||||
isRoot,
|
||||
nameSize: isRoot ? ROOT_NAME : NAME,
|
||||
children: (raw.children || []).map((c) => build(c, depth + 1, false)),
|
||||
};
|
||||
|
||||
const nameW = textWidth(node.name, node.nameSize);
|
||||
const noteW = node.note ? textWidth(node.note, NOTE) : 0;
|
||||
const chips = (node.items || []).map((text) => ({
|
||||
text,
|
||||
w: textWidth(text, CHIP) + 14,
|
||||
}));
|
||||
|
||||
const rows = [];
|
||||
let row = [];
|
||||
let rowW = 0;
|
||||
let maxRowW = 0;
|
||||
for (const chip of chips) {
|
||||
if (row.length && rowW + CHIP_GAP + chip.w > MAX_W - 24) {
|
||||
rows.push({ items: row, w: rowW });
|
||||
maxRowW = Math.max(maxRowW, rowW);
|
||||
row = [];
|
||||
rowW = 0;
|
||||
}
|
||||
rowW += (row.length ? CHIP_GAP : 0) + chip.w;
|
||||
row.push(chip);
|
||||
}
|
||||
if (row.length) {
|
||||
rows.push({ items: row, w: rowW });
|
||||
maxRowW = Math.max(maxRowW, rowW);
|
||||
}
|
||||
|
||||
node.rows = rows;
|
||||
node.w = Math.max(isRoot ? MIN_ROOT : MIN_W, nameW + 26, noteW + 20, maxRowW + 24);
|
||||
node.w = Math.min(node.w, MAX_W);
|
||||
node.h = PAD_TOP + 21 + (node.note ? 14 : 0) + (rows.length ? rows.length * ROW_H + 4 : 0) + 9;
|
||||
|
||||
const childTotal = node.children.length
|
||||
? node.children.reduce((sum, c) => sum + c.sw, 0) + GAP_X * (node.children.length - 1)
|
||||
: 0;
|
||||
node.sw = Math.max(node.w, childTotal);
|
||||
return node;
|
||||
}
|
||||
|
||||
function walk(node, fn) {
|
||||
fn(node);
|
||||
for (const child of node.children) walk(child, fn);
|
||||
}
|
||||
|
||||
function linkPath(parent, child) {
|
||||
const x1 = parent.x + parent.w / 2;
|
||||
const y1 = parent.y + parent.h;
|
||||
const x2 = child.x + child.w / 2;
|
||||
const y2 = child.y;
|
||||
const mid = y1 + (y2 - y1) / 2;
|
||||
if (Math.abs(x2 - x1) < 1) return `M${x1} ${y1}V${y2}`;
|
||||
const r = 7;
|
||||
const dir = x2 > x1 ? 1 : -1;
|
||||
return `M${x1} ${y1}V${mid - r}Q${x1} ${mid} ${x1 + dir * r} ${mid}H${x2 - dir * r}Q${x2} ${mid} ${x2} ${mid + r}V${y2}`;
|
||||
}
|
||||
|
||||
function nodeSvg(node) {
|
||||
const chipsY = PAD_TOP + 21 + (node.note ? 14 : 0) + 3;
|
||||
const nameY = PAD_TOP + (node.isRoot ? 17 : 15);
|
||||
const parts = [];
|
||||
|
||||
parts.push(`<text class="oc-name" x="${node.w / 2}" y="${nameY}" text-anchor="middle" font-size="${node.nameSize}">${esc(node.name)}</text>`);
|
||||
if (node.note) {
|
||||
parts.push(`<text class="oc-note" x="${node.w / 2}" y="${PAD_TOP + 31}" text-anchor="middle" font-size="${NOTE}">${esc(node.note)}</text>`);
|
||||
}
|
||||
|
||||
let y = chipsY;
|
||||
for (const row of node.rows) {
|
||||
let x = (node.w - row.w) / 2;
|
||||
for (const chip of row.items) {
|
||||
parts.push(`<g class="oc-chip"><rect x="${x.toFixed(1)}" y="${y}" width="${chip.w.toFixed(1)}" height="${CHIP_H}" rx="2"/><text x="${(x + chip.w / 2).toFixed(1)}" y="${y + 12}" text-anchor="middle" font-size="${CHIP}">${esc(chip.text)}</text></g>`);
|
||||
x += chip.w + CHIP_GAP;
|
||||
}
|
||||
y += ROW_H;
|
||||
}
|
||||
|
||||
const cls = node.isRoot ? 'oc-node oc-root' : `oc-node oc-${node.tone || 'plain'}`;
|
||||
return `<g class="${cls}" transform="translate(${node.x.toFixed(1)} ${node.y.toFixed(1)})"><rect width="${node.w.toFixed(1)}" height="${node.h.toFixed(1)}" rx="3"/>${parts.join('')}</g>`;
|
||||
}
|
||||
|
||||
function treeList(node) {
|
||||
const cls = ['om-node', node.isRoot ? 'root' : '', node.tone || ''].filter(Boolean).join(' ');
|
||||
const items = (node.items || []).length
|
||||
? `<div class="om-items">${node.items.map((i) => `<span>${esc(i)}</span>`).join('')}</div>`
|
||||
: '';
|
||||
const kids = node.children.length ? `<ul>${node.children.map(treeList).join('')}</ul>` : '';
|
||||
return `<li><div class="${cls}"><span class="om-name">${esc(node.name)}</span>${node.note ? `<span class="om-note">${esc(node.note)}</span>` : ''}${items}</div>${kids}</li>`;
|
||||
}
|
||||
|
||||
export function chartHtml(chart) {
|
||||
if (!chart?.root) return '';
|
||||
|
||||
const root = build(chart.root, 0, true);
|
||||
const depthMax = [];
|
||||
walk(root, (node) => {
|
||||
depthMax[node.depth] = Math.max(depthMax[node.depth] || 0, node.h);
|
||||
});
|
||||
|
||||
const rowY = [];
|
||||
let y = CANVAS;
|
||||
depthMax.forEach((h, depth) => {
|
||||
rowY[depth] = y;
|
||||
y += h + GAP_Y;
|
||||
});
|
||||
const height = Math.ceil(y - GAP_Y + CANVAS);
|
||||
|
||||
function place(node, left) {
|
||||
node.x = left + (node.sw - node.w) / 2;
|
||||
node.y = rowY[node.depth];
|
||||
if (node.children.length) {
|
||||
const total = node.children.reduce((sum, c) => sum + c.sw, 0) + GAP_X * (node.children.length - 1);
|
||||
let cursor = left + (node.sw - total) / 2;
|
||||
for (const child of node.children) {
|
||||
place(child, cursor);
|
||||
cursor += child.sw + GAP_X;
|
||||
}
|
||||
}
|
||||
}
|
||||
place(root, CANVAS);
|
||||
|
||||
const width = Math.ceil(root.sw + CANVAS * 2);
|
||||
const nodes = [];
|
||||
const links = [];
|
||||
walk(root, (node) => {
|
||||
nodes.push(nodeSvg(node));
|
||||
for (const child of node.children) {
|
||||
const dashed = child.dashed || child.tone === 'watch' || child.tone === 'local';
|
||||
links.push(`<path class="oc-link${dashed ? ' dashed' : ''}" d="${linkPath(node, child)}"/>`);
|
||||
}
|
||||
});
|
||||
|
||||
return `
|
||||
<div class="org-chart-panel">
|
||||
<div class="org-chart-head">
|
||||
<p class="oc-title">结构图<em>ORG CHART</em></p>
|
||||
<div class="oc-legend" aria-label="图例">
|
||||
<span><i class="lg-line"></i>统属</span>
|
||||
<span><i class="lg-line dash"></i>监察 / 派出 / 地方</span>
|
||||
<span><i class="lg-box core"></i>中枢</span>
|
||||
<span><i class="lg-box watch"></i>监察</span>
|
||||
<span><i class="lg-box local"></i>地方</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="org-chart-view">
|
||||
<div class="org-chart-scroll" tabindex="0" role="group" aria-label="可横向滚动的结构图">
|
||||
<svg class="org-svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" role="img" aria-label="${esc(chart.caption || '政权组织架构图')}">
|
||||
${links.join('')}
|
||||
${nodes.join('')}
|
||||
</svg>
|
||||
</div>
|
||||
<button class="oc-nav oc-nav-prev" type="button" aria-label="向左查看结构图">‹</button>
|
||||
<button class="oc-nav oc-nav-next" type="button" aria-label="向右查看结构图">›</button>
|
||||
</div>
|
||||
<div class="org-mobile-tree"><ul>${treeList(root)}</ul></div>
|
||||
<p class="org-chart-caption">${esc(chart.caption || '')}<span class="oc-hint">图为权力关系简示,不表示品级高低;具体职掌见下方逐层说明。</span><span class="oc-swipe">图较宽,共 ${root.children.length} 个分支;可按住左右拖动,或用两侧箭头查看全图。</span><span class="oc-mobile-hint">按隶属关系缩进;金底为中枢,绿底为监察,虚线框为地方。</span></p>
|
||||
</div>`;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
let boot = null;
|
||||
|
||||
export function setBootstrap(data) {
|
||||
boot = data;
|
||||
}
|
||||
|
||||
export const getBoot = () => boot;
|
||||
|
||||
export const site = () => boot?.site || { brand: '舆纪历史', name: '政体志', seal: '制' };
|
||||
export const eras = () => boot?.eras || [];
|
||||
export const dynasties = () => boot?.dynasties || [];
|
||||
export const threads = () => boot?.threads || [];
|
||||
export const stats = () => boot?.stats || {};
|
||||
|
||||
export const eraOf = (id) => eras().find((e) => e.id === id) || null;
|
||||
export const eraColor = (id) => eraOf(id)?.color || '#8a6320';
|
||||
export const dynastyOf = (slug) => dynasties().find((d) => d.slug === slug) || null;
|
||||
|
||||
export function indexOf(slug) {
|
||||
return dynasties().findIndex((d) => d.slug === slug);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
export function esc(value) {
|
||||
return String(value ?? '')
|
||||
.replaceAll('&', '&')
|
||||
.replaceAll('<', '<')
|
||||
.replaceAll('>', '>')
|
||||
.replaceAll('"', '"')
|
||||
.replaceAll("'", ''');
|
||||
}
|
||||
|
||||
export const fmtYear = (y) => (y < 0 ? `前${Math.abs(y)}` : String(y));
|
||||
|
||||
export const fmtNum = (n) => Number(n || 0).toLocaleString('zh-CN');
|
||||
|
||||
export function truncate(text, max = 26) {
|
||||
const s = String(text || '');
|
||||
return s.length > max ? s.slice(0, max) + '…' : s;
|
||||
}
|
||||
|
||||
export function highlight(text, query) {
|
||||
const safe = esc(text);
|
||||
const q = String(query || '').trim();
|
||||
if (!q) return safe;
|
||||
const terms = [...new Set(q.split(/\s+/).filter(Boolean))].map((t) => esc(t)).filter(Boolean);
|
||||
if (!terms.length) return safe;
|
||||
let out = safe;
|
||||
for (const t of terms.sort((a, b) => b.length - a.length)) {
|
||||
out = out.replaceAll(t, `<mark>${t}</mark>`);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function parseHash() {
|
||||
const raw = location.hash.replace(/^#/, '') || '/';
|
||||
const [pathPart, queryPart] = raw.split('?');
|
||||
const path = pathPart || '/';
|
||||
return { path, query: new URLSearchParams(queryPart || '') };
|
||||
}
|
||||
|
||||
export function scrollTop() {
|
||||
const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
window.scrollTo({ top: 0, behavior: reduce ? 'auto' : 'smooth' });
|
||||
}
|
||||
|
||||
export function setTitle(parts) {
|
||||
const list = [...parts.filter(Boolean), '舆纪历史 · 政体志'];
|
||||
document.title = list.join('|');
|
||||
}
|
||||
|
||||
export function markClass(name) {
|
||||
const n = [...String(name)].length;
|
||||
if (n >= 6) return 'long2';
|
||||
if (n >= 4) return 'long';
|
||||
return '';
|
||||
}
|
||||
|
||||
/** 把「中书省 · 门下省」这类分隔文本拆成标签 */
|
||||
export const splitTags = (text) =>
|
||||
String(text || '')
|
||||
.split(/[·、,,//]/)
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
@@ -0,0 +1,310 @@
|
||||
import { getDynasty } from '../api.js';
|
||||
import { eraOf, eraColor } from '../store.js';
|
||||
import { chartHtml } from '../orgchart.js';
|
||||
import { esc, fmtYear, markClass } from '../util.js';
|
||||
|
||||
function tierHtml(tier, i) {
|
||||
const nodes = tier.nodes.map((n) => {
|
||||
const children = (n.children || []).map((c) =>
|
||||
`<span class="chip" title="${esc(c.duty || '')}">${esc(c.name)}</span>`).join('');
|
||||
return `
|
||||
<article class="node">
|
||||
<div class="node-head">
|
||||
<h4 class="node-name">${esc(n.name)}</h4>
|
||||
${n.note ? `<span class="node-note">${esc(n.note)}</span>` : ''}
|
||||
</div>
|
||||
<p class="node-duty">${esc(n.duty)}</p>
|
||||
${n.chief ? `<p class="node-chief">${esc(n.chief)}</p>` : ''}
|
||||
${children ? `<div class="node-children">${children}</div>` : ''}
|
||||
</article>`;
|
||||
}).join('');
|
||||
|
||||
return `
|
||||
<li class="tier">
|
||||
<div class="tier-head">
|
||||
<span class="tier-no">${String(i + 1).padStart(2, '0')}</span>
|
||||
<h3 class="tier-label">${esc(tier.label)}</h3>
|
||||
<p class="tier-caption">${esc(tier.caption || '')}</p>
|
||||
</div>
|
||||
<div class="tier-body">${nodes}</div>
|
||||
</li>`;
|
||||
}
|
||||
|
||||
function quotesHtml(d) {
|
||||
if (!d.quotes?.length) return '';
|
||||
return d.quotes.map((q) => `
|
||||
<blockquote class="quote">
|
||||
<p class="quote-text">${esc(q.text)}</p>
|
||||
<p class="quote-src">${esc(q.source)}${q.paraphrase ? '<span class="paraphrase">大意</span>' : ''}</p>
|
||||
</blockquote>`).join('');
|
||||
}
|
||||
|
||||
export async function renderDynasty({ params }) {
|
||||
const d = await getDynasty(params.slug);
|
||||
const era = eraOf(d.era);
|
||||
|
||||
const facts = `
|
||||
<dl class="dyn-facts">
|
||||
<div class="fact"><dt>起止</dt><dd>${esc(d.period)}</dd></div>
|
||||
<div class="fact"><dt>都城</dt><dd title="${esc(d.capital)}">${esc(d.capital)}</dd></div>
|
||||
<div class="fact"><dt>开国</dt><dd>${esc(d.founder)}</dd></div>
|
||||
</dl>`;
|
||||
|
||||
const flow = (d.org.flow || []).map((step, i) =>
|
||||
`${i ? '<span class="flow-arrow" aria-hidden="true">→</span>' : ''}<span class="flow-step">${esc(step)}</span>`).join('');
|
||||
|
||||
const instRows = d.institutions.map((it) => `
|
||||
<tr>
|
||||
<td>${esc(it.name)}</td>
|
||||
<td class="c-chief">${esc(it.chief || '—')}</td>
|
||||
<td>${esc(it.duty)}</td>
|
||||
<td class="c-note${it.note ? '' : ' is-empty'}">${it.note ? `<span class="tag">${esc(it.note)}</span>` : '—'}</td>
|
||||
</tr>`).join('');
|
||||
|
||||
const levels = d.local.levels.map((l) => `
|
||||
<div class="level">
|
||||
<p class="level-name">${esc(l.name)}</p>
|
||||
<p class="level-chief">${esc(l.chief)}</p>
|
||||
<p class="level-duty">${esc(l.duty)}</p>
|
||||
</div>`).join('');
|
||||
|
||||
const changes = d.changes.map((c, i) => `
|
||||
<li class="change">
|
||||
<span class="change-no">${String(i + 1).padStart(2, '0')}</span>
|
||||
<div><h3>${esc(c.title)}</h3><p>${esc(c.text)}</p></div>
|
||||
</li>`).join('');
|
||||
|
||||
const prev = d.neighbours?.prev;
|
||||
const next = d.neighbours?.next;
|
||||
const pager = `
|
||||
<nav class="pager" aria-label="前后朝代">
|
||||
${prev ? `<a class="pager-link" href="#/dynasty/${esc(prev.slug)}"><p class="pager-dir">← 前朝</p><p class="pager-name">${esc(prev.name)}<small>${esc(prev.period)}</small></p></a>` : '<span></span>'}
|
||||
${next ? `<a class="pager-link right" href="#/dynasty/${esc(next.slug)}"><p class="pager-dir">后朝 →</p><p class="pager-name">${esc(next.name)}<small>${esc(next.period)}</small></p></a>` : '<span></span>'}
|
||||
</nav>`;
|
||||
|
||||
const related = (d.relatedTerms || []).map((g) =>
|
||||
`<li><a href="#/glossary?q=${encodeURIComponent(g.term)}">${esc(g.term)}</a></li>`).join('');
|
||||
|
||||
const html = `
|
||||
<nav class="crumb"><a href="#/">总目</a><span>/</span><a href="#/" title="${esc(era?.name || '')}">${esc(era?.name || '')}</a><span>/</span>${esc(d.name)}</nav>
|
||||
|
||||
<header class="dyn-head">
|
||||
<div class="dyn-mark ${markClass(d.name)}" style="--era:${eraColor(d.era)}" aria-hidden="true">${esc(d.name)}</div>
|
||||
<div class="dyn-title">
|
||||
<p class="kicker">${esc(era?.name || '')} · ${esc(d.period)}</p>
|
||||
<h1>${esc(d.fullName || d.name)}</h1>
|
||||
<p class="dyn-lede">${esc(d.subtitle)}</p>
|
||||
</div>
|
||||
${facts}
|
||||
</header>
|
||||
|
||||
<section class="dyn-summary">
|
||||
<p class="lede-text">${esc(d.summary)}</p>
|
||||
<div class="dyn-tags">${(d.tags || []).map((t) => `<span class="tag">${esc(t)}</span>`).join('')}</div>
|
||||
</section>
|
||||
|
||||
<section class="sec" id="form">
|
||||
<div class="sec-head">
|
||||
<span class="no">01</span>
|
||||
<h2>国体与政体</h2>
|
||||
<em>STATE & GOVERNMENT</em>
|
||||
<span class="sec-note">谁掌权,权力如何组织</span>
|
||||
</div>
|
||||
<div class="defs">
|
||||
<article class="def-card">
|
||||
<p class="def-label">国 体</p>
|
||||
<p class="def-value">${esc(d.stateForm.value)}</p>
|
||||
<p class="def-note">${esc(d.stateForm.note)}</p>
|
||||
</article>
|
||||
<article class="def-card gov">
|
||||
<p class="def-label">政 体</p>
|
||||
<p class="def-value">${esc(d.govForm.value)}</p>
|
||||
<p class="def-note">${esc(d.govForm.note)}</p>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="sec" id="org">
|
||||
<div class="sec-head">
|
||||
<span class="no">02</span>
|
||||
<h2>中央权力结构</h2>
|
||||
<em>ORG CHART</em>
|
||||
<span class="sec-note">先看结构,再看职掌</span>
|
||||
</div>
|
||||
<div class="flow"><span class="flow-label">权力流向</span>${flow}</div>
|
||||
${d.chart ? chartHtml(d.chart) : ''}
|
||||
<p class="org-note">${esc(d.org.note)}</p>
|
||||
<details class="org-details">
|
||||
<summary><span>逐层职掌</span><em>展开看每一层的机构与职责</em></summary>
|
||||
<ol class="tiers">${(d.org.tiers || []).map(tierHtml).join('')}</ol>
|
||||
</details>
|
||||
</section>
|
||||
|
||||
<section class="sec" id="duties">
|
||||
<div class="sec-head">
|
||||
<span class="no">03</span>
|
||||
<h2>机构职掌</h2>
|
||||
<em>DUTIES</em>
|
||||
<span class="sec-note">凡 ${d.institutions.length} 处</span>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table class="inst-table">
|
||||
<thead><tr><th>机构</th><th>长官</th><th>职掌</th><th>备考</th></tr></thead>
|
||||
<tbody>${instRows}</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="sec" id="local">
|
||||
<div class="sec-head">
|
||||
<span class="no">04</span>
|
||||
<h2>地方制度</h2>
|
||||
<em>LOCAL</em>
|
||||
<span class="sec-note">${esc(d.local.system)}</span>
|
||||
</div>
|
||||
<p class="local-summary">${esc(d.local.summary)}</p>
|
||||
<div class="ladder">${levels}</div>
|
||||
${d.local.note ? `<p class="local-note">${esc(d.local.note)}</p>` : ''}
|
||||
</section>
|
||||
|
||||
<section class="sec" id="checks">
|
||||
<div class="sec-head">
|
||||
<span class="no">05</span>
|
||||
<h2>选官 · 监察 · 军事</h2>
|
||||
<em>SELECTION · SUPERVISION · ARMY</em>
|
||||
<span class="sec-note">人如何进,权如何督,兵如何统</span>
|
||||
</div>
|
||||
<div class="grid-3">
|
||||
<article class="info-card">
|
||||
<h3>选官</h3>
|
||||
<span class="info-sys">${esc(d.selection.system)}</span>
|
||||
<p>${esc(d.selection.text)}</p>
|
||||
</article>
|
||||
<article class="info-card">
|
||||
<h3>监察</h3>
|
||||
<span class="info-sys">${esc(d.supervision.system)}</span>
|
||||
<p>${esc(d.supervision.text)}</p>
|
||||
</article>
|
||||
<article class="info-card">
|
||||
<h3>军事</h3>
|
||||
<span class="info-sys">${esc(d.military.system)}</span>
|
||||
<p>${esc(d.military.text)}</p>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="sec" id="changes">
|
||||
<div class="sec-head">
|
||||
<span class="no">06</span>
|
||||
<h2>沿革要点</h2>
|
||||
<em>CHANGES</em>
|
||||
<span class="sec-note">这一朝改了什么,又留下了什么</span>
|
||||
</div>
|
||||
<ol class="changes">${changes}</ol>
|
||||
</section>
|
||||
|
||||
<section class="sec" id="sources">
|
||||
<div class="sec-head">
|
||||
<span class="no">07</span>
|
||||
<h2>史料与出处</h2>
|
||||
<em>SOURCES</em>
|
||||
<span class="sec-note">引文标出处,概述标大意</span>
|
||||
</div>
|
||||
<div class="quotes">${quotesHtml(d)}</div>
|
||||
<ul class="sources"><span>参考</span>${d.sources.map((s) => `<li>${esc(s)}</li>`).join('')}</ul>
|
||||
${related ? `<ul class="sources"><span>相关词条</span>${related}</ul>` : ''}
|
||||
</section>
|
||||
|
||||
${pager}
|
||||
`;
|
||||
|
||||
return {
|
||||
html,
|
||||
title: `${d.name} · ${d.period}`,
|
||||
mount() {
|
||||
// 结构图较宽时:支持拖动与两侧箭头
|
||||
requestAnimationFrame(() => {
|
||||
document.querySelectorAll('.org-chart-panel').forEach((panel) => {
|
||||
const sc = panel.querySelector('.org-chart-scroll');
|
||||
if (!sc) return;
|
||||
const prev = panel.querySelector('.oc-nav-prev');
|
||||
const next = panel.querySelector('.oc-nav-next');
|
||||
|
||||
const sync = () => {
|
||||
const max = sc.scrollWidth - sc.clientWidth;
|
||||
const scrollable = max > 2;
|
||||
panel.classList.toggle('is-scrollable', scrollable);
|
||||
if (prev) prev.disabled = !scrollable || sc.scrollLeft <= 1;
|
||||
if (next) next.disabled = !scrollable || sc.scrollLeft >= max - 1;
|
||||
};
|
||||
|
||||
// 仅轻微超宽时整体缩到一屏,字号损失有限;明显超宽则保留滚动
|
||||
const svg = panel.querySelector('.org-svg');
|
||||
const overflow = sc.scrollWidth - sc.clientWidth;
|
||||
if (svg && overflow > 2 && overflow <= sc.clientWidth * 0.09) {
|
||||
svg.style.width = `${sc.clientWidth - 14}px`;
|
||||
svg.style.height = 'auto';
|
||||
panel.classList.add('is-shrunk');
|
||||
}
|
||||
|
||||
// 从最左端读起,避免左右两侧同时截断节点;根节点仍在首屏内
|
||||
if (sc.scrollWidth > sc.clientWidth + 2) sc.scrollLeft = 0;
|
||||
sync();
|
||||
|
||||
sc.addEventListener('scroll', sync, { passive: true });
|
||||
const onResize = () => {
|
||||
if (!sc.isConnected) {
|
||||
window.removeEventListener('resize', onResize);
|
||||
return;
|
||||
}
|
||||
sync();
|
||||
};
|
||||
window.addEventListener('resize', onResize, { passive: true });
|
||||
|
||||
prev?.addEventListener('click', () => sc.scrollBy({ left: -sc.clientWidth * 0.62, behavior: 'smooth' }));
|
||||
next?.addEventListener('click', () => sc.scrollBy({ left: sc.clientWidth * 0.62, behavior: 'smooth' }));
|
||||
|
||||
let dragging = false;
|
||||
let startX = 0;
|
||||
let startLeft = 0;
|
||||
let pid = null;
|
||||
|
||||
sc.addEventListener('pointerdown', (e) => {
|
||||
if (e.pointerType === 'touch' || sc.scrollWidth <= sc.clientWidth + 2) return;
|
||||
dragging = true;
|
||||
startX = e.clientX;
|
||||
startLeft = sc.scrollLeft;
|
||||
pid = e.pointerId;
|
||||
panel.classList.add('is-dragging');
|
||||
sc.setPointerCapture?.(pid);
|
||||
});
|
||||
sc.addEventListener('pointermove', (e) => {
|
||||
if (!dragging) return;
|
||||
const dx = e.clientX - startX;
|
||||
if (Math.abs(dx) > 2) {
|
||||
sc.scrollLeft = startLeft - dx;
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
const endDrag = () => {
|
||||
if (!dragging) return;
|
||||
dragging = false;
|
||||
panel.classList.remove('is-dragging');
|
||||
if (pid != null) {
|
||||
try {
|
||||
sc.releasePointerCapture(pid);
|
||||
} catch {
|
||||
/* 指针已释放 */
|
||||
}
|
||||
pid = null;
|
||||
}
|
||||
};
|
||||
sc.addEventListener('pointerup', endDrag);
|
||||
sc.addEventListener('pointercancel', endDrag);
|
||||
sc.addEventListener('pointerleave', endDrag);
|
||||
sc.addEventListener('dragstart', (e) => e.preventDefault());
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import { getGlossary } from '../api.js';
|
||||
import { dynastyOf } from '../store.js';
|
||||
import { esc } from '../util.js';
|
||||
|
||||
const ORDER = ['总纲', '中央', '地方', '选官', '监察', '军事', '近代'];
|
||||
|
||||
export async function renderGlossary({ query }) {
|
||||
const q = (query.get('q') || '').trim();
|
||||
const cat = (query.get('cat') || '').trim();
|
||||
const data = await getGlossary({ q, category: cat });
|
||||
const categories = [...data.categories].sort((a, b) => {
|
||||
const ia = ORDER.indexOf(a);
|
||||
const ib = ORDER.indexOf(b);
|
||||
return (ia < 0 ? 99 : ia) - (ib < 0 ? 99 : ib);
|
||||
});
|
||||
|
||||
const chips = ['', ...categories].map((c) => {
|
||||
const label = c || '全部';
|
||||
const params = new URLSearchParams();
|
||||
if (q) params.set('q', q);
|
||||
if (c) params.set('cat', c);
|
||||
const href = `#/glossary${params.toString() ? '?' + params.toString() : ''}`;
|
||||
return `<a class="chip-btn${c === cat ? ' active' : ''}" href="${href}">${esc(label)}</a>`;
|
||||
}).join('');
|
||||
|
||||
const cards = data.items.map((g) => {
|
||||
const rel = (g.related || [])
|
||||
.map((slug) => dynastyOf(slug))
|
||||
.filter(Boolean)
|
||||
.map((d) => `<a href="#/dynasty/${esc(d.slug)}">${esc(d.name)}</a>`)
|
||||
.join('');
|
||||
const flash = q && g.term === q ? ' flash' : '';
|
||||
return `
|
||||
<article class="term-card${flash}" id="term-${encodeURIComponent(g.term)}">
|
||||
<div class="term-top">
|
||||
<h2 class="term-name">${esc(g.term)}</h2>
|
||||
<span class="term-cat">${esc(g.category)}</span>
|
||||
</div>
|
||||
<p class="term-def">${esc(g.definition)}</p>
|
||||
${rel ? `<div class="term-rel">${rel}</div>` : ''}
|
||||
</article>`;
|
||||
}).join('');
|
||||
|
||||
const html = `
|
||||
<header class="thread-hero">
|
||||
<p class="kicker">词典 · 职官与制度</p>
|
||||
<h1>职官词典</h1>
|
||||
<p class="thread-q">读志先识名。名不辨,则制不明。</p>
|
||||
<p class="thread-summary">国体、政体、三省六部、二府三司、票拟批红、军机处……这些词在正文里反复出现,各有确切的所指与来历。此处按类收词,逐条释义,并附所属朝代,便于前后对照。</p>
|
||||
</header>
|
||||
|
||||
<div class="glossary-tools">
|
||||
<form class="search-form" data-glossary-form role="search" style="margin-top:0;flex:1;min-width:260px">
|
||||
<input class="search-input" type="search" name="q" value="${esc(q)}" placeholder="检索词条,如「三省」" aria-label="检索词条" />
|
||||
${cat ? `<input type="hidden" name="cat" value="${esc(cat)}" />` : ''}
|
||||
<button class="btn" type="submit">检索</button>
|
||||
</form>
|
||||
<span class="term-count">${data.total} 条</span>
|
||||
</div>
|
||||
<div class="glossary-tools" style="border-bottom:0;padding-top:0">
|
||||
<div class="chips">${chips}</div>
|
||||
</div>
|
||||
|
||||
${data.items.length ? `<div class="glossary-grid">${cards}</div>` : '<p class="empty">没有找到匹配的词条。</p>'}
|
||||
`;
|
||||
|
||||
function mount() {
|
||||
const form = document.querySelector('[data-glossary-form]');
|
||||
form?.addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
const val = form.querySelector('input[name="q"]').value.trim();
|
||||
const params = new URLSearchParams();
|
||||
if (val) params.set('q', val);
|
||||
if (cat) params.set('cat', cat);
|
||||
location.hash = `#/glossary${params.toString() ? '?' + params.toString() : ''}`;
|
||||
});
|
||||
if (q) {
|
||||
const target = [...document.querySelectorAll('.term-card')].find((el) => el.querySelector('.term-name')?.textContent === q);
|
||||
target?.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
||||
}
|
||||
}
|
||||
|
||||
return { html, title: q ? `词典 · ${q}` : '职官词典', mount };
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
import { getBoot } from '../store.js';
|
||||
import { dynasties, eras, threads, stats, eraColor } from '../store.js';
|
||||
import { esc, fmtYear, fmtNum } from '../util.js';
|
||||
|
||||
const RAIL_SHORT = {
|
||||
xia: '夏', shang: '商', xizhou: '西周', chunqiu: '春秋', zhanguo: '战国',
|
||||
qin: '秦', 'han-west': '西汉', xinmang: '新', 'han-east': '东汉',
|
||||
sanguo: '三国', xijin: '西晋', dongjin: '东晋', nanbeichao: '南北朝',
|
||||
sui: '隋', tang: '唐', wudai: '五代', shiguo: '十国',
|
||||
song: '北宋', nansong: '南宋', yuan: '元', ming: '明', qing: '清',
|
||||
minguo: '民国', prc: '共和国'
|
||||
};
|
||||
|
||||
function rail() {
|
||||
const items = [];
|
||||
for (const d of dynasties()) {
|
||||
const weight = Math.max(15, d.endYear - d.startYear);
|
||||
items.push(`
|
||||
<a class="rail-seg" href="#/dynasty/${esc(d.slug)}" style="--grow:${weight};--era:${eraColor(d.era)}" title="${esc(d.name)} ${esc(d.period)}">
|
||||
<span class="seg-name">${esc(RAIL_SHORT[d.slug] || d.name)}</span>
|
||||
<span class="seg-years">${fmtYear(d.startYear)}</span>
|
||||
</a>`);
|
||||
}
|
||||
return items.join('');
|
||||
}
|
||||
|
||||
function eraBlocks() {
|
||||
let index = 0;
|
||||
return eras().map((era, eraIndex) => {
|
||||
const rows = dynasties()
|
||||
.filter((d) => d.era === era.id)
|
||||
.map((d) => {
|
||||
index += 1;
|
||||
const tags = (d.tags || []).slice(0, 3).map((t) => `<span class="tag">${esc(t)}</span>`).join('');
|
||||
return `
|
||||
<a class="dyn-row" href="#/dynasty/${esc(d.slug)}">
|
||||
<span class="dyn-no">${String(index).padStart(2, '0')}</span>
|
||||
<span class="dyn-name">${esc(d.name)}<span class="dyn-sub">${esc(d.period)} · ${esc(d.subtitle)}</span></span>
|
||||
<span class="dyn-forms">${tags}</span>
|
||||
<svg class="dyn-arrow" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 17 17 7M8 7h9v9"/></svg>
|
||||
</a>`;
|
||||
}).join('');
|
||||
return `
|
||||
<section class="era-block" id="era-${esc(era.id)}" style="--era:${era.color}">
|
||||
<div class="era-side">
|
||||
<span class="era-no">ERA ${String(eraIndex + 1).padStart(2, '0')}</span>
|
||||
<h3 class="era-name">${esc(era.name)}</h3>
|
||||
<p class="era-sub">${esc(era.sub)}</p>
|
||||
<p class="era-intro">${esc(era.intro)}</p>
|
||||
</div>
|
||||
<div class="era-rows">${rows}</div>
|
||||
</section>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
function threadCards() {
|
||||
return threads().map((t, i) => {
|
||||
const all = (t.eras && t.eras.length ? t.eras : String(t.span || '').split('→').map((s) => s.trim()).filter(Boolean));
|
||||
const seq = all.length > 5 ? [...all.slice(0, 2), '…', ...all.slice(-2)] : all;
|
||||
return `
|
||||
<a class="thread-card" href="#/thread/${esc(t.slug)}" style="--tc:${esc(t.color)}">
|
||||
<div class="tc-top">
|
||||
<span class="tc-no">${String(i + 1).padStart(2, '0')}</span>
|
||||
<span class="tc-title">${esc(t.title)}</span>
|
||||
</div>
|
||||
<div class="tc-sub">${esc(t.subtitle)}</div>
|
||||
<p class="tc-q">${esc(t.question)}</p>
|
||||
<div class="tc-seq">${seq.map((s) => `<span>${esc(s)}</span>`).join('')}</div>
|
||||
<div class="tc-meta"><span>${t.count} 个节点</span><b>展卷 →</b></div>
|
||||
</a>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
export function renderHome() {
|
||||
const s = stats();
|
||||
const quote = getBoot()?.quote;
|
||||
|
||||
const html = `
|
||||
<section class="hero">
|
||||
<div class="hero-note">
|
||||
<p class="kicker">制度卷 · 四千年</p>
|
||||
<div class="hero-preface">
|
||||
<p>国体言国家属于谁,政体言权力如何组织。同一片山河,夏商以王权统率部族,周人以分封定尊卑,秦以降则以<b>皇帝、官僚与郡县</b>层层相制。</p>
|
||||
<p>二十四朝,四千年。中央之省、台、院、阁,地方之郡、州、道、路、省,选官之察举、中正、科举,皆非孤立之制,而是<b>因革相承的一条长线</b>。此卷按朝编排,<b>先看结构图,再读逐层职掌</b>;另以五条专线串起沿革,供前后对读。</p>
|
||||
</div>
|
||||
<p class="hero-sign">舆纪 编</p>
|
||||
</div>
|
||||
<div class="hero-name">
|
||||
<div class="hero-side">
|
||||
<p class="hero-sub">历代国体政体与官制沿革</p>
|
||||
<span class="hero-seal" aria-hidden="true">制</span>
|
||||
</div>
|
||||
<h1 class="hero-title">政体志</h1>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="stats" aria-label="规模">
|
||||
<div class="stat"><b>${s.dynasties}</b><span>朝</span></div>
|
||||
<div class="stat"><b>${s.institutions}</b><span>处机构</span></div>
|
||||
<div class="stat"><b>${s.threads}</b><span>条沿革</span></div>
|
||||
<div class="stat"><b>${fmtNum(s.years)}</b><span>年制度史</span></div>
|
||||
</section>
|
||||
|
||||
<section class="rail-wrap" aria-label="朝代尺">
|
||||
<div class="rail-head"><h3>朝代尺</h3><span>长度约略示意国祚长短,点击入卷</span></div>
|
||||
<div class="rail">${rail()}</div>
|
||||
<p class="rail-cap">按朝代先后依次排列,尺上用简称;并立时期分卷并置,如五代与十国、北宋与南宋。窄屏可左右滑动。</p>
|
||||
</section>
|
||||
|
||||
<section class="sec" id="toc">
|
||||
<div class="sec-head">
|
||||
<span class="no">01</span>
|
||||
<h2>总目</h2>
|
||||
<em>DYNASTIES</em>
|
||||
<span class="sec-note">按时代分八段,凡二十四朝</span>
|
||||
</div>
|
||||
<div class="eras">${eraBlocks()}</div>
|
||||
</section>
|
||||
|
||||
<section class="sec" id="threads">
|
||||
<div class="sec-head">
|
||||
<span class="no">02</span>
|
||||
<h2>沿革</h2>
|
||||
<em>THREADS</em>
|
||||
<span class="sec-note">五条专线,看制度如何一步步变成后来的样子</span>
|
||||
</div>
|
||||
<div class="thread-cards">${threadCards()}</div>
|
||||
</section>
|
||||
|
||||
${quote ? `
|
||||
<section class="sec" id="quote">
|
||||
<div class="sec-head">
|
||||
<span class="no">03</span>
|
||||
<h2>史料一瞥</h2>
|
||||
<em>EXCERPT</em>
|
||||
<span class="sec-note">随卷抽读</span>
|
||||
</div>
|
||||
<div class="quotes">
|
||||
<blockquote class="quote">
|
||||
<p class="quote-text">${esc(quote.text)}</p>
|
||||
<p class="quote-src">${esc(quote.source)} · <a href="#/dynasty/${esc(quote.slug)}">${esc(quote.dynasty)}</a></p>
|
||||
</blockquote>
|
||||
</div>
|
||||
</section>` : ''}
|
||||
|
||||
<section class="sec" id="fanli">
|
||||
<div class="sec-head">
|
||||
<span class="no">04</span>
|
||||
<h2>凡例</h2>
|
||||
<em>NOTES</em>
|
||||
<span class="sec-note">这套志书怎么读</span>
|
||||
</div>
|
||||
<div class="fanli-grid">
|
||||
<p class="fanli-lead">制度史最怕割断来看。一个机构的名字、一个官员的品级,背后往往是几百年间皇权与相权、中央与地方反复拉扯的结果。本志把每一朝当作一个横剖面,再把二十四个剖面串成纵线,横看架构,纵看因革。</p>
|
||||
<ul class="fanli-list">
|
||||
<li><span>一</span><div><b>国体政体,分而观之</b><p>国体言政权性质,政体言权力组织形式。古代部分采用史学界通行表述,史料有限或学界有争议处,随文注明。</p></div></li>
|
||||
<li><span>二</span><div><b>架构按层,职掌系人</b><p>中央机构按「皇帝—中枢—行政—监察—军事—地方」分层展示,各机构列长官与职掌,力求一眼看清谁向谁负责。</p></div></li>
|
||||
<li><span>三</span><div><b>因革相承,不割断看</b><p>每朝列「沿革要点」,另设五条专线,串起宰相、监察、地方、选官、军事的长期变化。</p></div></li>
|
||||
<li><span>四</span><div><b>史料为据,异说另注</b><p>引文标明出处,概述标「大意」;年代取通行说法,异说与制度性质之争,不作独断。</p></div></li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
`;
|
||||
|
||||
return { html, title: '历代国体、政体与官制沿革' };
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import { search } from '../api.js';
|
||||
import { esc, highlight } from '../util.js';
|
||||
|
||||
const HOT = ['三省六部', '军机处', '科举制', '行省', '二府三司', '内阁', '刺史', '九品中正制'];
|
||||
|
||||
function resultRow(r, q) {
|
||||
return `
|
||||
<a class="result" href="${esc(r.url)}">
|
||||
<div class="result-title">${highlight(r.title, q)}</div>
|
||||
<div class="result-sub">${esc(r.subtitle)}</div>
|
||||
<div class="result-snippet">${highlight(r.snippet, q)}</div>
|
||||
</a>`;
|
||||
}
|
||||
|
||||
export async function renderSearch({ query }) {
|
||||
const q = (query.get('q') || '').trim();
|
||||
const data = q ? await search(q) : null;
|
||||
|
||||
let body = '';
|
||||
if (!q) {
|
||||
body = `
|
||||
<div class="hot-terms">
|
||||
<span>试着检索</span>
|
||||
${HOT.map((t) => `<a class="chip-btn" href="#/search?q=${encodeURIComponent(t)}">${esc(t)}</a>`).join('')}
|
||||
</div>
|
||||
<div class="search-scope">
|
||||
<a href="#/"><b>二十四朝</b><span>按时代与国祚翻阅</span></a>
|
||||
<a href="#/threads"><b>五条沿革</b><span>宰相、监察、地方、选官、军事</span></a>
|
||||
<a href="#/glossary"><b>四十词条</b><span>职官与制度术语释义</span></a>
|
||||
</div>
|
||||
<p class="search-hint">检索范围包括朝代名与概要、国体政体表述、中央机构与长官、地方层级、沿革要点、史料引文,以及五条沿革的全部节点与词条释义。</p>`;
|
||||
} else if (!data.total) {
|
||||
body = `<p class="empty">没有找到与「${esc(q)}」相关的内容。可换个说法,或从总目逐朝翻阅。</p>`;
|
||||
} else {
|
||||
const groups = [
|
||||
['朝代', data.groups.dynasty],
|
||||
['沿革', data.groups.thread],
|
||||
['词条', data.groups.term],
|
||||
].filter(([, list]) => list.length);
|
||||
body = `
|
||||
<p class="search-meta">共 ${data.total} 条结果,显示 ${data.groups.dynasty.length + data.groups.thread.length + data.groups.term.length} 条</p>
|
||||
<div class="search-groups">
|
||||
${groups.map(([label, list]) => `
|
||||
<section class="search-group">
|
||||
<h2>${label}</h2>
|
||||
${list.map((r) => resultRow(r, q)).join('')}
|
||||
</section>`).join('')}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
const html = `
|
||||
<header class="search-hero">
|
||||
<p class="kicker">检索 · 全志</p>
|
||||
<h1>检索</h1>
|
||||
<form class="search-form" data-search-form role="search">
|
||||
<input class="search-input" type="search" name="q" value="${esc(q)}" placeholder="朝代、机构、制度、人物……" aria-label="检索全志" autofocus />
|
||||
<button class="btn" type="submit">检索</button>
|
||||
</form>
|
||||
</header>
|
||||
${body}
|
||||
`;
|
||||
|
||||
function mount() {
|
||||
const form = document.querySelector('[data-search-form]');
|
||||
form?.addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
const val = form.querySelector('input[name="q"]').value.trim();
|
||||
location.hash = val ? `#/search?q=${encodeURIComponent(val)}` : '#/search';
|
||||
});
|
||||
}
|
||||
|
||||
return { html, title: q ? `检索 · ${q}` : '检索', mount };
|
||||
}
|
||||
@@ -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}沿革` };
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { threads } from '../store.js';
|
||||
import { esc } from '../util.js';
|
||||
|
||||
export function renderThreads() {
|
||||
const rows = threads().map((t, i) => `
|
||||
<a class="thread-row" href="#/thread/${esc(t.slug)}" style="--tc:${esc(t.color)}">
|
||||
<span class="tr-no">${String(i + 1).padStart(2, '0')}</span>
|
||||
<div class="tr-main">
|
||||
<div class="tr-head">
|
||||
<h2>${esc(t.title)}</h2>
|
||||
<span class="tr-sub">${esc(t.subtitle)}</span>
|
||||
</div>
|
||||
<p class="tr-q">${esc(t.question)}</p>
|
||||
<p class="tr-sum">${esc(t.summary)}</p>
|
||||
</div>
|
||||
<div class="tr-meta">
|
||||
<b>${t.count}</b>
|
||||
<span>节点</span>
|
||||
<em>${esc(t.span)}</em>
|
||||
</div>
|
||||
<span class="tr-go" aria-hidden="true">→</span>
|
||||
</a>`).join('');
|
||||
|
||||
const html = `
|
||||
<header class="thread-hero">
|
||||
<p class="kicker">沿革 · 五条专线</p>
|
||||
<h1>制度沿革</h1>
|
||||
<p class="thread-q">横看一朝之架构,纵看千年之因革。</p>
|
||||
<p class="thread-summary">同一件事——谁辅佐皇帝、谁监督百官、地方设几级、士人如何做官、兵从哪里来——在不同朝代有不同的答案。五条专线把二十四朝的制度碎片串成连续的线索,看它如何一步一步变成后来的样子。</p>
|
||||
</header>
|
||||
<div class="thread-index">${rows}</div>
|
||||
`;
|
||||
|
||||
return { html, title: '制度沿革' };
|
||||
}
|
||||
Reference in new issue
Block a user