mirror of
https://github.com/jgonyea/grav-plugin-podcast.git
synced 2025-12-05 16:00:02 +01:00
Cleanup and bugfixes for rss and partial template
This commit is contained in:
13
CHANGELOG.md
13
CHANGELOG.md
@@ -1,3 +1,16 @@
|
||||
# v0.9.0
|
||||
## 07/05/2017
|
||||
1. [](#new)
|
||||
* Groundwork for calculating episode duration.
|
||||
* CSS striping added to podcast_archive_list.html.twig partial.
|
||||
2. [](#improved)
|
||||
* Rss feed as well as the partial render an episode's duration.
|
||||
3. [](#bugfix)
|
||||
* Added self-referencing atom tag for rss feed.
|
||||
* Collections now use the correct header date for published date. Falls back to header.date if header.publish_date is not avilable.
|
||||
* Removed a few debug lines.
|
||||
* Removed auto-generated 'text_var' from podcast.yaml
|
||||
|
||||
# v0.1.0
|
||||
## 06/30/2017
|
||||
|
||||
|
||||
51
podcast.php
51
podcast.php
@@ -4,6 +4,7 @@ namespace Grav\Plugin;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Plugin;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
use RocketTheme\Toolbox\File\File;
|
||||
|
||||
/**
|
||||
* Class PodcastPlugin
|
||||
@@ -44,6 +45,7 @@ class PodcastPlugin extends Plugin
|
||||
// Enable the main event we are interested in
|
||||
$this->enable([
|
||||
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
|
||||
'onPageInitialized' => ['onPageInitialized', 0],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -57,7 +59,7 @@ class PodcastPlugin extends Plugin
|
||||
$types->scanBlueprints($locator->findResource('plugin://' . $this->name . '/blueprints'));
|
||||
$types->scanTemplates($locator->findResource('plugin://' . $this->name . '/templates'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add templates directory to twig lookup paths.
|
||||
*/
|
||||
@@ -65,7 +67,52 @@ class PodcastPlugin extends Plugin
|
||||
{
|
||||
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set metadata in header for podcast if audio file is attached.
|
||||
*/
|
||||
public function onPageInitialized($event){
|
||||
$page = $this->grav['page'];
|
||||
$header = $page->header();
|
||||
// Only process podcast pages with audio attached.
|
||||
if( isset($header->podcast['audio']) && $page->name() == 'podcast-episode.md') {
|
||||
|
||||
// Find array key for podcast audio.
|
||||
$key = array_keys($header->podcast['audio']);
|
||||
|
||||
if(!isset($header->podcast['audio'][$key[0]]['duration'])){
|
||||
$audio = $header->podcast['audio'];
|
||||
$dir = $page->path();
|
||||
$fullFileName = $dir. DS . 'podcast-episode.md';
|
||||
$file = File::instance($fullFileName);
|
||||
|
||||
$duration = $this->retreiveAudioDuration($key[0]);
|
||||
$raw = $file->raw();
|
||||
$orig = "type: audio/mpeg\n";
|
||||
$replace = $orig . " duration: $duration\n";
|
||||
$raw = str_replace($orig, $replace, $raw);
|
||||
|
||||
$file->save($raw);
|
||||
$this->grav['log']->info("Added duration to ");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve audio metadata duration.
|
||||
*
|
||||
* @param string $file
|
||||
* Path to audio file.
|
||||
* @return string
|
||||
* Audio file duration.
|
||||
*/
|
||||
public static function retreiveAudioDuration($file) {
|
||||
//todo: change fixed value to calcuated one.
|
||||
return "2:30";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate GUID for podcast entry.
|
||||
*/
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
enabled: true
|
||||
text_var: Custom Text added by the **Podcast** plugin (disable plugin to remove)
|
||||
|
||||
|
||||
@@ -32,10 +32,11 @@
|
||||
<itunes:image href ="{{ (uri.base ~ '/' ~ (episode.header.podcast.itunes.image | first).path) }}"/>
|
||||
<enclosure length="{{ length }}" url="{{ (uri.base ~ '/' ~ (episode.header.podcast.audio | first).path) }}" type="audio/mpeg" />
|
||||
<guid>{{ episode.header.podcast.guid }}</guid>
|
||||
<itunes:duration>{{ length }}</itunes:duration>
|
||||
<pubDate>{{ episode.date|date('D, d M Y H:i:s O') }}</pubDate>
|
||||
<itunes:duration>{{ ((episode.header.podcast.audio)|first).duration }}</itunes:duration>
|
||||
<pubDate>{{ (episode.header.publish_date ?: episode.header.date)|date('D, d M Y H:i:s O') }}</pubDate>
|
||||
</item>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<atom:link href="{{ uri.base ~ base_url ~ page.route ~ '.rss' }}" rel="self" type="application/rss+xml" />
|
||||
</channel>
|
||||
</rss>
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
{% for episode in page.collection %}
|
||||
|
||||
{% if episode.header.podcast.audio %}
|
||||
{% set striping = cycle(["even", "odd"], loop.index) %}
|
||||
{% set striping = cycle(["even", "odd"], loop.index) %}
|
||||
{% set foundItems = TRUE %}
|
||||
{{ dump(episode.path) }}
|
||||
<li class = 'podcast-meta {{ striping }}'>
|
||||
<a href="{{ episode.uri|absolute_url }}"><h3>{{ episode.title }}</h2></a>
|
||||
<p class="date">{{ episode.date|date(' d M Y ') }}</p>
|
||||
<p class="length">Length: </p>
|
||||
<a href="{{ episode.url|absolute_url }}"><h3>{{ episode.title }}</h2></a>
|
||||
<p class="date">{{ (episode.header.publish_date ?: episode.header.date)|date(' d M Y ') }}</p>
|
||||
<p class="length">Length: {{ ((episode.header.podcast.audio)|first).duration }} </p>
|
||||
</li>
|
||||
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user