Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit the RSS feed to 15 entries #1999

Merged
merged 3 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions templates/atom.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% import "macros/atom.html" as atom %}
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="{{ lang }}">
<title>{{ config.title }}
Expand All @@ -19,25 +20,14 @@
<generator uri="https://www.getzola.org/">Zola</generator>
<updated>{{ last_updated | date(format="%+") }}</updated>
<id>{{ feed_url | safe }}</id>
{% set pageslen = pages | length %}
{% if pageslen > 15 %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? Have you tested what end=15 does if there are fewer (or exactly) 15 pages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems needed, here's the output of zola serve without it

Error: Failed to serve the site
Error: Failed to render 'atom.xml'
Error: Reason: Variable `pages[i]` not found in context while rendering 'atom.xml': the evaluated version was `pages.1`. Maybe the index is out of bounds?

{% for i in range(end=15) %}
{{ atom::entry(page=pages[i]) }}
{% endfor %}
{% else %}
{%- 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>
<author>
<name>
{%- if page.authors -%}
{{ page.authors[0] }}
{%- elif config.author -%}
{{ config.author }}
{%- else -%}
Unknown
{%- endif -%}
</name>
</author>
<link rel="alternate" href="{{ page.permalink | safe }}" type="text/html"/>
<id>{{ page.permalink | safe }}</id>
<content type="html">{{ page.content }}</content>
</entry>
{{ atom::entry(page=page) }}
{%- endfor %}
{% endif %}
</feed>
21 changes: 21 additions & 0 deletions templates/macros/atom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% macro entry(page) %}
<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>
<author>
<name>
{%- if page.authors -%}
{{ page.authors[0] }}
{%- elif config.author -%}
{{ config.author }}
{%- else -%}
Unknown
{%- endif -%}
</name>
</author>
<link rel="alternate" href="{{ page.permalink | safe }}" type="text/html"/>
<id>{{ page.permalink | safe }}</id>
<content type="html">{{ page.content }}</content>
</entry>
{% endmacro %}
Loading