dashboard: merge log page into index (nav 首页/词条/语法); session back-link -> index

This commit is contained in:
Lang
2026-10-14 21:37:27 +08:00
parent 4566e349ec
commit 60e0a1b856
+13 -14
View File
@@ -107,7 +107,7 @@ tr:last-child td{border-bottom:none}
# 页头/页脚:banner 结构(参考 FRA 模板)
NAV = [("index", "index.html", "首页"), ("items", "items.html", "词条"),
("grammar", "grammar.html", "语法"), ("log", "log.html", "日志")]
("grammar", "grammar.html", "语法")]
COMMON_JS = r"""
const esc = s => String(s ?? "").replace(/[&<>"]/g, c => ({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"}[c]));
@@ -177,7 +177,7 @@ def render_md(text: str) -> str:
def session_body(s: dict, files: list[tuple[str, str]]) -> str:
head = (f'<p><a href="log.html">← 返回日志</a></p>'
head = (f'<p><a href="index.html">← 返回首页</a></p>'
f'<h1>{esc(s["date"])} · {esc(s["type"]) or "session"}</h1>')
if not files:
return head + '<p class="muted">没有对应的 logs/*.md 记录文件。</p>'
@@ -220,6 +220,11 @@ BODY_INDEX = """
<div class="cards vert" id="skills"></div>
</div>
</div>
<h2>训练日志</h2>
<div class="wrapx"><table id="log"></table></div>
<h2>等级变更历史</h2>
<div class="wrapx"><table id="history"></table></div>
"""
BODY_ITEMS = """
@@ -249,14 +254,6 @@ BODY_GRAMMAR = """
<div class="wrapx"><table id="grammar"></table></div>
"""
BODY_LOG = """
<h1>训练日志</h1>
<div class="wrapx"><table id="log"></table></div>
<h2>等级变更历史</h2>
<div class="wrapx"><table id="history"></table></div>
"""
# ---------- 各页脚本 ----------
SCRIPT_INDEX = r"""
@@ -365,15 +362,17 @@ def main() -> int:
conn.close()
OUT.mkdir(parents=True, exist_ok=True)
for old in OUT.glob("*"): # 清掉上次生成的页面,避免残留(如已并入首页的 log.html)
if old.suffix in (".html", ".js"):
old.unlink()
(OUT / "data.js").write_text(
"window.DATA = " + json.dumps(payload, ensure_ascii=False) + ";\n", encoding="utf-8")
gen = payload["generated"]
pages = {
"index.html": ("概览", "index", BODY_INDEX, SCRIPT_INDEX),
"index.html": ("概览", "index", BODY_INDEX, SCRIPT_INDEX + SCRIPT_LOG),
"items.html": ("词条", "items", BODY_ITEMS, SCRIPT_ITEMS),
"grammar.html": ("语法修正", "grammar", BODY_GRAMMAR, SCRIPT_GRAMMAR),
"log.html": ("训练日志", "log", BODY_LOG, SCRIPT_LOG),
"grammar.html": ("语法", "grammar", BODY_GRAMMAR, SCRIPT_GRAMMAR),
}
for fname, (title, active, body, script) in pages.items():
(OUT / fname).write_text(html_page(title, active, body, script, gen), encoding="utf-8")
@@ -387,7 +386,7 @@ def main() -> int:
for p in sorted(logs_dir.glob(f"{date}*.md"))] if logs_dir.exists() else []
body = session_body(s, files)
(OUT / f"session-{s['id']}.html").write_text(
html_page(f"{date} {s.get('type','')}", "log", body, "", gen), encoding="utf-8")
html_page(f"{date} {s.get('type','')}", "index", body, "", gen), encoding="utf-8")
n += 1
print(f"HTML : {OUT.relative_to(ROOT)}/ ({len(pages)} 页 + {n} 会话详情 + data.js, "