Files
notplanned/ventures/context-curator/build.py
T

18 lines
1004 B
Python

"""Deterministically embed the editor; no runtime fetches, works on file://."""
import json
import base64
from pathlib import Path
ROOT = Path(__file__).resolve().parent
page = (ROOT / 'site/template.html').read_text()
for key, content in {
'/*__FONT_REGULAR__*/': 'data:font/woff2;base64,' + base64.b64encode((ROOT / 'site/fonts/libre-baskerville-latin-400-normal.woff2').read_bytes()).decode(),
'/*__FONT_ITALIC__*/': 'data:font/woff2;base64,' + base64.b64encode((ROOT / 'site/fonts/libre-baskerville-latin-400-italic.woff2').read_bytes()).decode(),
'/*__CORE__*/': (ROOT / 'core.js').read_text(),
'/*__SAMPLE__*/': json.dumps((ROOT / 'sample.json').read_text()).replace('<', r'\u003c'),
'/*__APP__*/': (ROOT / 'site/app.js').read_text(),
}.items():
page = page.replace(key, content)
(ROOT / 'site/index.html').write_text(page)
(ROOT / 'site/sample.json').write_bytes((ROOT / 'sample.json').read_bytes())
(ROOT / 'site/README.md').write_bytes((ROOT / 'README.md').read_bytes())