#!/usr/bin/env python3 """Decode / re-encode the __bundler/template of the apex-fusion site. python3 bundle.py decode index.html page.html # template -> editable HTML python3 bundle.py encode index.html page.html out.html # editable HTML -> site file The bundler stores the page as a JSON string with ' tags cannot terminate the outer tag). Encoding mirrors that exactly, and `encode` proves it by asserting that an untouched page round-trips byte-identical before writing. """ import json, re, sys TAG = re.compile(r'()', re.S) def decode(site): return json.loads(TAG.search(site).group(2)) def encode_template(page): e = json.dumps(page, ensure_ascii=False) return '\n' + e.replace('', out_path)