"""build2.py <splitDir> <cfg.json> <out.html> — page = skeleton + public template with the settings."""
import sys,json
d,cfg_p,out_p=sys.argv[1:4]
tpl=open(d+'/page.txt',encoding='utf-8').read();cfg=json.load(open(cfg_p,encoding='utf-8'))
js=json.dumps(cfg,ensure_ascii=False,separators=(',',':')).replace('<','\\u003c')
assert tpl.count('__CFG'+'_JSON__')==1
head='<!doctype html><html><head><meta charset=utf8><meta name=viewport content="width=device-width,initial-scale=1,viewport-fit=cover"><style>:root{color-scheme:light;padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}body{margin:0;font:14px/1.4 system-ui,sans-serif}img{max-width:100%}[hidden]{display:none!important}</style></head><body>'
html=head+tpl.replace('__CFG'+'_JSON__',js)+'</body></html>'
open(out_p,'w',encoding='utf-8').write(html);print(out_p,len(html.encode())//1024,'KB')
