From: mar77i Date: Sun, 16 Mar 2025 22:09:45 +0000 (+0100) Subject: simplify template rendering. use markdown for nav. X-Git-Url: https://git.mar77i.info/?a=commitdiff_plain;h=3b73eeaf4224aa49565387e43e7c381bba2ba3ee;p=mar77i.info simplify template rendering. use markdown for nav. --- diff --git a/content/nav.md b/content/nav.md new file mode 100644 index 0000000..6a75086 --- /dev/null +++ b/content/nav.md @@ -0,0 +1,3 @@ +- [Home](/) +- [Blog](/blog) +- [Git](https://git.mar77i.info/) diff --git a/generate.py b/generate.py index 9f4b50f..89e50ff 100755 --- a/generate.py +++ b/generate.py @@ -5,7 +5,6 @@ from argparse import ArgumentParser from pathlib import Path from md import MDRenderer -from template import Template from utils import get_content, write_content @@ -19,27 +18,14 @@ def main(): if output_path.exists(): shutil.rmtree(output_path) output_path.mkdir(0o755) - template = Template(source_path / "template.html") + template = get_content(source_path / "template.html") context = { - "nav-items": [ - { - "link": "/", - "text": "Home", - }, - { - "link": "/blog/", - "text": "Blog", - }, - { - "link": "https://git.mar77i.info/", - "text": "Git", - }, - ] + "nav": MDRenderer(get_content(content_path / "nav.md")).render_html()[1], } context["title"], context["page"] = MDRenderer( get_content(content_path / "index.md") ).render_html() - write_content(output_path / "index.html", template.render(context)) + write_content(output_path / "index.html", template.format(**context)) #context["blogs"] = [] #context["hashtags"] = [] @@ -58,7 +44,7 @@ def main(): blog_path = output_path / "blog" blog_path.mkdir(0o755) context["title"], context["page"] = "Blog stub", "

Blog stub

" - write_content(blog_path / "index.html", template.render(context)) + write_content(blog_path / "index.html", template.format(**context)) if __name__ == "__main__": diff --git a/md.py b/md.py index acc64d4..d855cc6 100644 --- a/md.py +++ b/md.py @@ -75,12 +75,15 @@ class BulletList(Paragraph): @property def lines(self): - return + return self.list_items[-1].lines @lines.setter def lines(self, value): self.list_items.append(self.ListItem()) + def join_lines(self): + return "\n".join(li.join() for li in self.list_items) + class MDRenderer: """ @@ -137,4 +140,4 @@ class MDRenderer: tag = Paragraph() tags.append(tag) tag.lines.append(line) - return title.join_lines(), "\n".join(t.join() for t in tags) + return title.join_lines() if title else None, "\n".join(t.join() for t in tags) diff --git a/template.html b/template.html index 69e3102..63f3069 100644 --- a/template.html +++ b/template.html @@ -10,13 +10,9 @@

mar77i.info

- {page|safe} + {page}