import base64, pathlib, sys, urllib.request
# Run before starting each app. Only supplies a font; list styles are untouched.
root = pathlib.Path(sys.argv[1])
font = pathlib.Path(sys.argv[2])
if not font.exists():
    urllib.request.urlretrieve('https://raw.githubusercontent.com/IdreesInc/Monocraft/main/dist/Monocraft-ttf/Monocraft.ttf', font)
data = base64.b64encode(font.read_bytes()).decode()
p = root / 'apps/web/index.html'
s = p.read_text()
style = f'<style>@font-face{{font-family:Monocraft;src:url(data:font/ttf;base64,{data}) format("truetype");font-weight:100 900;}}</style>'
if style not in s:
    p.write_text(s.replace('</head>', style + '</head>'))
