diff options
| author | smdyv <88971341+smdyv@users.noreply.github.com> | 2023-07-13 17:06:57 +0200 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2023-07-13 16:08:16 -0400 |
| commit | 150608e016fe9c8c2e8a5af645db50acc1d85fe1 (patch) | |
| tree | 6214630b2f63313b06e1f1ed3abf8302925aec59 /process-templates.py | |
| parent | 4430036ea2b54e416b0375d25c322ba066d67084 (diff) | |
Use simple templating for static processing
Diffstat (limited to 'process-templates.py')
| -rw-r--r-- | process-templates.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/process-templates.py b/process-templates.py new file mode 100644 index 00000000..703acc74 --- /dev/null +++ b/process-templates.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +from jinja2 import FileSystemLoader, Environment +import os +import sys + +ROOT_DIR = sys.argv[1] +TEMPLATE_PATH_LIST = [ROOT_DIR, "templates/"] + +loader = FileSystemLoader(searchpath=TEMPLATE_PATH_LIST) +environment = Environment(loader=loader, autoescape=True) + +template_file_list = [] +for dirpath, dirnames, filenames in os.walk(ROOT_DIR): + for filename in filenames: + if filename.endswith(".html"): + template_file_list.append( + (os.path.join(dirpath, filename)).split(sep=os.path.sep, maxsplit=1)[1] + ) + +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) |
