42 lines
1.7 KiB
Python
42 lines
1.7 KiB
Python
"""Reproduce the original publication CSS/SVG, scoped to the accepted runtime shell."""
|
|
|
|
import json
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from css_scope import scope_css
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def main():
|
|
target = ROOT / "src/site_engine/web/admin"
|
|
css = (ROOT / "design/assets/publication.css").read_text()
|
|
css = re.sub(r"(?<![-\w])(?:html|body)(?![-\w])", ":scope", css).replace(":root", ":scope")
|
|
css = css.replace(':scope[data-theme="antirion"]', ":scope").replace(
|
|
':scope[data-theme="rose"]', ":scope[data-unused-rose]"
|
|
)
|
|
js = (ROOT / "design/assets/publication.js").read_text()
|
|
data = js.split("const ico={", 1)[1].split("};", 1)[0]
|
|
icons = dict(re.findall(r"(\w+):'([^']*)'", data))
|
|
output = {
|
|
target
|
|
/ "static/publication.css": "/* Generated by scripts/sync_publication_design.py; original declarations unchanged. */\n"
|
|
+ scope_css(css, ".publication-content", ":where(.publication-content)"),
|
|
target / "templates/_publication_icons.html.j2": "{% macro pi(name) -%}{% set paths = "
|
|
+ json.dumps(icons)
|
|
+ ' %}<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="{{ paths.get(name, paths.file) }}"/></svg>{%- endmacro %}\n',
|
|
target / "static/publication-icons.json": json.dumps(icons, ensure_ascii=False) + "\n",
|
|
}
|
|
for path, content in output.items():
|
|
if "--check" in sys.argv:
|
|
if not path.exists() or path.read_text() != content:
|
|
raise SystemExit(f"Publication design out of date: {path}")
|
|
else:
|
|
path.write_text(content)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|