Peach: Local-first video metadata scraper and media manager.
fix: 统一四〇四页面与返回首页按钮
longmeidao749bbbc9593d
diff --git a/src/peach/routes_pages.py b/src/peach/routes_pages.pyindex 48dbce604..c035dcc5d 100644--- a/src/peach/routes_pages.py+++ b/src/peach/routes_pages.py@@ -55,7 +55,8 @@ main{max-width:560px;margin:0 auto}h1{font-size:var(--fs-3xl);font-weight:600;line-height:1.25;margin:16px 0 0}.lede{margin:6px 0 0;color:var(--muted)}h2{font-size:var(--fs-lg);font-weight:600;margin-top:32px;padding-top:24px;border-top:1px solid var(--line)}-p{color:var(--ink-2)}a{color:var(--tungsten);text-underline-offset:3px}+p{color:var(--ink-2)}a{color:var(--tungsten);text-decoration:none}+a:hover{text-decoration:none}code{font:var(--fs-xs)/1.5 ui-monospace,Consolas,"Cascadia Mono",monospace;background:var(--surface);border:1px solid var(--line-soft);border-radius:var(--badge-radius);padding:2px 6px;overflow-wrap:anywhere}@@ -276,16 +277,23 @@ def _scrollbar_rules() -> str:def error_page(status: int, message: str) -> str:"""浏览器导航撞上 403/404/409 时给人看的那一页,不是一行 JSON。"""- title = {403: "这里不能打开", 404: "没有这一页", 409: "现在不能这样做"}.get(status, "出了点问题")+ title = {403: "这里不能打开", 404: "四〇四", 409: "现在不能这样做"}.get(status, "出了点问题")+ description = '' if status == 404 else f'<p class="lede">{escape(message)}</p>'body = (f'<img class="mark" src="/peach-logo.png" alt=""><h1>{title}</h1>'- f'<p class="lede">{escape(message)}</p><p><a href="/">返回馆藏</a></p>')+ f'{description}<p><a class="geist-button primary" href="/">返回首页</a></p>')return _document(f"Peach · {title}", body)+def _button_rules() -> str:+ """独立页面直接使用主站的 Geist Button 规则。"""+ base = (PROJECT_ROOT / "web/css/01-base.css").read_text(encoding="utf-8")+ return '\n'.join(re.findall(r'^\.geist-button[^{}]*\{[^}]*\}', base, re.M))++def _document(title: str, body: str) -> str:# 页内脚本对两张页面都生效:找不到对应控件时它什么也不做。return (f"{_SETUP_HEAD}<title>{title}</title><style>{_theme_tokens()}{_scrollbar_rules()}</style>"- f"{_SETUP_STYLE}</head><body><main>{body}</main>{_SETUP_SCRIPT}{_SHARED_SCRIPT}</body></html>\n")+ f"{_SETUP_STYLE}<style>{_button_rules()}</style></head><body><main>{body}</main>{_SETUP_SCRIPT}{_SHARED_SCRIPT}</body></html>\n")def _check_html(name: str, text_html: str, *, checked: bool) -> str:diff --git a/tests/test_onboarding.py b/tests/test_onboarding.pyindex 9a99c6521..c756f0a6f 100644--- a/tests/test_onboarding.py+++ b/tests/test_onboarding.py@@ -727,12 +727,19 @@ class StandaloneConfigurationTests(_Case):self.assertTrue(page.headers["content-type"].startswith("text/html"))self.assertIn("<h1>现在不能这样做</h1>", page.text)self.assertIn('<p class="lede">请先完成首次设置</p>', page.text)- self.assertIn('<a href="/">返回馆藏</a>', page.text)+ self.assertIn('<a class="geist-button primary" href="/">返回首页</a>', page.text)+ self.assertIn('a{color:var(--tungsten);text-decoration:none}', page.text)+ self.assertIn('a:hover{text-decoration:none}', page.text)self.assertIn("@media (prefers-color-scheme:dark)", page.text)missing = client.get("/no-such-page", headers={"Accept": "text/html"})self.assertEqual(missing.status_code, 404)- self.assertIn("<h1>没有这一页</h1>", missing.text, "路由没匹配到的 404 是 Starlette 抛的,也要成页")- self.assertIn("这个地址下没有页面。", missing.text, "Starlette 的英文 detail 不能原样给人看")+ self.assertIn("<h1>四〇四</h1>", missing.text)+ self.assertNotIn('<p class="lede">', missing.text)+ self.assertNotIn("这个地址下没有页面。", missing.text)+ self.assertIn('<a class="geist-button primary" href="/">返回首页</a>', missing.text)+ from peach.routes_pages import _button_rules+ self.assertIn('.geist-button.primary{', _button_rules())+ self.assertIn(_button_rules(), missing.text)data = client.get("/refuse", headers={"Accept": "application/json"})self.assertEqual(data.status_code, 409)self.assertEqual(data.json(), {"error": "请先完成首次设置"})