Init
This commit is contained in:
45
src/build.py
Normal file
45
src/build.py
Normal 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))
|
||||
|
||||
Reference in New Issue
Block a user