CI / check (push) Failing after 15m48s
Signed-off-by: 南通一次元科技有限公司 <guwangtu@icimeta.com>
89 lines
2.9 KiB
Python
89 lines
2.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""统一嵌入主题同步工具
|
|
|
|
把 shared/embed_theme.css 注入到各业务页面,替换原有的
|
|
<style id="platform-embed-style"> 内容,避免主题散落在 6 个文件里各改一份。
|
|
|
|
用法:
|
|
python deploy/同步统一主题.py # 写入
|
|
python deploy/同步统一主题.py --check # 只检查是否需要更新
|
|
"""
|
|
import argparse
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
WORKSPACE = Path(__file__).resolve().parent.parent
|
|
THEME_FILE = WORKSPACE / "shared" / "embed_theme.css"
|
|
|
|
# 页面级补充样式(只放页面特有的高度/布局修正)
|
|
PAGE_EXTRAS = {
|
|
"审计项目管理平台/templates/index.html": "",
|
|
"风险管理项目/templates/index.html": "",
|
|
"合同审核管理平台/index.html": "body.embedded { height:100vh !important; }",
|
|
"综合管理平台/knowledge.html": "",
|
|
"综合管理平台/settings.html": "",
|
|
"综合管理平台/digital_audit.html": "",
|
|
}
|
|
|
|
STYLE_RE = re.compile(r'<style id="platform-embed-style">.*?</style>', re.S)
|
|
SCRIPT_MARKER = 'id="platform-embed-script"'
|
|
|
|
|
|
def build_block(extra: str) -> str:
|
|
theme = THEME_FILE.read_text(encoding="utf-8")
|
|
if extra:
|
|
theme += "\n/* 页面补充样式 */\n" + extra + "\n"
|
|
return '<style id="platform-embed-style">\n' + theme + "</style>"
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--check", action="store_true")
|
|
args = parser.parse_args()
|
|
|
|
if not THEME_FILE.exists():
|
|
print("缺少 shared/embed_theme.css")
|
|
return 1
|
|
problems = 0
|
|
for rel, extra in PAGE_EXTRAS.items():
|
|
path = WORKSPACE / rel
|
|
if not path.exists():
|
|
print(f"[缺失] {rel}")
|
|
problems += 1
|
|
continue
|
|
raw = path.read_bytes()
|
|
bom = raw.startswith(b"\xef\xbb\xbf")
|
|
text = raw.decode("utf-8-sig")
|
|
if SCRIPT_MARKER not in text:
|
|
print(f"[缺少嵌入脚本] {rel}")
|
|
problems += 1
|
|
new_block = build_block(extra)
|
|
if STYLE_RE.search(text):
|
|
new_text = STYLE_RE.sub(lambda m: new_block, text, count=1)
|
|
else:
|
|
idx = text.rfind("</body>")
|
|
if idx < 0:
|
|
print(f"[无法定位] {rel}")
|
|
problems += 1
|
|
continue
|
|
new_text = text[:idx] + new_block + "\n" + text[idx:]
|
|
if new_text == text:
|
|
print(f"[已是最新] {rel}")
|
|
continue
|
|
if args.check:
|
|
print(f"[需要更新] {rel}")
|
|
problems += 1
|
|
else:
|
|
path.write_bytes(new_text.encode("utf-8-sig" if bom else "utf-8"))
|
|
print(f"[已同步] {rel}")
|
|
if problems:
|
|
print(f"\n完成:发现 {problems} 处需要处理")
|
|
return 1
|
|
print("\n完成:统一嵌入主题全部一致")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|