summaryrefslogtreecommitdiff
path: root/process-templates
diff options
context:
space:
mode:
authorsandbank52641 <153552626+sandbank52641@users.noreply.github.com>2024-01-07 20:08:05 +0100
committerDaniel Micay <danielmicay@gmail.com>2024-01-07 15:18:18 -0500
commit968167ad525827e202837231ee920fa094302d13 (patch)
tree28c73579566413632a7284bf767008962407dc2b /process-templates
parent9435589e44b359e486b82ac27e2b2dc82f19398e (diff)
simplify process templates script
Python provides a high-level path object with `pathlib`[^1], which is included in the standard library[^2]. This makes it simpler to find all html files to process. [^1]: https://docs.python.org/3/library/pathlib.html#module-pathlib [^2]: https://peps.python.org/pep-0428/
Diffstat (limited to 'process-templates')
-rwxr-xr-xprocess-templates12
1 files changed, 4 insertions, 8 deletions
diff --git a/process-templates b/process-templates
index 703acc74..8f24d921 100755
--- a/process-templates
+++ b/process-templates
@@ -1,22 +1,18 @@
#!/usr/bin/env python3
from jinja2 import FileSystemLoader, Environment
+from pathlib import Path
import os
import sys
-ROOT_DIR = sys.argv[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)
-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]
- )
+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)