File size: 846 Bytes
8aabba6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #!/usr/bin/env python3
"""把 src/page.html 包成完整的 index.html(Hugging Face 静态 Space 直接使用)。
python tools/build.py
"""
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
body = (ROOT / "src/page.html").read_text(encoding="utf-8")
head_end = body.index("</style>") + len("</style>")
head, rest = body[:head_end], body[head_end:]
html = f"""<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<style>:root{{padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}}img{{max-width:100%}}[hidden]{{display:none!important}}</style>
{head}
</head>
<body>
{rest}
</body>
</html>
"""
(ROOT / "index.html").write_text(html, encoding="utf-8")
print("写出 index.html")
|