jgonyea / grav-plugin-podcast

GravCMS plugin that creates podcast channel and podcast episode page templates along with a podcast RSS feed.
MIT License
18 stars 7 forks source link

Podcast plugin feed.rss.twig override is applying sitewide, causing blank rss feeds. #56

Closed jgonyea closed 2 years ago

jgonyea commented 2 years ago

Due to how I'm overriding the default feed.rss.twig file, if someone attempts to create a "normal" feed elsewhere on the site, the rss feed returns blank.

jgonyea commented 2 years ago

Bandaid fix is to apply the following to the podcast's feed.rss.twig at the end of the file:

+{% else %}
+{# Copied from the default feed.rss.twig #}
+{# Format specification: https://www.rssboard.org/rss-specification #}
+{% set collection = collection|default(page.collection) %}
+{% set lastBuildDate = 0 %}
+{% for page in collection %}
+    {%- set lastBuildDate = max(lastBuildDate, page.date) %}
+    {%- if collection.params.show_last_modified %}
+        {%- set lastBuildDate = max(feed_updated, page.modified) %}
+    {%- endif %}
+{% endfor %}
+<?xml version="1.0" encoding="utf-8"?>
+<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
+    <channel>
+        <title>{{ collection.params.title }}</title>
+        <link>{{ page.url(true) }}</link>
+        <atom:link href="{{ uri.rootUrl(true)~uri.uri() }}" rel="self" type="application/rss+xml"/>
+        <description>{{ collection.params.description }}</description>
+        <language>{{ grav.language.getLanguage|default(config.system.language.default_lang)|default('en') }}</language>
+        <lastBuildDate>{{ lastBuildDate|date('D, d M Y H:i:s O') }}</lastBuildDate>
+        {% for item in collection %}
+        {% set banner = item.media.images|first %}
+        <item>
+            <title>{{ item.title|e }}</title>
+            <link>{{ item.url(true) }}</link>
+            <guid>{{ item.url(true) }}</guid>
+            <pubDate>{{ item.date|date('D, d M Y H:i:s O') }}</pubDate>
+            <description>
+                <![CDATA[
+                {% if banner %}
+                {{ banner.cropZoom(1200,800).html|absolute_url|raw }}
+                {% endif %}
+                {{ item.content|safe_truncate_html(collection.params.length)|raw }}
+                ]]>
+            </description>
+            {% for tag in item.taxonomy.tag %}
+                <category>{{ tag|e }}</category>
+            {% endfor %}
+        </item>
+        {% endfor %}
+    </channel>
+</rss>
 {% endif %}
jgonyea commented 2 years ago

Addressed in 3.0.7