feed.twig 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. {% if config.tagblog.feed.content is defined and config.tagblog.feed.content %}
  41. <content:encoded><![CDATA[{{ page.id|content }}]]></content:encoded>
  42. {% endif %}
  43. </item>
  44. {% set count = count + 1 %}
  45. {% if count == limit %}{% set break = true %}{% endif %}
  46. {% endif %}
  47. {% endfor %}
  48. </channel>
  49. {% endspaceless %}
  50. </rss>