From 8a4a08cae892399ba37a3dfcba8009d0438e4333 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sat, 15 Jul 2023 15:26:27 -0400 Subject: run process-templates as an executable --- process-static | 2 +- process-templates | 26 ++++++++++++++++++++++++++ process-templates.py | 26 -------------------------- 3 files changed, 27 insertions(+), 27 deletions(-) create mode 100755 process-templates delete mode 100644 process-templates.py diff --git a/process-static b/process-static index cf6355e7..23c0282b 100755 --- a/process-static +++ b/process-static @@ -31,7 +31,7 @@ cp -a nginx nginx-tmp rm -rf static-tmp cp -a static static-tmp -python3 process-templates.py static-tmp +./process-templates static-tmp for file in static-tmp/**/*.@(json|webmanifest); do json_verify < "$file" >/dev/null diff --git a/process-templates b/process-templates new file mode 100755 index 00000000..703acc74 --- /dev/null +++ b/process-templates @@ -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) diff --git a/process-templates.py b/process-templates.py deleted file mode 100644 index 703acc74..00000000 --- a/process-templates.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/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) -- cgit v1.3.1