Add all tags page rendering
This commit is contained in:
@@ -29,6 +29,7 @@ class Site:
|
|||||||
self.by_tag: dict[str, list[Content]] = {}
|
self.by_tag: dict[str, list[Content]] = {}
|
||||||
self.by_uri: dict[str, Content] = {}
|
self.by_uri: dict[str, Content] = {}
|
||||||
self.by_section: dict[str, list[Content]] = {}
|
self.by_section: dict[str, list[Content]] = {}
|
||||||
|
self.tags_by_count: list[tuple[str, int]] = []
|
||||||
|
|
||||||
config = self.read_config()
|
config = self.read_config()
|
||||||
self.name: str = config["name"]
|
self.name: str = config["name"]
|
||||||
@@ -96,6 +97,11 @@ class Site:
|
|||||||
)
|
)
|
||||||
self.by_uri[content.uri] = content
|
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:
|
def discover(self) -> None:
|
||||||
log.info("Discovering content...")
|
log.info("Discovering content...")
|
||||||
content_path = self.site_path / "content"
|
content_path = self.site_path / "content"
|
||||||
@@ -106,6 +112,7 @@ class Site:
|
|||||||
self.add_by_section(content)
|
self.add_by_section(content)
|
||||||
self.add_by_tag(content)
|
self.add_by_tag(content)
|
||||||
self.content.append(content)
|
self.content.append(content)
|
||||||
|
self.update_tags_by_count()
|
||||||
log.info("Discovered %d content items", len(self.content))
|
log.info("Discovered %d content items", len(self.content))
|
||||||
|
|
||||||
def render_single_index_page(
|
def render_single_index_page(
|
||||||
@@ -151,6 +158,13 @@ class Site:
|
|||||||
index.unlink()
|
index.unlink()
|
||||||
index.symlink_to("page-1.html")
|
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:
|
def render_indices(self) -> None:
|
||||||
sorted_all = sorted(self.content, key=lambda c: c.created, reverse=True)
|
sorted_all = sorted(self.content, key=lambda c: c.created, reverse=True)
|
||||||
self.render_index_pages(sorted_all, self.output_path, None)
|
self.render_index_pages(sorted_all, self.output_path, None)
|
||||||
@@ -162,6 +176,7 @@ class Site:
|
|||||||
self.render_index_pages(
|
self.render_index_pages(
|
||||||
sorted_items, self.output_path / "tags" / tag, None, tag
|
sorted_items, self.output_path / "tags" / tag, None, tag
|
||||||
)
|
)
|
||||||
|
self.render_tags_page()
|
||||||
|
|
||||||
def build(self) -> None:
|
def build(self) -> None:
|
||||||
if not self.origin:
|
if not self.origin:
|
||||||
|
|||||||
@@ -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 %}
|
||||||
Reference in New Issue
Block a user