"""Inline the three startup files into index.html so the first paint needs no fetch.""" import io, json, pathlib root = pathlib.Path(__file__).parent src = (root / 'index.src.html').read_text(encoding='utf-8') blocks = [] for el, name in (('d-index', 'index.json'), ('d-checkpoints', 'checkpoints.json'), ('d-frontier', 'frontier.json')): data = json.loads((root / name).read_text(encoding='utf-8')) # inside JSON would close the tag early text = json.dumps(data, separators=(',', ':')).replace('{text}') out = src.replace('', '\n'.join(blocks)) assert '' not in out (root / 'index.html').write_text(out, encoding='utf-8') print(f'index.html {len(out)/1e6:.2f} MB (inlined {len(blocks)} files)')