"""网页生成器 — 读取数据库,生成静态 HTML 展示页面。"""
import os
import json
import db
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
TEMPLATE_PATH = os.path.join(BASE_DIR, "templates", "index.html")
STYLE_PATH = os.path.join(BASE_DIR, "static", "style.css")
OUTPUT_DIR = os.path.join(BASE_DIR, "output")
OUTPUT_PATH = os.path.join(OUTPUT_DIR, "index.html")
def _escape(text):
"""简单的 HTML 转义。"""
if not text:
return ""
return (str(text)
.replace("&", "&")
.replace("<", "<")
.replace(">", ">")
.replace('"', """))
def _render_book_card(book):
"""渲染单本书的 HTML 卡片。"""
cover = book.get("cover_url") or ""
cover_html = (f''
if cover
else '