<?xml version="1.0" encoding="utf-8"?>
<feed {% block feed_attributes %}xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"{% endblock %}>
    {%- block feed_elements %}
        {%- block feed_title %}
            <title type="html">{{ config.kerko.meta.title|escape }} - {{ feed_title|escape }}</title>
        {%- endblock %}
        {%- block feed_author %}
            <author>
                <name>{{ config.kerko.meta.title|escape }}</name>
                <uri>{{ url_for('kerko.search', _external=True)|escape }}</uri>
            </author>
        {%- endblock %}
        <link rel="alternate" type="text/html" href="{{ html_url|escape }}"/>
        <link rel="self" type="application/atom+xml" href="{{ feed_url|escape }}"/>
        {#- RFC 5005 paged feed links #}
        {%- if pager.first %}
            <link rel="first" type="application/atom+xml" href="{{ pager.first[0].url|escape }}"/>
        {%- endif %}
        {%- if pager.previous %}
            <link rel="previous" type="application/atom+xml" href="{{ pager.previous[0].url|escape }}"/>
        {%- endif %}
        {%- if pager.next %}
            <link rel="next" type="application/atom+xml" href="{{ pager.next[0].url|escape }}"/>
        {%- endif %}
        {%- if pager.last %}
            <link rel="last" type="application/atom+xml" href="{{ pager.last[0].url|escape }}"/>
        {%- endif %}
        <updated>{{ last_sync }}</updated>
        <id>{{ feed_url|escape }}</id>
        <generator uri="https://github.com/whiskyechobravo/kerko">Kerko</generator>
    {%- endblock %}
    {%- block feed_entries %}
        {%- for item in items %}
            <entry>
                {%- block feed_entry scoped %}
                    <title type="html">{{ kerko_item_title(item)|kerko_richtext_escape|forceescape }}</title>
                    <link type="text/html" href="{{ url_for('kerko.item_view', item_id=item.id, _external=True)|escape }}"/>
                    <id>{{ url_for('kerko.item_view', item_id=item.id, _external=True)|escape }}</id>
                    <published>{{ item.data.dateAdded|escape }}</published>
                    <updated>{{ item.data.dateModified|escape }}</updated>
                    {%- if item.data.abstractNote %}
                        <summary type="html">{{ item.data.abstractNote|kerko_richtext_escape|forceescape }}</summary>
                    {%- endif %}
                    {%- for creator in item.data.creators %}
                        {%- if creator.display %}
                            <dc:creator>{{ creator.display|kerko_richtext_escape|striptags|forceescape }}</dc:creator>
                        {%- endif %}
                    {%- endfor %}
                    {%- with item_date = [item.data.date, item.data.dateDecided, item.data.dateEnacted, item.data.filingDate, item.data.issueDate]|select|first %}
                        {%- if item_date %}
                            <dc:date>{{ item_date|escape }}</dc:date>
                        {%- endif %}
                    {%- endwith %}
                    {%- if item.data.DOI %}
                        <dc:identifier>{{ item.data.DOI|kerko_urlize_doi(link=False)|escape }}</dc:identifier>
                        {#- TODO: If item.data.DOI empty, check if it can be parsed from the Extra field. #}
                    {%- endif %}
                    {%- if item.data.ISBN %}
                        <dc:identifier>{{ item.data.ISBN|kerko_richtext_escape|striptags|forceescape }}</dc:identifier>
                    {%- endif %}
                    {%- if item.data.ISSN %}
                        <dc:identifier>{{ item.data.ISSN|kerko_richtext_escape|striptags|forceescape }}</dc:identifier>
                    {%- endif %}
                    {%- if item.data.language %}
                        <dc:language>{{ item.data.language|kerko_richtext_escape|striptags|forceescape }}</dc:language>
                    {%- endif %}
                    {%- if item.data.publisher %}
                        <dc:publisher>{{ item.data.publisher|kerko_richtext_escape|striptags|forceescape }}</dc:publisher>
                    {%- endif %}
                    {%- if item.data.rights %}
                        <dc:rights>{{ item.data.rights|kerko_richtext_escape|striptags|escape|forceescape }}</dc:rights>
                    {%- endif %}
                    <dc:title>{{ kerko_item_title(item)|kerko_richtext_escape|striptags|forceescape }}</dc:title>
                {%- endblock feed_entry %}
            </entry>
        {%- endfor %}
    {%- endblock feed_entries %}
</feed>
