luciaa.at/generate_site.py

27 lines
910 B
Python
Raw Normal View History

2025-01-12 01:08:30 +01:00
import jinja2
from datetime import datetime as dt
2025-01-12 01:08:30 +01:00
import pathlib
2025-01-12 01:08:30 +01:00
date_str = dt.now().strftime("%Y-%m-%d")
output_path = pathlib.Path("out")
input_path = pathlib.Path("templates")
jenv = jinja2.Environment(
loader=jinja2.FileSystemLoader(input_path),
autoescape=True, trim_blocks=True, lstrip_blocks=True,
keep_trailing_newline=False)
def render_template(template_name, output_name, **kwargs):
template = jenv.get_template(template_name)
with open(output_path / output_name, "w") as out_file:
out_file.write(template.render(**kwargs))
if __name__ == "__main__":
2025-01-12 01:08:30 +01:00
render_template("blog.html", "blog.html", date=date_str)
render_template("faq.html", "faq.html", date=date_str)
render_template("index.html", "index.html", date=date_str)
render_template("licenses.html", "licenses.html", date=date_str)
render_template("links.html", "links.html", date=date_str)