{%- macro _author(author) -%}
<author>
  <name>{{ author.name or author }}</name>
  {% if author.url %}
  <uri>{{ author.url }}</uri>
  {% endif %}
</author>
{% endmacro -%}

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="{{ options.url }}">
  <title>{{ title or options.homeKey }}</title>
  <link href="{{ page.url | canonicalUrl }}" rel="self"/>
  <updated>{{ collections[collection.name] | getNewestCollectionItemDate | dateToRfc3339 }}</updated>
  <id>{{ options.url }}</id>
  {% for item in collections[collection.name] | sliceFromCollection(collection.limit) %}
  {% set absolutePostUrl = item.url | canonicalUrl %}
  <entry>
    <title>{{ item.data.title }}</title>
    <link href="{{ absolutePostUrl }}"/>
    <updated>{{ item.date | dateToRfc3339 }}</updated>
    <id>{{ absolutePostUrl }}</id>
    {%- if item.data.author is string or item.data.author is mapping -%}
      {{- _author(item.data.author) -}}
    {%- else -%}
      {%- for author in item.data.author -%}
        {{- _author(author) -}}
      {%- endfor -%}
    {%- endif -%}
    <content xml:lang="{{ language or "en" }}" type="html">
      <![CDATA[
        {% if item.data.image %}<figure><img src="{{ item.data.image.src | canonicalUrl }}" alt="{{ item.data.image.alt }}">{% if item.data.image.caption %}<figcaption>{{ item.data.image.caption | markdown }}</figcaption>
        {% endif %}</figure>{% endif %}
        {{- item.templateContent | renderTransforms(item.data.page) }}
      ]]>
    </content>
  </entry>
  {% endfor %}
</feed>
