#13 Make feed a real Atom feed

Merged
ohnonot merged 1 commits from raspbeguy/atom-compliance into ohnonot/master 4 years ago
1 changed files with 45 additions and 47 deletions
  1. 45 47
      feed.twig

+ 45 - 47
feed.twig

@@ -1,52 +1,50 @@
-<?xml version="1.0"?>
-<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
 {% spaceless %}
-    <channel>
-        <title>{{ site_title }}</title>
-        <link>{{ base_url }}</link>
-        <atom:link href="{{ current_page.url }}" rel="self" type="application/rss+xml" />
-        <description>
-            {% if config.tagblog.site_description %}
-                {{ config.tagblog.site_description }}
-            {% else %}
-                Blog feed
-            {% endif %}
-        </description>
-        {# <language>en-us</language> #}
-        <pubDate>{{ "now"|date("r") }}</pubDate>
-        <lastBuildDate>{{ "now"|date("r") }}</lastBuildDate>
-
-        {% if config.tagblog.feed.limit %}
-            {% set limit = config.tagblog.feed.limit %}
+    <title>{{ site_title }}</title>
+    <link href="{{ current_page.url }}" rel="self"/>
+    <subtitle>
+        {% if config.tagblog.site_description %}
+            {{ config.tagblog.site_description }}
         {% else %}
-            {% set limit = 10 %}
+            Blog feed
         {% endif %}
-        {# it is not easy to break out of a loop in twig: stackoverflow.com/a/29161205 #}
-        {% set break = false %}
-        {% set count = 0 %}
-        {% for page in pages if not break %}
-            {% if page.meta.tags %}
-                <item>
-                    <title>{{ page.title }}</title>
-                    <link>{{ page.url }}</link>
-                    <pubDate>{{ page.date_formatted|date("r") }}</pubDate>
-                    {% if page.author %}
-                        <author>{{ page.author }}</author>
-                    {% endif %}
-                    {% for tag in page.meta.tags|split(',') %}
-                        <category>{{ tag }}</category>
-                    {% endfor %}
-                    <guid>{{ page.url }}</guid>
-                    <description><![CDATA[{% if page.description %}{{ page.description }}{% else %}{{ page.id|content|striptags|slice(0, 300) }}...{% endif %}]]></description>
-                    {% if config.tagblog.feed.content is defined and config.tagblog.feed.content %}
-                        <content:encoded><![CDATA[{{ page.id|content }}]]></content:encoded>
-                    {% endif %}
+    </subtitle>
+    {# <language>en-us</language> #}
+    <updated>{{ "now"|date("Y-m-d\\TH:i:sP") }}</updated>
+    <id>{{ base_url }}</id>
+
+    {% if config.tagblog.feed.limit %}
+        {% set limit = config.tagblog.feed.limit %}
+    {% else %}
+        {% set limit = 10 %}
+    {% endif %}
+    {# it is not easy to break out of a loop in twig: stackoverflow.com/a/29161205 #}
+    {% set break = false %}
+    {% set count = 0 %}
+    {% for page in pages if not break %}
+        {% if page.meta.tags %}
+            <entry>
+                <title>{{ page.title }}</title>
+                <link href="{{ page.url }}" rel="alternate"/>
+                <updated>{{ page.date_formatted|date("Y-m-d\\TH:i:sP") }}</updated>
+                <published>{{ page.date_formatted|date("Y-m-d\\TH:i:sP") }}</published>
+                {% if page.author %}
+                    <author><name>{{ page.author }}</name></author>
+                {% endif %}
+                {% for tag in page.meta.tags|split(',') %}
+                    <category term="{{ tag }}"/>
+                {% endfor %}
+                <id>{{ page.url }}</id>
+                <summary><![CDATA[{% if page.description %}{{ page.description }}{% else %}{{ page.id|content|striptags|slice(0, 300) }}...{% endif %}]]></summary>
+                {% if config.tagblog.feed.content is defined and config.tagblog.feed.content %}
+                    <content><![CDATA[{{ page.id|content }}]]></content>
+                {% endif %}
 
-                </item>
-                {% set count = count + 1 %}
-                {% if count == limit %}{% set break = true %}{% endif %}
-            {% endif %}
-        {% endfor %}
-    </channel>
+            </entry>
+            {% set count = count + 1 %}
+            {% if count == limit %}{% set break = true %}{% endif %}
+        {% endif %}
+    {% endfor %}
 {% endspaceless %}
-</rss>
+</feed>