QQgit/scripts/check_preview.py

55 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""预览页自检:确认 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()):
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()
classes = sorted({c for group in re.findall(r'class="([^"]+)"', tmpl) for c in group.split()})
ui = (CSS / 'qq-ui.css').read_text()
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().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())