Finsihed
This commit is contained in:
54
src/build.py
Normal file
54
src/build.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||
from inventory import load_cheatsheet_inventory, download_cheatsheet, CheatsheetItem
|
||||
|
||||
import shutil
|
||||
import datetime
|
||||
|
||||
INVENTORY_FILE = "cheatsheet_inventory.json"
|
||||
STATIC_DIR = "static"
|
||||
TEMPLATES_DIR = "templates"
|
||||
OUTPUT_DIR = "out"
|
||||
|
||||
inv_raw = load_cheatsheet_inventory(INVENTORY_FILE)
|
||||
inv: list[CheatsheetItem] = []
|
||||
|
||||
# Clear output directory
|
||||
shutil.rmtree(OUTPUT_DIR, ignore_errors=True)
|
||||
shutil.copytree(STATIC_DIR, OUTPUT_DIR)
|
||||
|
||||
for i in inv_raw.items:
|
||||
a = None
|
||||
if i.cache:
|
||||
print("Downloading", i.url)
|
||||
url = download_cheatsheet(i, OUTPUT_DIR)
|
||||
if url is not None:
|
||||
i.url = url
|
||||
a = i
|
||||
|
||||
else:
|
||||
a = i
|
||||
|
||||
if a is not None:
|
||||
inv.append(a)
|
||||
|
||||
env = Environment(
|
||||
loader=FileSystemLoader(TEMPLATES_DIR),
|
||||
autoescape=select_autoescape()
|
||||
)
|
||||
|
||||
index = env.get_template("index.html.j2")
|
||||
|
||||
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