From a1ac81681b5799715019c3895ef46d8f4a1ffbbf Mon Sep 17 00:00:00 2001 From: Heitor Date: Wed, 26 Jul 2023 18:18:39 -0300 Subject: [PATCH] Atom template authors (#2259) * templates:atom: add support for multiple authors Atom 1.0 [0] support multiple `` entries in the feed. This commit modified the template to generate as many `` 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 --- components/site/tests/site.rs | 5 +++++ components/templates/src/builtins/atom.xml | 12 +++++++++--- .../content/posts/tutorials/programming/rust.md | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/components/site/tests/site.rs b/components/site/tests/site.rs index 2c6d3c46bb..baca868e2b 100644 --- a/components/site/tests/site.rs +++ b/components/site/tests/site.rs @@ -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] diff --git a/components/templates/src/builtins/atom.xml b/components/templates/src/builtins/atom.xml index 2f16095563..4d8b3ec6e7 100644 --- a/components/templates/src/builtins/atom.xml +++ b/components/templates/src/builtins/atom.xml @@ -24,17 +24,23 @@ {{ page.title }} {{ page.date | date(format="%+") }} {{ page.updated | default(value=page.date) | date(format="%+") }} + {% for author in page.authors %} - {%- if page.authors -%} - {{ page.authors[0] }} - {%- elif config.author -%} + {{ author }} + + + {% else %} + + + {%- if config.author -%} {{ config.author }} {%- else -%} Unknown {%- endif -%} + {% endfor %} {{ page.permalink | safe }} {% if page.summary %} diff --git a/test_site/content/posts/tutorials/programming/rust.md b/test_site/content/posts/tutorials/programming/rust.md index e9986e12ea..6a7d8081e7 100644 --- a/test_site/content/posts/tutorials/programming/rust.md +++ b/test_site/content/posts/tutorials/programming/rust.md @@ -2,6 +2,7 @@ title = "Rust" weight = 2 date = 2017-01-01 +authors = ["Foo Doe", "Bar Doe", "Baz Doe"] +++ A simple page