aggregate enclosures
authorJoey Hess <joeyh@joeyh.name>
Sat, 25 Dec 2021 16:58:24 +0000 (12:58 -0400)
committerJoey Hess <joeyh@joeyh.name>
Sat, 25 Dec 2021 16:59:27 +0000 (12:59 -0400)
aggregate: When a feed has an enclosure that is an image, audio, or video,
include the enclosure in the generated page.

The enclosure is hotlinked from the original feed, not copied.

My use case is to include a mastodon rss feed in amoung other rss feeds for
users who don't use mastodon. It could also be used to aggregate together
podcasts, etc.

Other enclosure types than image, audio, video, could be added, perhaps
a generic one? But these are the main ones.

The template uses 50% width for image and video, because often
attachments are in a high resolution, which will default to being
perhaps too wide for the page, or taking up a lot of vertical space. By
making it take up at most half the page width, that is avoided, while
also leaving room for any sidebar.

Sponsored-by: Shae Erisson on Patreon
CHANGELOG
IkiWiki/Plugin/aggregate.pm
templates/aggregatepost.tmpl

index 9360a8f26de07f53ac442582367c5274929492ad..f33c3bd14d2317de43d328f99ffa3d63ae9dde4e 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,10 @@
+ikiwiki (3.20200202.4) UNRELEASED; urgency=medium
+
+  * aggregate: When a feed has an enclosure that is an image, audio, or
+    video, include the enclosure in the generated page.
+
+ -- Joey Hess <id@joeyh.name>  Sat, 25 Dec 2021 12:41:34 -0400
+
 ikiwiki (3.20200202.3) upstream; urgency=medium
 
   [ Amitai Schleier ]
index 8f0870e2eea27257135aef9d5daaf6731c036506..01e026c880c16d8c04964648c774b718429d7521 100644 (file)
@@ -590,6 +590,10 @@ sub aggregate (@) {
                                title => defined $entry->title ? decode_entities($entry->title) : "untitled",
                                author => defined $entry->author ? decode_entities($entry->author) : "",
                                link => $entry->link,
+                               enclosureurl => defined $entry->enclosure ? $entry->enclosure->url : "",
+                               enclosureimage => (defined $entry->enclosure && $entry->enclosure->type =~ m/image\//) ? "1" : "",
+                               enclosureaudio => (defined $entry->enclosure && $entry->enclosure->type =~ m/audio\//) ? "1" : "",
+                               enclosurevideo => (defined $entry->enclosure && $entry->enclosure->type =~ m/video\//) ? "1" : "",
                                content => (defined $c && defined $c->body) ? $c->body : "",
                                guid => defined $entry->id ? $entry->id : time."_".$feed->{name},
                                ctime => $entry->issued ? ($entry->issued->epoch || time) : time,
@@ -700,6 +704,14 @@ sub write_page ($$$$$) {
                if defined $params{copyright} && length $params{copyright};
        $template->param(permalink => IkiWiki::urlabs($params{link}, $feed->{feedurl}))
                if defined $params{link};
+       $template->param(enclosureurl => $params{enclosureurl})
+               if defined $params{enclosureurl} && length $params{enclosureurl};
+       $template->param(enclosureimage => $params{enclosureimage})
+               if defined $params{enclosureimage} && length $params{enclosureimage};
+       $template->param(enclosureaudio => $params{enclosureaudio})
+               if defined $params{enclosureaudio} && length $params{enclosureaudio};
+       $template->param(enclosurevideo => $params{enclosurevideo})
+               if defined $params{enclosurevideo} && length $params{enclosurevideo};
        if (ref $feed->{tags}) {
                $template->param(tags => [map { tag => $_ }, @{$feed->{tags}}]);
        }
index 5a0f6e7805b299feee7b4077a58cad0af557e02b..0d2c2d94e3944c347a37ff8ea17b7f9957cff675 100644 (file)
@@ -1,4 +1,15 @@
 <TMPL_VAR CONTENT>
+<TMPL_IF ENCLOSUREURL>
+<TMPL_IF ENCLOSUREIMAGE>
+<img src="<TMPL_VAR ENCLOSUREURL ESCAPE=HTML>" width="50%" />
+</TMPL_IF>
+<TMPL_IF ENCLOSUREAUDIO>
+<audio controls src="<TMPL_VAR ENCLOSUREURL ESCAPE=HTML>" />
+</TMPL_IF>
+<TMPL_IF ENCLOSUREVIDEO>
+<video controls src="<TMPL_VAR ENCLOSUREURL ESCAPE=HTML>" width="50%" />
+</TMPL_IF>
+</TMPL_IF>
 <TMPL_LOOP TAGS>
 [[!tag <TMPL_VAR TAG>]]
 </TMPL_LOOP>