This commit is contained in:
alexander
2026-01-22 21:14:16 +01:00
parent 8a26344e20
commit 24d0a9216a
21 changed files with 778 additions and 0 deletions

45
src/build.py Normal file
View File

@@ -0,0 +1,45 @@
from jinja2 import Environment, FileSystemLoader, select_autoescape
import shutil
import datetime
import os
from sources import CSItem
from inventory import load_cheatsheet_inventory, prepare_cheatsheets
INVENTORY_FILE = "cheatsheet_inventory.json"
STATIC_DIR = "static"
TEMPLATES_DIR = "templates"
OUTPUT_DIR = "out"
inv_raw = load_cheatsheet_inventory(INVENTORY_FILE)
# Clear output directory
shutil.rmtree(OUTPUT_DIR, ignore_errors=True)
shutil.copytree(STATIC_DIR, OUTPUT_DIR)
inv: list[CSItem] = prepare_cheatsheets(inv_raw, OUTPUT_DIR)
env = Environment(
loader=FileSystemLoader(TEMPLATES_DIR),
autoescape=select_autoescape()
)
index = env.get_template("index.html.j2")
print(f"{len(inv)} Cheatsheets")
for i in inv:
print("-", i)
thisYear = datetime.datetime.now().year
with open(f"{OUTPUT_DIR}/index.html", "w", encoding="utf-8") as f:
f.write(index.render(items=inv, thisYear=thisYear))
with open(f"{OUTPUT_DIR}/impressum.html", "w", encoding="utf-8") as f:
f.write(env.get_template("impressum.html.j2").render(thisYear=thisYear))
with open(f"{OUTPUT_DIR}/license.html", "w", encoding="utf-8") as f:
f.write(env.get_template("license.html.j2").render(thisYear=thisYear))