diff options
| author | Christoph Schlosser <christoph@linux.com> | 2025-08-23 22:40:20 +0200 |
|---|---|---|
| committer | Christoph Schlosser <christoph@linux.com> | 2025-08-23 22:40:20 +0200 |
| commit | e4ba1fc772b2ed50fb5f7b469fa30b8915479416 (patch) | |
| tree | 7a531adee09d8e7b8c227b32baa285db0de9a763 /g2h/gen.py | |
| parent | 2f102e4036c3a49e5d40883fa4ef59193c9d943c (diff) | |
| download | git2hugo-e4ba1fc772b2ed50fb5f7b469fa30b8915479416.tar.gz | |
g2h: Add jinja and git basic flow
Diffstat (limited to 'g2h/gen.py')
| -rw-r--r-- | g2h/gen.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/g2h/gen.py b/g2h/gen.py new file mode 100644 index 0000000..4884072 --- /dev/null +++ b/g2h/gen.py @@ -0,0 +1,22 @@ +from jinja2 import Environment, FileSystemLoader +import os + +class Generator: + def __init__(self, output_dir): + self.output_dir = output_dir + template_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'templates')) + self.templates = Environment(loader=FileSystemLoader(template_dir)) + + def _render(self, template, context, out_path): + template = self.templates.get_template(template) + content = template.render(context) + out_file = os.path.join(self.output_dir, out_path) + os.makedirs(os.path.dirname(out_file), exist_ok=True) + with open(out_file, 'w', encoding='utf-8') as f: + f.write(content) + + def render_overview(self, commits): + context = { + 'commits': commits + } + self._render('overview.md', context, '_index.md') |