Skip to content

Commit 66f5bf5

Browse files
authored
Atom template authors (getzola#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
1 parent afc0e2c commit 66f5bf5

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

components/site/tests/site.rs

+5
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,11 @@ fn can_build_feeds() {
680680
assert!(file_contains!(public, "posts/tutorials/programming/atom.xml", "Rust"));
681681
// It doesn't contain articles from other sections
682682
assert!(!file_contains!(public, "posts/tutorials/programming/atom.xml", "Extra Syntax"));
683+
684+
// Test Atom feed entry with 3 authors
685+
assert!(file_contains!(public, "posts/tutorials/programming/atom.xml", "Foo Doe"));
686+
assert!(file_contains!(public, "posts/tutorials/programming/atom.xml", "Bar Doe"));
687+
assert!(file_contains!(public, "posts/tutorials/programming/atom.xml", "Baz Doe"));
683688
}
684689

685690
#[test]

components/templates/src/builtins/atom.xml

+9-3
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,23 @@
2424
<title>{{ page.title }}</title>
2525
<published>{{ page.date | date(format="%+") }}</published>
2626
<updated>{{ page.updated | default(value=page.date) | date(format="%+") }}</updated>
27+
{% for author in page.authors %}
2728
<author>
2829
<name>
29-
{%- if page.authors -%}
30-
{{ page.authors[0] }}
31-
{%- elif config.author -%}
30+
{{ author }}
31+
</name>
32+
</author>
33+
{% else %}
34+
<author>
35+
<name>
36+
{%- if config.author -%}
3237
{{ config.author }}
3338
{%- else -%}
3439
Unknown
3540
{%- endif -%}
3641
</name>
3742
</author>
43+
{% endfor %}
3844
<link rel="alternate" href="{{ page.permalink | safe }}" type="text/html"/>
3945
<id>{{ page.permalink | safe }}</id>
4046
{% if page.summary %}

test_site/content/posts/tutorials/programming/rust.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title = "Rust"
33
weight = 2
44
date = 2017-01-01
5+
authors = ["Foo Doe", "Bar Doe", "Baz Doe"]
56
+++
67

78
A simple page

0 commit comments

Comments
 (0)