Track the TRK preview package and the newest value artifacts for FRA20261007, move the 17lands API notes under data, and ignore downloaded 17lands, card image and live directories.
77 lines
2.9 KiB
Python
77 lines
2.9 KiB
Python
"""Shared top/bottom banner + centred page wrapper for the standalone report pages.
|
||
|
||
All these pages live in ``value/<SNAP>/reports/`` so the links below are relative to
|
||
that directory (``matchups.html``, ``card_graph.html``, ``cluster_viz.html`` and
|
||
``templates/index.html``).
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import re
|
||
import shutil
|
||
from pathlib import Path
|
||
|
||
ASSETS_SRC = Path(__file__).resolve().parent / "assets"
|
||
ASSETS = ("d3.v7.min.js",) # 随报告一起发布的前端资源
|
||
|
||
|
||
def ensure_assets(reports_dir) -> int:
|
||
"""把 scripts/assets/ 下的前端资源拷到 <reports>/assets/(首页图、d3 等),返回拷贝数。
|
||
|
||
这些文件不在 value/ 里(否则每次重建都被清掉),而在 render 时随报告部署。
|
||
"""
|
||
dst = Path(reports_dir) / "assets"
|
||
dst.mkdir(parents=True, exist_ok=True)
|
||
n = 0
|
||
for name in ASSETS:
|
||
src = ASSETS_SRC / name
|
||
if src.exists() and not (dst / name).exists():
|
||
shutil.copy2(src, dst / name)
|
||
n += 1
|
||
return n
|
||
|
||
|
||
NAV = [
|
||
("templates/index.html", "首页"),
|
||
("daily.html", "每日走势"),
|
||
("matchups.html", "克制矩阵"),
|
||
("card_graph.html", "牌间关系图"),
|
||
("cluster_viz.html", "聚类可视化"),
|
||
]
|
||
|
||
CSS = """*{box-sizing:border-box} body{font-family:system-ui,'Segoe UI',sans-serif;margin:0;padding:0;
|
||
background:#12141a;color:#e8e8ea}
|
||
.wrap{max-width:1460px;margin:0 auto;padding:20px 20px 8px}
|
||
.banner{background:#0f1218;border-bottom:1px solid #232b38}
|
||
.banner.bot{border-bottom:0;border-top:1px solid #232b38;margin-top:26px}
|
||
.bwrap{max-width:1460px;margin:0 auto;padding:10px 20px;display:flex;align-items:center;gap:18px;
|
||
font-size:13px;flex-wrap:wrap}
|
||
.brand{font-weight:700;color:#fff;text-decoration:none}
|
||
.banner .nav{display:flex;gap:14px;margin-left:auto;flex-wrap:wrap}
|
||
.banner .nav a{color:#9fb0c7;text-decoration:none}
|
||
.banner .nav a:hover{color:#fff}
|
||
.banner .nav a.on{color:#fff;font-weight:600}
|
||
.footwrap{max-width:1460px;margin:0 auto;padding:10px 20px;font-size:12px;color:#8a94a6;line-height:1.8}
|
||
"""
|
||
|
||
|
||
def set_of(path) -> str:
|
||
"""从 `value/TRK20261114` / `data/17lands/TRK20261114` 这类目录名取系列码。"""
|
||
m = re.match(r"([A-Za-z]+)", Path(path).name)
|
||
return (m.group(1) if m else "FRA").upper()
|
||
|
||
|
||
SET = "FRA" # 由各 renderer 从 out_dir / snapshot 名推导后覆盖(如 TRK)
|
||
|
||
|
||
def banner(current: str = "", extra: str = "") -> str:
|
||
links = "".join(
|
||
f'<a href="{h}"{" class=\"on\"" if h == current else ""}>{t}</a>' for h, t in NAV)
|
||
return ('<header class="banner"><div class="bwrap">'
|
||
f'<a class="brand" href="templates/index.html">{SET} PremierDraft · 子流派模板</a>'
|
||
f'<nav class="nav">{links}</nav>{extra}</div></header>')
|
||
|
||
|
||
def footbanner(legend: str = "") -> str:
|
||
"""Legend-only footer (no nav / attribution)."""
|
||
return f'<footer class="banner bot"><div class="footwrap">{legend}</div></footer>' if legend else ""
|