Add all tags page rendering

This commit is contained in:
2026-08-07 03:41:22 +02:00
parent 6a4bacc5e6
commit bda4ce5ef2
2 changed files with 31 additions and 0 deletions
+15
View File
@@ -29,6 +29,7 @@ class Site:
self.by_tag: dict[str, list[Content]] = {}
self.by_uri: dict[str, Content] = {}
self.by_section: dict[str, list[Content]] = {}
self.tags_by_count: list[tuple[str, int]] = []
config = self.read_config()
self.name: str = config["name"]
@@ -96,6 +97,11 @@ class Site:
)
self.by_uri[content.uri] = content
def update_tags_by_count(self) -> None:
tags = [(tag, len(items)) for tag, items in self.by_tag.items()]
tags.sort(key=lambda x: x[1], reverse=True)
self.tags_by_count = tags
def discover(self) -> None:
log.info("Discovering content...")
content_path = self.site_path / "content"
@@ -106,6 +112,7 @@ class Site:
self.add_by_section(content)
self.add_by_tag(content)
self.content.append(content)
self.update_tags_by_count()
log.info("Discovered %d content items", len(self.content))
def render_single_index_page(
@@ -151,6 +158,13 @@ class Site:
index.unlink()
index.symlink_to("page-1.html")
def render_tags_page(self) -> None:
template = self.jinja_env.get_template("tags.html")
html = template.render(site=self, tags=self.tags_by_count)
tags_dir = self.output_path / "tags"
tags_dir.mkdir(parents=True, exist_ok=True)
(tags_dir / "index.html").write_text(html, encoding="utf-8")
def render_indices(self) -> None:
sorted_all = sorted(self.content, key=lambda c: c.created, reverse=True)
self.render_index_pages(sorted_all, self.output_path, None)
@@ -162,6 +176,7 @@ class Site:
self.render_index_pages(
sorted_items, self.output_path / "tags" / tag, None, tag
)
self.render_tags_page()
def build(self) -> None:
if not self.origin:
+16
View File
@@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block title %}Tags — {{ site.name }}{% endblock %}
{% block head %}
<link rel="canonical" href="{{ site.origin }}{{ site.base_dir }}tags/">
{% endblock %}
{% block main %}
<h1>Tags</h1>
<ul>
{% for tag, count in tags %}
<li><a href="{{ site.base_dir }}tags/{{ tag }}/">{{ tag }}</a> ({{ count }})</li>
{% endfor %}
</ul>
{% endblock %}