photos properly included in RSS and Atom feed

This commit is contained in:
Parker TenBroeck 2026-05-02 10:52:48 -04:00
parent 792646c68d
commit b106d42f4d
4 changed files with 111 additions and 2 deletions

54
templates/atom.xml Normal file
View file

@ -0,0 +1,54 @@
{% import "macros/feed.html" as feed_macros %}
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="{{ lang }}">
<title>{{ config.title }}
{%- if term %} - {{ term.name }}
{%- elif section.title %} - {{ section.title }}
{%- endif -%}
</title>
{%- if config.description %}
<subtitle>{{ config.description }}</subtitle>
{%- endif %}
<link rel="self" type="application/atom+xml" href="{{ feed_url | safe }}"/>
<link rel="alternate" type="text/html" href="
{%- if section -%}
{{ section.permalink | escape_xml | safe }}
{%- else -%}
{{ config.base_url | escape_xml | safe }}
{%- endif -%}
"/>
<generator uri="https://www.getzola.org/">Zola</generator>
{% if last_updated is defined %}<updated>{{ last_updated | date(format="%+") }}</updated>{% endif %}
<id>{{ feed_url | safe }}</id>
{%- for page in pages %}
<entry xml:lang="{{ page.lang }}">
<title>{{ page.title }}</title>
<published>{{ page.date | date(format="%+") }}</published>
<updated>{{ page.updated | default(value=page.date) | date(format="%+") }}</updated>
{% for author in page.authors %}
<author>
<name>
{{ author }}
</name>
</author>
{% else %}
<author>
<name>
{%- if config.author -%}
{{ config.author }}
{%- else -%}
Unknown
{%- endif -%}
</name>
</author>
{% endfor %}
<link rel="alternate" type="text/html" href="{{ page.permalink | safe }}"/>
<id>{{ page.permalink | safe }}</id>
{% if page.description %}
<summary type="html">{{ page.description }}</summary>
{% endif %}
<content type="html" xml:base="{{ page.permalink | escape_xml | safe }}">{{ feed_macros::content(page=page) }}</content>
</entry>
{%- endfor %}
</feed>

View file

@ -1,3 +1,5 @@
{% import "macros/figures.html" as figures %}
{%- macro link_alternate(filename, title) -%} {%- macro link_alternate(filename, title) -%}
{%- if filename is ending_with("atom.xml") -%} {%- if filename is ending_with("atom.xml") -%}
{%- set type = 'type="application/atom+xml" ' -%} {%- set type = 'type="application/atom+xml" ' -%}
@ -7,4 +9,15 @@
{%- set type = 'type="application/feed+json" ' -%} {%- set type = 'type="application/feed+json" ' -%}
{%- endif -%} {%- endif -%}
<link rel="alternate" {{ type | default(value="") | safe -}} href="{{ get_url(path=filename) }}" title="{{ title | replace(from='"', to="&quot;") | safe }}"> <link rel="alternate" {{ type | default(value="") | safe -}} href="{{ get_url(path=filename) }}" title="{{ title | replace(from='"', to="&quot;") | safe }}">
{%- endmacro -%} {%- endmacro -%}
{%- macro content(page) -%}
{%if page.taxonomies.category is containing("photo") %}
{{ figures::image(src=page.extra.picture_src, caption=page.description) }}
{% else %}
{% if page.summary %}{{ page.summary }}{% else %}{{ page.content }}{% endif %}
{% endif %}
{%- endmacro -%}

View file

@ -3,7 +3,7 @@
{# {% set image = resize_image(path=src, height=mdata.height, width=mdata.width, format="webp") %} #} {# {% set image = resize_image(path=src, height=mdata.height, width=mdata.width, format="webp") %} #}
<figure class="{% if class %} {{ class }} {% endif %}"> <figure class="{% if class %} {{ class }} {% endif %}">
<img src="{{ get_url(path=src) }}" loading="lazy" height="{{mdata.height}}" width="{{mdata.width}}" alt="{{caption | default(value='')}}" decoding="async" class="zoomable"> <img src="{{ get_url(path=src) }}" loading="lazy" height="{{mdata.height}}" width="{{mdata.width}}" alt="{{caption | default(value='')}}" decoding="async" class="zoomable"/>
{% if caption != "" %} {% if caption != "" %}
<figcaption>{{ caption | markdown() | safe }}</figcaption> <figcaption>{{ caption | markdown() | safe }}</figcaption>
{% endif %} {% endif %}

42
templates/rss.xml Normal file
View file

@ -0,0 +1,42 @@
{% import "macros/feed.html" as feed_macros %}
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>{{ config.title }}
{%- if term %} - {{ term.name }}
{%- elif section.title %} - {{ section.title }}
{%- endif -%}
</title>
<link>
{%- if section -%}
{{ section.permalink | escape_xml | safe }}
{%- else -%}
{{ config.base_url | escape_xml | safe }}
{%- endif -%}
</link>
<description>{{ config.description }}</description>
<generator>Zola</generator>
<language>{{ lang }}</language>
<atom:link href="{{ feed_url | safe }}" rel="self" type="application/rss+xml"/>
{% if last_updated is defined %}<lastBuildDate>{{ last_updated | date(format="%a, %d %b %Y %H:%M:%S %z") }}</lastBuildDate>{% endif %}
{%- for page in pages %}
<item>
<title>{{ page.title }}</title>
<pubDate>{{ page.date | date(format="%a, %d %b %Y %H:%M:%S %z") }}</pubDate>
<author>
{%- if page.authors -%}
{{ page.authors[0] }}
{%- elif config.author -%}
{{ config.author }}
{%- else -%}
Unknown
{%- endif -%}
</author>
<link>{{ page.permalink | escape_xml | safe }}</link>
<guid>{{ page.permalink | escape_xml | safe }}</guid>
<description xml:base="{{ page.permalink | escape_xml | safe }}">{{ feed_macros::content(page=page) }}</description>
</item>
{%- endfor %}
</channel>
</rss>