summaryrefslogtreecommitdiff
path: root/process-templates.py
diff options
context:
space:
mode:
Diffstat (limited to 'process-templates.py')
-rw-r--r--process-templates.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/process-templates.py b/process-templates.py
new file mode 100644
index 00000000..1e2cb25c
--- /dev/null
+++ b/process-templates.py
@@ -0,0 +1,24 @@
+from jinja2 import FileSystemLoader, Environment
+from pathlib import Path
+import os
+import sys
+
+if len(sys.argv) != 2:
+ print(f"Usage: {sys.argv[0]} <path>")
+ sys.exit(1)
+
+ROOT_DIR = Path(sys.argv[1])
+TEMPLATE_PATH_LIST = [ROOT_DIR, "templates/"]
+
+loader = FileSystemLoader(searchpath=TEMPLATE_PATH_LIST)
+environment = Environment(loader=loader, autoescape=True)
+
+file_path_list = ROOT_DIR.glob("**/*.html")
+template_file_list = [os.fspath(p.relative_to(ROOT_DIR)) for p in file_path_list]
+
+for template_file in template_file_list:
+ template = environment.get_template(template_file)
+ rendered_template = template.render()
+ path = os.path.join(ROOT_DIR, template_file)
+ with open(path, mode="w") as f:
+ f.write(rendered_template)