poschi3 / podlove-publisher-templates

Podlove Publisher Templates of https://podcast.entbehrlich.es/
MIT License
6 stars 2 forks source link

Not usable in Podlove #1

Open nie-froehlich opened 1 month ago

nie-froehlich commented 1 month ago

as of version 4.1.15, a change breaks this template. Here's the changelog for the release in question:

security: disable unsafe Twig Template filters „filter“, „map“ and „reduce“

Unfortunately, the template makes heavy use of filter and therefore doesn't work with that version of Podlove any longer.

poschi3 commented 1 month ago

@nie-froehlich Thank you for pointing out. I think we can work around the filter method. I'll try to fix it if I find some spar time.

nie-froehlich commented 1 month ago

With a little help from an AI friend I came up with this solution. This is for statistik.twig:

{% set sum = 0 %}
{% set count = 0 %}
{% for episode in podcast.episodes %}
   {% set sum = sum + episode.duration.totalMilliseconds %} 
   {% set count = count + 1 %}
{% endfor %}

{% set validEpisodes = [] %}

{% for episode in podcast.episodes %}
    {% if episode.total_downloads > 0 %}
        {% set validEpisodes = validEpisodes | merge([episode]) %}
    {% endif %}
{% endfor %}

<p>Bisher haben wir <b>{{ count }} Folgen</b> veröffentlicht die <b>im Durchschnitt {{ (sum / count / 1000 / 60)|round(0, 'floor') }} Minuten</b> lang sind. In Summe haben wir schon <b>{{ (sum / 1000 / 60)|round(0, 'floor') }} Minuten gepodcasted</b>, das sind <b>{{ (sum / 1000 / 60 / 60)|round(2) }} Stunden</b>.</p>

<h2>Downloads</h2>
{% set latest = podcast.episodes[0] %}
<p>Unsere aktuelle Folge (<a href="{{ latest.url }}"><b>{{ latest.title }}</b></a>) hat bisher <b>{{ latest.total_downloads }} Downloads</b>. {% if not latest.meta('_podlove_downloads_2d') is empty %} In den ersten 48 Stunden waren es <b>{{  latest.meta('_podlove_downloads_2d') }} Abrufe</b>.{% endif %}</p>

<script src="https://unpkg.com/chartkick@4.0.4/dist/chartkick.js"></script>
<script src="https://unpkg.com/chart.js@3.3.2/dist/chart.js"></script
<script src="https://unpkg.com/chartjs-adapter-date-fns@2.0.0/dist/chartjs-adapter-date-fns.bundle.js"></script>
<!--
<script src="/wp-content/uploads/js/chartkick.js"></script>
<script src="/wp-content/uploads/js/chart.js"></script>
<script src="/wp-content/uploads/js/chartjs-adapter-date-fns.bundle.js"></script>
-->

<div id="all-episodes" style="height: 300px;"></div>
<script>
    new Chartkick.ColumnChart("all-episodes", [
        {% for episode in podcast.episodes({publicationDate: 'title', 'order': 'ASC'}) %}
            {% if episode.total_downloads > 0 %}
                ["{{ episode.title|escape('js') }}", {{ episode.total_downloads|escape('js') }}],
            {% endif %}
        {% endfor %}
    ]);
</script>

<p></p>
<p>Gezählt werden <a href="https://docs.podlove.org/podlove-publisher/reference/download-analytics">Downloadversuche</a>.</p>

<h3>Unsere beliebtesten Folgen</h3>
<ul>
    {% set sortedEpisodes = validEpisodes | sort((a, b) => b.total_downloads <=> a.total_downloads) %}

    {% for episode in sortedEpisodes[:5] %}
        <li>
            <a href="{{ episode.url }}"><b>{{ episode.title }}</b></a> ({{ episode.total_downloads }} Downloads)
        </li>
    {% endfor %}
</ul>

<h3>Unsere Folgen mit Potential</h3>
<ul>
    {% set sortedEpisodes = validEpisodes | sort((a, b) => a.total_downloads <=> b.total_downloads) %}

    {% for episode in sortedEpisodes[:5] %}
        <li>
            <a href="{{ episode.url }}"><b>{{ episode.title }}</b></a> ({{ episode.total_downloads }} Downloads)
        </li>
    {% endfor %}
</ul>

<h2>Folgenlänge</h2>

<div id="episode-length" style="height: 300px;"></div>
<script>
    new Chartkick.ColumnChart("episode-length", [
        {% for episode in podcast.episodes({publicationDate: 'title', 'order': 'ASC'}) %}
            {% if episode.total_downloads > 0 %}
                ["{{ episode.title|escape('js') }}", {{ (episode.duration.totalMilliseconds / 1000 / 60)|round(0, 'floor') }}],
            {% endif %}
        {% endfor %}
    ]);
</script>

<h3>Unsere längsten Folgen</h3>
<ul>
    {% set sortedEpisodes = validEpisodes | sort((a, b) => b.duration.totalMilliseconds <=> a.duration.totalMilliseconds) %}

    {% for episode in sortedEpisodes[:5] %}
        <li>
            <a href="{{ episode.url }}"><b>{{ episode.title }}</b></a> ({{ episode.duration }})
        </li>
    {% endfor %}
</ul>

<h3>Unsere kürzesten Folgen</h3>
<ul>
    {% set sortedEpisodes = validEpisodes | sort((a, b) => a.duration.totalMilliseconds <=> b.duration.totalMilliseconds) %}

    {% for episode in sortedEpisodes[:5] %}
        <li>
            <a href="{{ episode.url }}"><b>{{ episode.title }}</b></a> ({{ episode.duration }})
        </li>
    {% endfor %}
</ul>

<h2>Unsere meist diskutierten Folgen</h2>
<ul>
    {% for episode in podcast.episodes|sort((b, a) => a.post.comment_count <=> b.post.comment_count)|slice(0,5) %}
        <li>
            <a href="{{ episode.url }}#comments"><b>{{ episode.title }}</b></a> ({{ episode.post.comment_count }} Kommentare)

        </li>
    {% endfor %}
</ul>

<p>Ihr wollt die Statistik auch für euren Podlove-Podcast? Das <a href="https://github.com/poschi3/podlove-publisher-templates">Template findet ihr auf Github</a>.</p>