Add Site.feed_url helper and use it in the template
This commit is contained in:
+7
-1
@@ -1,6 +1,6 @@
|
||||
import logging
|
||||
import shutil
|
||||
from typing import Any, cast
|
||||
from typing import Any, Literal, cast
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from omicron.ssg.output import (
|
||||
@@ -155,6 +155,12 @@ class Site:
|
||||
def tags_url(self) -> str:
|
||||
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:
|
||||
tags = [(tag, len(items)) for tag, items in self.by_tag.items()]
|
||||
tags.sort(key=lambda x: x[1], reverse=True)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<link rel="stylesheet" href="{{ site.url_for('assets/style.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.feed_url("root", None) %}<link rel="alternate" type="application/atom+xml" title="{{ site.name }}" href="{{ site.feed_url('root', None) }}">{% endif %}
|
||||
{% block head %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
|
||||
{% block head %}
|
||||
{% 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 %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
|
||||
Reference in New Issue
Block a user