summaryrefslogtreecommitdiffstats
path: root/g2h/page.py
diff options
context:
space:
mode:
authorChristoph Schlosser <christoph@linux.com>2025-08-24 17:10:11 +0200
committerChristoph Schlosser <christoph@linux.com>2025-08-24 17:10:11 +0200
commit9bd3fd1bce788dce610ad7276ce1f1634019c380 (patch)
tree59898b74445bf4a9e751b4b7bec46f85a7ad43d8 /g2h/page.py
parent66dfe0e665ebeb0dce1ff290b77245e4a9fadd88 (diff)
downloadgit2hugo-9bd3fd1bce788dce610ad7276ce1f1634019c380.tar.gz
g2h: Add unit tests and restructure class layout
Instead of having a large generator class use individual pages
Diffstat (limited to 'g2h/page.py')
-rw-r--r--g2h/page.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/g2h/page.py b/g2h/page.py
new file mode 100644
index 0000000..44f97ee
--- /dev/null
+++ b/g2h/page.py
@@ -0,0 +1,18 @@
+from jinja2 import Environment, FileSystemLoader
+import os
+
+class Page:
+ def __init__(self, template_file, out_dir, out_file, name):
+ self.out_file_path = os.path.join(out_dir, out_file)
+ self.name = name
+ template_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'templates'))
+ self.template = Environment(loader=FileSystemLoader(template_dir)).get_template(template_file)
+
+ def context(self):
+ raise NotImplementedError("Must override context")
+
+ def render(self):
+ content = self.template.render(self.context())
+ os.makedirs(os.path.dirname(self.out_file_path), exist_ok=True)
+ with open(self.out_file_path, 'w', encoding='utf-8') as f:
+ f.write(content)