import jinja2 from datetime import datetime as dt import pathlib date_str = dt.now().strftime("%Y-%m-%d") output_path = pathlib.Path("") 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__": # generate blog overview and entries exec(open("cgbe.py").read()) # generate other pages render_template("faq.html", "faq.html", opt={"current_site": "faq", "date": date_str}) render_template("index.html", "index.html", date=date_str, opt={"current_site": "index", "date": date_str}) render_template("licenses.html", "licenses.html", date=date_str, opt={"current_site": "licenses", "date": date_str}) render_template("links.html", "links.html", date=date_str, opt={"current_site": "links", "date": date_str}) render_template("data.html", "data.html", date=date_str, opt={"current_site": "data", "date": date_str})