Add Site.feed_url helper and use it in the template

This commit is contained in:
2026-08-26 05:07:40 +02:00
parent f18392c899
commit a0fa7d8fe2
3 changed files with 11 additions and 1 deletions
+7 -1
View File
@@ -1,6 +1,6 @@
import logging import logging
import shutil import shutil
from typing import Any, cast from typing import Any, Literal, cast
from urllib.parse import urlparse from urllib.parse import urlparse
from omicron.ssg.output import ( from omicron.ssg.output import (
@@ -155,6 +155,12 @@ class Site:
def tags_url(self) -> str: def tags_url(self) -> str:
return self.by_path[Tags.PATH].url return self.by_path[Tags.PATH].url
def feed_url(
self, kind: Literal["root", "section"], label: str | None
) -> str | None:
output = self.by_path.get(Feed.build_path(kind, label))
return output.url if output else None
def update_tags_by_count(self) -> None: def update_tags_by_count(self) -> None:
tags = [(tag, len(items)) for tag, items in self.by_tag.items()] tags = [(tag, len(items)) for tag, items in self.by_tag.items()]
tags.sort(key=lambda x: x[1], reverse=True) tags.sort(key=lambda x: x[1], reverse=True)
+1
View File
@@ -7,6 +7,7 @@
<link rel="stylesheet" href="{{ site.url_for('assets/style.css') }}"> <link rel="stylesheet" href="{{ site.url_for('assets/style.css') }}">
<link rel="stylesheet" href="{{ site.url_for('assets/pygments.css') }}"> <link rel="stylesheet" href="{{ site.url_for('assets/pygments.css') }}">
{% if site.origin %}<link rel="canonical" href="{{ site.origin }}{{ page.url }}">{% endif %} {% if site.origin %}<link rel="canonical" href="{{ site.origin }}{{ page.url }}">{% endif %}
{% if site.feed_url("root", None) %}<link rel="alternate" type="application/atom+xml" title="{{ site.name }}" href="{{ site.feed_url('root', None) }}">{% endif %}
{% block head %}{% endblock %} {% block head %}{% endblock %}
</head> </head>
<body> <body>
+3
View File
@@ -4,6 +4,9 @@
{% block head %} {% block head %}
{% if page.page_num > 1 %}<meta name="robots" content="noindex, follow">{% endif %} {% if page.page_num > 1 %}<meta name="robots" content="noindex, follow">{% endif %}
{% if page.kind == "section" %}
<link rel="alternate" type="application/atom+xml" title="{{ page.label }}" href="{{ site.feed_url('section', page.label) }}">
{% endif %}
{% endblock %} {% endblock %}
{% block breadcrumb %} {% block breadcrumb %}