QQgit/scripts/check_preview.py

55 行
1.8 KiB
Python
原始文件 Blame 文件历史

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

"""预览页自检:确认 preview / qq-ui / 模板之间没有对不上的 CSS 变量或类名。
用法:python3 scripts/check_preview.py
"""
import pathlib
import re
import sys
ROOT = pathlib.Path(__file__).resolve().parent.parent
CSS = ROOT / 'custom/public/assets/css'
OWN = {'--qq-font-mono', '--disc', '--mark'}
def vars_in(p):
out = set()
for v in re.findall(r'--[a-z0-9-]+', pathlib.Path(p).read_text(encoding="utf-8")):
if v.strip('-') and not v.endswith('-'):
out.add(v)
return out
def main():
used = (vars_in(ROOT / 'preview/preview.css')
| vars_in(ROOT / 'preview/index.html')
| vars_in(CSS / 'qq-ui.css'))
light = vars_in(CSS / 'theme-qq-light.css')
dark = vars_in(CSS / 'theme-qq-dark.css')
ok = True
for name, defined in (('light', light), ('dark', dark)):
missing = sorted(used - defined - OWN)
print(f'{name:5s} 缺失变量: {missing if missing else "无"}')
ok = ok and not missing
tmpl = (ROOT / 'custom/templates/home.tmpl').read_text(encoding="utf-8")
classes = sorted({c for group in re.findall(r'class="([^"]+)"', tmpl) for c in group.split()})
ui = (CSS / 'qq-ui.css').read_text(encoding="utf-8")
for cls in ('qq-home-cards', 'qq-home-card', 'qq-footer', 'page-content'):
has = ('.' + cls) in ui
print(f'qq-ui 含 .{cls}: {has}')
ok = ok and has
auto = (CSS / 'theme-qq-auto.css').read_text(encoding="utf-8").replace(' ', '')
has_media = '@media(prefers-color-scheme:dark)' in auto
print('theme-qq-auto 含日夜媒体查询:', has_media)
ok = ok and has_media
print('模板类名:', ' '.join(classes))
print('\n结论:', '通过' if ok else '有问题')
return 0 if ok else 1
if __name__ == '__main__':
sys.exit(main())