feed.twig 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <feed xmlns="http://www.w3.org/2005/Atom">
  3. {% spaceless %}
  4. <title>{{ site_title }}</title>
  5. <link href="{{ current_page.url }}" rel="self"/>
  6. <subtitle>
  7. {% if config.tagblog.site_description %}
  8. {{ config.tagblog.site_description }}
  9. {% else %}
  10. Blog feed
  11. {% endif %}
  12. </subtitle>
  13. {# <language>en-us</language> #}
  14. <updated>{{ "now"|date("Y-m-d\\TH:i:sP") }}</updated>
  15. <id>{{ base_url }}</id>
  16. {% if config.tagblog.feed.limit %}
  17. {% set limit = config.tagblog.feed.limit %}
  18. {% else %}
  19. {% set limit = 10 %}
  20. {% endif %}
  21. {# it is not easy to break out of a loop in twig: stackoverflow.com/a/29161205 #}
  22. {% set break = false %}
  23. {% set count = 0 %}
  24. {% for page in pages if not break %}
  25. {% if page.meta.tags %}
  26. <entry>
  27. <title>{{ page.title }}</title>
  28. <link href="{{ page.url }}" rel="alternate"/>
  29. <updated>{{ page.date_formatted|date("Y-m-d\\TH:i:sP") }}</updated>
  30. <published>{{ page.date_formatted|date("Y-m-d\\TH:i:sP") }}</published>
  31. {% if page.author %}
  32. <author><name>{{ page.author }}</name></author>
  33. {% endif %}
  34. {% for tag in page.meta.tags|split(',') %}
  35. <category term="{{ tag }}"/>
  36. {% endfor %}
  37. <id>{{ page.url }}</id>
  38. <summary><![CDATA[{% if page.description %}{{ page.description }}{% else %}{{ page.id|content|striptags|slice(0, 300) }}...{% endif %}]]></summary>
  39. {% if config.tagblog.feed.content is defined and config.tagblog.feed.content %}
  40. <content><![CDATA[{{ page.id|content }}]]></content>
  41. {% endif %}
  42. </entry>
  43. {% set count = count + 1 %}
  44. {% if count == limit %}{% set break = true %}{% endif %}
  45. {% endif %}
  46. {% endfor %}
  47. {% endspaceless %}
  48. </feed>