chaostreff.ch/build.py
2023-01-04 03:05:25 +01:00

37 lines
1.1 KiB
Python
Executable file

#!/usr/bin/env python3
import jinja2
import os
import shutil
import yaml
with open('config.yml', 'r') as f:
config = yaml.safe_load(f)
os.makedirs('out', exist_ok = True)
shutil.copytree('static', 'out/static', dirs_exist_ok=True)
env = jinja2.Environment(loader=jinja2.FileSystemLoader('static-src'))
env.globals.update(config['jinja_environment'])
env.globals['languages'] = config['languages']
for fname in os.listdir('static-src'):
tmpl = env.get_template(fname)
with open(os.path.join('out', fname), 'w') as of:
of.write(tmpl.render())
for lang in config['languages'].keys():
with open(f'l10n/{lang}.yml', 'r') as l:
l10n = yaml.safe_load(l)
env = jinja2.Environment(loader=jinja2.FileSystemLoader('src'))
env.globals.update(config['jinja_environment'])
env.globals.update(l10n)
env.globals['languages'] = config['languages']
env.globals['lang'] = lang
os.makedirs(os.path.join('out', lang), exist_ok = True)
for fname in os.listdir('src'):
tmpl = env.get_template(fname)
with open(os.path.join('out', lang, fname), 'w') as of:
of.write(tmpl.render())