From f21e7468586262e35d0b1494b0783d6eadc96985 Mon Sep 17 00:00:00 2001 From: omicron Date: Fri, 7 Aug 2026 02:08:54 +0200 Subject: [PATCH] Add tag index rendering --- omicron/ssg/site.py | 12 ++++++++++-- omicron/ssg/templates/plain/index.html | 17 +++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/omicron/ssg/site.py b/omicron/ssg/site.py index 320e76e..abc539e 100644 --- a/omicron/ssg/site.py +++ b/omicron/ssg/site.py @@ -115,6 +115,7 @@ class Site: page_num: int, total_pages: int, section: str | None, + tag: str | None = None, ) -> None: template = self.jinja_env.get_template("index.html") html = template.render( @@ -123,6 +124,7 @@ class Site: page_num=page_num, total_pages=total_pages, section=section, + tag=tag, ) out_file = out_dir / f"page-{page_num}.html" out_file.write_text(html, encoding="utf-8") @@ -132,16 +134,17 @@ class Site: items: list[Content], out_dir: Path, section: str | None, + tag: str | None = None, ) -> None: out_dir.mkdir(parents=True, exist_ok=True) if not items: log.warning("No content, generating empty index page") - self.render_single_index_page(out_dir, (), 1, 1, section) + self.render_single_index_page(out_dir, (), 1, 1, section, tag) else: num_pages = ceil(len(items) / self.items_per_page) for i, page_items in enumerate(batched(items, self.items_per_page)): self.render_single_index_page( - out_dir, page_items, i + 1, num_pages, section + out_dir, page_items, i + 1, num_pages, section, tag ) index = out_dir / "index.html" if index.exists() or index.is_symlink(): @@ -154,6 +157,11 @@ class Site: for section, items in self.by_section.items(): sorted_items = sorted(items, key=lambda c: c.created, reverse=True) self.render_index_pages(sorted_items, self.output_path / section, section) + for tag, items in self.by_tag.items(): + sorted_items = sorted(items, key=lambda c: c.created, reverse=True) + self.render_index_pages( + sorted_items, self.output_path / "tags" / tag, None, tag + ) def build(self) -> None: if not self.origin: diff --git a/omicron/ssg/templates/plain/index.html b/omicron/ssg/templates/plain/index.html index 352bc11..f27f36a 100644 --- a/omicron/ssg/templates/plain/index.html +++ b/omicron/ssg/templates/plain/index.html @@ -1,11 +1,16 @@ {% extends "base.html" %} +{% set prefix = (section + "/") if section else (("tags/" + tag + "/") if tag else "") %} +{% set heading = section or tag or "" %} -{% block title %}{% if section %}{{ section }} — {% endif %}{{ site.name }}{% if page_num > 1 %} — Page {{ page_num }}{% endif %}{% endblock %} +{% block title %}{% if heading %}{{ heading }} — {% endif %}{{ site.name }}{% if page_num > 1 %} — Page {{ page_num }}{% endif %}{% endblock %} -{% block head %}{% endblock %} +{% block head %} + +{% if page_num > 1 %}{% endif %} +{% endblock %} {% block main %} -{% if section %}

{{ section }}

{% endif %} +{% if heading %}

{{ heading }}

{% endif %} {% for item in items %}
@@ -18,15 +23,15 @@ {% if total_pages > 1 %} {% endif %}