File size: 1,059 Bytes
411d33b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3
"""GreenRoot build: inline CSS + JS into self-contained HTML pages."""
import pathlib, re

SRC = pathlib.Path(__file__).parent
OUT = SRC.parent
PAGES = SRC / "pages"

css = (SRC / "style.css").read_text(encoding="utf-8")
i18n = (SRC / "i18n.js").read_text(encoding="utf-8")
extra = (SRC / "i18n-extra.js").read_text(encoding="utf-8")
areas = (SRC / "areas-i18n.js").read_text(encoding="utf-8")
app = (SRC / "app.js").read_text(encoding="utf-8")

SCRIPTS = ("<script>\n" + i18n + "\n</script>\n<script>\n" + extra +
           "\n</script>\n<script>\n" + areas +
           "\n</script>\n<script>\n" + app + "\n</script>")
STYLE = "<style>\n" + css + "\n</style>"

for page in sorted(PAGES.glob("*.html")):
    html = page.read_text(encoding="utf-8")
    assert "<!--STYLE-->" in html and "<!--APP-->" in html, page.name
    html = html.replace("<!--STYLE-->", STYLE).replace("<!--APP-->", SCRIPTS)
    out = OUT / page.name
    out.write_text(html, encoding="utf-8")
    print(f"built {out.name}  ({len(html)//1024} KB)")
print("done")