Skip to content

Commit

Permalink
Atom template authors (#2259)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
heitorPB authored and Keats committed Dec 18, 2023
1 parent c18a0c8 commit a1ac816
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions components/site/tests/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,11 @@ fn can_build_feeds() {
assert!(file_contains!(public, "posts/tutorials/programming/atom.xml", "Rust"));
// It doesn't contain articles from other sections
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]
Expand Down
12 changes: 9 additions & 3 deletions components/templates/src/builtins/atom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,23 @@
<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>
{%- if page.authors -%}
{{ page.authors[0] }}
{%- elif config.author -%}
{{ author }}
</name>
</author>
{% else %}
<author>
<name>
{%- if config.author -%}
{{ config.author }}
{%- else -%}
Unknown
{%- endif -%}
</name>
</author>
{% endfor %}
<link rel="alternate" href="{{ page.permalink | safe }}" type="text/html"/>
<id>{{ page.permalink | safe }}</id>
{% if page.summary %}
Expand Down
1 change: 1 addition & 0 deletions test_site/content/posts/tutorials/programming/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title = "Rust"
weight = 2
date = 2017-01-01
authors = ["Foo Doe", "Bar Doe", "Baz Doe"]
+++

A simple page
Expand Down

0 comments on commit a1ac816

Please sign in to comment.