scripts/banner.py builds artwork/banner.svg from the web UI's logo and wordmark, as Jarl's does; scripts/logo.py runs it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
61 lines
2.1 KiB
Python
61 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
# Builds the web UI's logo from the master, artwork/logo.svg (a key whose
|
|
# bow is a crown with Jarl's network nodes, in Jarl's blue and white):
|
|
#
|
|
# internal/web/static/assets/logo.svg the favicon (a copy)
|
|
# internal/web/static/assets/logo.js the shapes for the web UI, which
|
|
# draws them inline (brand.js), so the
|
|
# logo appears together with the page
|
|
#
|
|
# The master is hand-written SVG: <g> elements whose attributes apply to
|
|
# their <path> and <circle> children. It then runs scripts/banner.py to
|
|
# rebuild the README's banner. Run from the repository root after changing
|
|
# it:
|
|
#
|
|
# python3 scripts/logo.py
|
|
import json
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import xml.etree.ElementTree as ET
|
|
|
|
MASTER = "artwork/logo.svg"
|
|
OUT = "internal/web/static/assets"
|
|
SVG = "{http://www.w3.org/2000/svg}"
|
|
|
|
|
|
def shapes(el, inherited):
|
|
out = []
|
|
attrs = dict(inherited)
|
|
attrs.update({k: v for k, v in el.attrib.items() if k not in ("xmlns", "viewBox")})
|
|
tag = el.tag.replace(SVG, "")
|
|
if tag in ("path", "circle", "rect", "polygon"):
|
|
out.append([tag, attrs])
|
|
for child in el:
|
|
out.extend(shapes(child, attrs if tag == "g" else inherited))
|
|
return out
|
|
|
|
|
|
def main():
|
|
root = ET.parse(MASTER).getroot()
|
|
view_box = root.attrib["viewBox"]
|
|
items = []
|
|
for child in root:
|
|
items.extend(shapes(child, {}))
|
|
with open(os.path.join(OUT, "logo.js"), "w") as f:
|
|
f.write(f"// The Steward logo, from {MASTER} by scripts/logo.py; don't edit.\n"
|
|
"// brand.js draws it; logo.svg is the same picture.\n"
|
|
f"export const viewBox = {json.dumps(view_box)};\n"
|
|
"export const shapes = [\n"
|
|
+ "".join(f" {json.dumps(s)},\n" for s in items)
|
|
+ "];\n")
|
|
shutil.copyfile(MASTER, os.path.join(OUT, "logo.svg"))
|
|
for name in ("logo.svg", "logo.js"):
|
|
print(f"{OUT}/{name}: {os.path.getsize(os.path.join(OUT, name))} bytes")
|
|
subprocess.run([sys.executable, "scripts/banner.py"], check=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|