feed.twig 1.9 KB

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