summaryrefslogtreecommitdiff
path: root/build.py
blob: ea11922979656407719ea54382da1c988ad9b144 (plain)
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
29
30
31
32
import sys, json, tomllib, zlib

inputs = ["config.toml", "main.css", "main.js", "index.html"]
files = {}
for name in inputs:
    with open(name,'r') as f:
        files[name] = f.read()

config = tomllib.loads(files["config.toml"])
configjson = json.dumps(config, separators=(',',':'))
with open("config.js","w") as f:
    f.write("config="+configjson+";")


index = files["index.html"]
index = index.replace('<link rel="stylesheet" href="style.css">', f'<style>{files["main.css"]}</style>')
index = index.replace('<script src="config.js"></script>', '')
index = index.replace('<script src="ka.js"></script>', '')
index = index.replace('<script src="app.js"></script>', f'<script>config={configjson};{files["main.js"]}</script>')

data = zlib.compress(index.encode('utf-8'))
out = ', '.join(hex(x) for x in data)
print(f"""
#include <avr/pgmspace.h>
#include "webif-fs.h"

static const char index_html[] PROGMEM = {{ {out} }};
PGM_P index_html_data = index_html;
uint16_t index_html_size = {len(data)};
""")