Atom template authors (#2259)

* templates:atom: add support for multiple authors

Atom 1.0 [0] support multiple `<author>` entries in the feed. This commit
modified the template to generate as many `<author>` as the page's
metadata contains.

[0] https://validator.w3.org/feed/docs/atom.html#recommendedEntryElements

* Test we can have multiple authors in ATOM feeds
This commit is contained in:
Heitor 2023-07-26 18:18:39 -03:00 committed by Vincent Prouillet
parent c18a0c8031
commit a1ac81681b
3 changed files with 15 additions and 3 deletions

View File

@ -680,6 +680,11 @@ fn can_build_feeds() {
assert!(file_contains!(public, "posts/tutorials/programming/atom.xml", "Rust")); assert!(file_contains!(public, "posts/tutorials/programming/atom.xml", "Rust"));
// It doesn't contain articles from other sections // It doesn't contain articles from other sections
assert!(!file_contains!(public, "posts/tutorials/programming/atom.xml", "Extra Syntax")); assert!(!file_contains!(public, "posts/tutorials/programming/atom.xml", "Extra Syntax"));
// Test Atom feed entry with 3 authors
assert!(file_contains!(public, "posts/tutorials/programming/atom.xml", "Foo Doe"));
assert!(file_contains!(public, "posts/tutorials/programming/atom.xml", "Bar Doe"));
assert!(file_contains!(public, "posts/tutorials/programming/atom.xml", "Baz Doe"));
} }
#[test] #[test]

View File

@ -24,17 +24,23 @@
<title>{{ page.title }}</title> <title>{{ page.title }}</title>
<published>{{ page.date | date(format="%+") }}</published> <published>{{ page.date | date(format="%+") }}</published>
<updated>{{ page.updated | default(value=page.date) | date(format="%+") }}</updated> <updated>{{ page.updated | default(value=page.date) | date(format="%+") }}</updated>
{% for author in page.authors %}
<author> <author>
<name> <name>
{%- if page.authors -%} {{ author }}
{{ page.authors[0] }} </name>
{%- elif config.author -%} </author>
{% else %}
<author>
<name>
{%- if config.author -%}
{{ config.author }} {{ config.author }}
{%- else -%} {%- else -%}
Unknown Unknown
{%- endif -%} {%- endif -%}
</name> </name>
</author> </author>
{% endfor %}
<link rel="alternate" href="{{ page.permalink | safe }}" type="text/html"/> <link rel="alternate" href="{{ page.permalink | safe }}" type="text/html"/>
<id>{{ page.permalink | safe }}</id> <id>{{ page.permalink | safe }}</id>
{% if page.summary %} {% if page.summary %}

View File

@ -2,6 +2,7 @@
title = "Rust" title = "Rust"
weight = 2 weight = 2
date = 2017-01-01 date = 2017-01-01
authors = ["Foo Doe", "Bar Doe", "Baz Doe"]
+++ +++
A simple page A simple page