feed => $feed,
copyright => $f->copyright,
title => defined $entry->title ? decode_entities($entry->title) : "untitled",
+ author => defined $entry->author ? decode_entities($entry->author) : "",
link => $entry->link,
content => (defined $c && defined $c->body) ? $c->body : "",
guid => defined $entry->id ? $entry->id : time."_".$feed->{name},
}
$template->param(title => $params{title})
if defined $params{title} && length($params{title});
+ $template->param(author => $params{author})
+ if defined $params{author} && length($params{author}
+ && $params{author} ne $feed->{name});
$template->param(content => wikiescape(htmlabs($params{content},
defined $params{base} ? $params{base} : $feed->{feedurl})));
$template->param(name => $feed->{name});
return $ret;
}
+sub genenclosure {
+ my $itemtemplate=shift;
+ my $url=shift;
+ my $file=shift;
+
+ return unless $itemtemplate->query(name => "enclosure");
+
+ my $size=(srcfile_stat($file))[8];
+ my $mime="unknown";
+ eval q{use File::MimeInfo};
+ if (! $@) {
+ $mime = mimetype($file);
+ }
+ $itemtemplate->param(
+ enclosure => $url,
+ type => $mime,
+ length => $size,
+ );
+}
+
sub genfeed ($$$$$@) {
my $feedtype=shift;
my $feedurl=shift;
foreach my $p (@pages) {
my $u=URI->new(encode_utf8(urlto($p, "", 1)));
my $pcontent = absolute_urls(get_inline_content($p, $page), $url);
+ my $fancy_enclosure_seen = 0;
$itemtemplate->param(
title => pagetitle(basename($p)),
$itemtemplate->param(mdate_822 => date_822($pagestate{$p}{meta}{updated}));
$itemtemplate->param(mdate_3339 => date_3339($pagestate{$p}{meta}{updated}));
}
- }
- if ($itemtemplate->query(name => "enclosure")) {
- my $file=$pagesources{$p};
- my $type=pagetype($file);
- if (defined $type) {
- $itemtemplate->param(content => $pcontent);
- }
- else {
- my $size=(srcfile_stat($file))[8];
- my $mime="unknown";
- eval q{use File::MimeInfo};
- if (! $@) {
- $mime = mimetype($file);
- }
- $itemtemplate->param(
- enclosure => $u,
- type => $mime,
- length => $size,
- );
+ if (exists $pagestate{$p}{meta}{enclosure}) {
+ my $absurl = $pagestate{$p}{meta}{enclosure};
+ my $file = $pagestate{$p}{meta}{enclosurefile};
+ genenclosure($itemtemplate, $absurl, $file);
+ $fancy_enclosure_seen = 1;
}
}
- else {
- $itemtemplate->param(content => $pcontent);
+
+ my $file=$pagesources{$p};
+ unless ($fancy_enclosure_seen || defined(pagetype($file))) {
+ genenclosure($itemtemplate, $u, $file);
+ $itemtemplate->param(simplepodcast => 1);
}
+ $itemtemplate->param(content => $pcontent);
+
run_hooks(pagetemplate => sub {
shift->(page => $p, destpage => $page,
template => $itemtemplate);
feeddesc => $feeddesc,
guid => $guid,
feeddate => date_3339($lasttime),
+ feeddate_822 => date_822($lasttime),
feedurl => $feedurl,
);
run_hooks(pagetemplate => sub {
add_link($page, $value);
return "";
}
+ elsif ($key eq 'enclosure') {
+ my $link=bestlink($page, $value);
+ if (! length $link) {
+ error gettext("enclosure not found")
+ }
+ add_depends($page, $link, deptype("presence"));
+
+ $value=urlto($link, $page, 1);
+ $pagestate{$page}{meta}{enclosure}=$value;
+ $pagestate{$page}{meta}{enclosurefile}=$link;
+ # fallthrough
+ }
elsif ($key eq 'author') {
$pagestate{$page}{meta}{author}=$value;
if (exists $params{sortas}) {
$template->param(title_overridden => 1);
}
+ if (exists $pagestate{$page}{meta}{enclosure}) {
+ $template->param(enclosure => HTML::Entities::encode_entities(IkiWiki::urlabs($pagestate{$page}{meta}{enclosure}, $config{url})));
+ }
+
foreach my $field (qw{authorurl}) {
eval q{use HTML::Entities};
$template->param($field => HTML::Entities::encode_entities($pagestate{$page}{meta}{$field}))
the wiki. This can be used to create a Planet type site that aggregates
interesting feeds.
-You can also mix blogging with podcasting by dropping audio files where
-they will be picked up like blog posts. This will work for any files that
-you would care to syndicate.
+You can also mix blogging with podcasting. Simply drop media files
+where they will be picked up like blog posts. For fuller-featured
+podcast feeds, enclose media files in blog posts using [[plugins/meta]].
+Either way, this will work for any files that you would care to
+syndicate.
## Valid html and [[css]]
[[SubPage]] of "blog") will be part of the blog, and the newest 10
of them will appear in the page. Note that if files that are not pages
match the [[PageSpec]], they will be included in the feed using RSS
-enclosures, which is useful for podcasting.
+enclosures, which is useful for simple podcasting; for fuller-featured
+podcast feeds, enclose media files in blog posts using [[meta]].
The optional `rootpage` parameter tells the wiki that new posts to this
blog should default to being [[SubPages|SubPage]] of "blog", and enables a
[[!iki plugins/htmlscrubber desc=htmlscrubber]] plugin is enabled, since it can be used to
insert unsafe content.
+* enclosure
+
+ Specifies a link to a file to be rendered as an "enclosure" in
+ RSS/Atom feeds (and a plain old link in HTML). Useful for podcasting.
+
* redir
Causes the page to redirect to another page in the wiki.
border-bottom: 1px solid #000;
}
-.inlinecontent {
+.inlinecontent,
+.inlineenclosure {
margin-top: .4em;
}
--- /dev/null
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+BEGIN {
+ eval q{use XML::Feed; use HTML::Parser; use HTML::LinkExtor};
+ if ($@) {
+ eval q{use Test::More skip_all =>
+ "XML::Feed and/or HTML::Parser not available"};
+ }
+ else {
+ eval q{use Test::More tests => 136};
+ }
+}
+
+use Cwd;
+use File::Basename;
+
+my $tmp = 't/tmp';
+my $statedir = 't/tinypodcast/.ikiwiki';
+
+sub podcast {
+ my $podcast_style = shift;
+
+ my $baseurl = 'http://example.com';
+ my @command = (qw(./ikiwiki.out -plugin inline -rss -atom));
+ push @command, qw(-underlaydir=underlays/basewiki);
+ push @command, qw(-set underlaydirbase=underlays -templatedir=templates);
+ push @command, "-url=$baseurl", qw(t/tinypodcast), "$tmp/out";
+
+ ok(! system("mkdir $tmp"),
+ q{setup});
+ ok(! system(@command),
+ q{build});
+
+ my %media_types = (
+ 'simplepost' => undef,
+ 'piano.mp3' => 'audio/mpeg',
+ 'scroll.3gp' => 'video/3gpp',
+ 'walter.ogg' => 'video/x-theora+ogg',
+ );
+
+ for my $format (qw(atom rss)) {
+ my $feed = XML::Feed->parse("$tmp/out/$podcast_style/index.$format");
+
+ is($feed->title, $podcast_style,
+ qq{$format feed title});
+ is($feed->link, "$baseurl/$podcast_style/",
+ qq{$format feed link});
+ is($feed->description, 'wiki',
+ qq{$format feed description});
+ if ('atom' eq $format) {
+ is($feed->author, $feed->description,
+ qq{$format feed author});
+ is($feed->id, $feed->link,
+ qq{$format feed id});
+ is($feed->generator, "ikiwiki",
+ qq{$format feed generator});
+ }
+
+ for my $entry ($feed->entries) {
+ my $title = $entry->title;
+ my $url = $entry->id;
+ my $body = $entry->content->body;
+ my $enclosure = $entry->enclosure;
+
+ is($entry->link, $url, qq{$format $title link});
+ isnt($entry->issued, undef,
+ qq{$format $title issued date});
+ isnt($entry->modified, undef,
+ qq{$format $title modified date});
+
+ if (defined $media_types{$title}) {
+ is($url, "$baseurl/$title",
+ qq{$format $title id});
+ is($body, undef,
+ qq{$format $title no body text});
+ is($enclosure->url, $url,
+ qq{$format $title enclosure url});
+ is($enclosure->type, $media_types{$title},
+ qq{$format $title enclosure type});
+ cmp_ok($enclosure->length, '>', 0,
+ qq{$format $title enclosure length});
+ }
+ else {
+ # XXX hack hack hack
+ my $expected_id = "$baseurl/$title/";
+ $expected_id =~ s/\ /_/g;
+
+ is($url, $expected_id,
+ qq{$format $title id});
+ isnt($body, undef,
+ qq{$format $title body text});
+
+ if ('fancy' eq $podcast_style) {
+ isnt($enclosure, undef,
+ qq{$format $title enclosure});
+ my $filename = basename($enclosure->url);
+ is($enclosure->type, $media_types{$filename},
+ qq{$format $title enclosure type});
+ cmp_ok($enclosure->length, '>', 0,
+ qq{$format $title enclosure length});
+ }
+ else {
+ is($enclosure, undef,
+ qq{$format $title no enclosure});
+ }
+ }
+ }
+ }
+
+ ok(! system("rm -rf $tmp $statedir"), q{teardown});
+}
+
+sub single_page_html {
+ my @command = (qw(./ikiwiki.out));
+ push @command, qw(-underlaydir=underlays/basewiki);
+ push @command, qw(-set underlaydirbase=underlays -templatedir=templates);
+ push @command, qw(t/tinypodcast), "$tmp/out";
+
+ ok(! system("mkdir $tmp"),
+ q{setup});
+ ok(! system(@command),
+ q{build});
+
+ my $html = "$tmp/out/pianopost/index.html";
+ like(_extract_html_content($html, 'content'), qr/has content and/m,
+ q{html body text});
+ like(_extract_html_content($html, 'enclosure'), qr/Download/m,
+ q{html enclosure});
+ my ($href) = _extract_html_links($html, 'piano');
+ is($href, '/piano.mp3',
+ q{html enclosure sans -url is site-absolute});
+
+ $html = "$tmp/out/attempted_multiple_enclosures/index.html";
+ like(_extract_html_content($html, 'content'), qr/has content and/m,
+ q{html body text});
+ like(_extract_html_content($html, 'enclosure'), qr/Download/m,
+ q{html enclosure});
+ ($href) = _extract_html_links($html, 'walter');
+ is($href, '/walter.ogg',
+ q{html enclosure sans -url is site-absolute});
+
+ my $baseurl = 'http://example.com';
+ ok(! system(@command, "-url=$baseurl", q{--rebuild}));
+
+ $html = "$tmp/out/pianopost/index.html";
+ ($href) = _extract_html_links($html, 'piano');
+ is($href, "$baseurl/piano.mp3",
+ q{html enclosure with -url is fully absolute});
+
+ $html = "$tmp/out/attempted_multiple_enclosures/index.html";
+ ($href) = _extract_html_links($html, 'walter');
+ is($href, "$baseurl/walter.ogg",
+ q{html enclosure with -url is fully absolute});
+
+ ok(! system("rm -rf $tmp $statedir"), q{teardown});
+}
+
+sub inlined_pages_html {
+ my @command = (qw(./ikiwiki.out -plugin inline));
+ push @command, qw(-underlaydir=underlays/basewiki);
+ push @command, qw(-set underlaydirbase=underlays -templatedir=templates);
+ push @command, qw(t/tinypodcast), "$tmp/out";
+
+ ok(! system("mkdir $tmp"),
+ q{setup});
+ ok(! system(@command),
+ q{build});
+
+ my $html = "$tmp/out/fancy/index.html";
+ my $contents = _extract_html_content($html, 'content');
+ like($contents, qr/has content and an/m,
+ q{html body text from pianopost});
+ like($contents, qr/has content and only one/m,
+ q{html body text from attempted_multiple_enclosures});
+ my $enclosures = _extract_html_content($html, 'inlineenclosure');
+ like($enclosures, qr/Download/m,
+ q{html enclosure});
+ my ($href) = _extract_html_links($html, 'piano.mp3');
+ is($href, '/piano.mp3',
+ q{html enclosure from pianopost sans -url});
+ ($href) = _extract_html_links($html, 'walter.ogg');
+ is($href, '/walter.ogg',
+ q{html enclosure from attempted_multiple_enclosures sans -url});
+
+ ok(! system("rm -rf $tmp $statedir"), q{teardown});
+}
+
+sub _extract_html_content {
+ my ($file, $desired_id, $desired_tag) = @_;
+ $desired_tag = 'div' unless defined $desired_tag;
+
+ my $p = HTML::Parser->new(api_version => 3);
+ my $content = '';
+
+ $p->handler(start => sub {
+ my ($tag, $self, $attr) = @_;
+ return if $tag ne $desired_tag;
+ return unless exists $attr->{id} && $attr->{id} eq $desired_id;
+
+ $self->handler(text => sub {
+ my ($dtext) = @_;
+ $content .= $dtext;
+ }, "dtext");
+ }, "tagname,self,attr");
+
+ $p->parse_file($file) || die $!;
+
+ return $content;
+}
+
+sub _extract_html_links {
+ my ($file, $desired_value) = @_;
+
+ my @hrefs = ();
+
+ my $p = HTML::LinkExtor->new(sub {
+ my ($tag, %attr) = @_;
+ return if $tag ne 'a';
+ return unless $attr{href} =~ qr/$desired_value/;
+ push(@hrefs, values %attr);
+ }, getcwd() . '/' . $file);
+
+ $p->parse_file($file);
+
+ return @hrefs;
+}
+
+podcast('simple');
+single_page_html();
+inlined_pages_html();
+podcast('fancy');
--- /dev/null
+[[!meta enclosure="piano.mp3" enclosure="scroll.3gp"]]
+[[!meta enclosure="walter.ogg"]]
+
+this article has content _and_ only one enclosure!
--- /dev/null
+[[!inline pages="pianopost or attempted_multiple_enclosures"]]
--- /dev/null
+[[!meta enclosure="piano.mp3"]]
+
+this article has content _and_ an enclosure!
--- /dev/null
+[[!inline pages="simplepost or *.3gp or *.mov or *.mp3 or *.ogg"]]
--- /dev/null
+this article has content but no enclosure
<TMPL_IF COPYRIGHT>
[[!meta copyright="<TMPL_VAR COPYRIGHT ESCAPE=HTML>"]]
</TMPL_IF>
+<TMPL_IF AUTHOR>
+[[!meta author="<TMPL_VAR NAME ESCAPE=HTML>: <TMPL_VAR AUTHOR ESCAPE=HTML>"]]
+<TMPL_ELSE>
[[!meta author="<TMPL_VAR NAME ESCAPE=HTML>"]]
+</TMPL_IF>
[[!meta authorurl="<TMPL_VAR URL ESCAPE=HTML>"]]
<published><TMPL_VAR CDATE_3339></published>
<TMPL_IF ENCLOSURE>
<link rel="enclosure" type="<TMPL_VAR TYPE>" href="<TMPL_VAR ENCLOSURE>" length="<TMPL_VAR LENGTH>" />
-<TMPL_ELSE>
+</TMPL_IF>
+<TMPL_UNLESS SIMPLEPODCAST>
<content type="html" xml:lang="en">
<TMPL_VAR CONTENT ESCAPE=HTML>
</content>
-</TMPL_IF>
+</TMPL_UNLESS>
<TMPL_IF COMMENTSURL>
<link rel="comments" href="<TMPL_VAR COMMENTSURL>" type="text/html" />
</TMPL_IF>
<TMPL_VAR CONTENT>
<TMPL_IF HTML5></section><TMPL_ELSE></div></TMPL_IF>
+<TMPL_IF ENCLOSURE>
+<TMPL_IF HTML5><section id="inlineenclosure"><TMPL_ELSE><div id="inlineenclosure"></TMPL_IF>
+<a href="<TMPL_VAR ENCLOSURE>">Download</a>
+<TMPL_IF HTML5></section><TMPL_ELSE></div></TMPL_IF>
+</TMPL_IF>
+
<TMPL_IF HTML5><footer class="inlinefooter"><TMPL_ELSE><div class="inlinefooter"></TMPL_IF>
<span class="pagedate">
<TMPL_VAR CONTENT>
<TMPL_IF HTML5></section><TMPL_ELSE></div></TMPL_IF>
+<TMPL_IF ENCLOSURE>
+<TMPL_IF HTML5><section id="enclosure"><TMPL_ELSE><div id="enclosure"></TMPL_IF>
+<a href="<TMPL_VAR ENCLOSURE>">Download</a>
+<TMPL_IF HTML5></section><TMPL_ELSE></div></TMPL_IF>
+</TMPL_IF>
+
<TMPL_UNLESS DYNAMIC>
<TMPL_IF COMMENTS>
<TMPL_IF HTML5><section id="comments"><TMPL_ELSE><div id="comments"></TMPL_IF>
<item>
-<TMPL_IF AUTHOR>
- <title><TMPL_VAR AUTHOR ESCAPE=HTML>: <TMPL_VAR TITLE></title>
- <dcterms:creator><TMPL_VAR AUTHOR ESCAPE=HTML></dcterms:creator>
-<TMPL_ELSE>
<title><TMPL_VAR TITLE></title>
-</TMPL_IF>
<TMPL_IF GUID>
<guid isPermaLink="false"><TMPL_VAR GUID></guid>
<TMPL_ELSE>
<guid isPermaLink="false"><TMPL_VAR URL></guid>
</TMPL_IF>
<link><TMPL_VAR PERMALINK></link>
+<TMPL_IF AUTHOR>
+ <dc:creator><TMPL_VAR AUTHOR ESCAPE=HTML></dc:creator>
+</TMPL_IF>
<TMPL_IF CATEGORIES>
<TMPL_LOOP CATEGORIES>
<category><TMPL_VAR CATEGORY></category>
<dcterms:modified><TMPL_VAR MDATE_3339></dcterms:modified>
<TMPL_IF ENCLOSURE>
<enclosure url="<TMPL_VAR ENCLOSURE>" type="<TMPL_VAR TYPE>" length="<TMPL_VAR LENGTH>" />
-<TMPL_ELSE>
- <description><TMPL_VAR CONTENT ESCAPE=HTML></description>
</TMPL_IF>
+<TMPL_UNLESS SIMPLEPODCAST>
+ <description><TMPL_VAR CONTENT ESCAPE=HTML></description>
+</TMPL_UNLESS>
<TMPL_IF COMMENTSURL>
<comments><TMPL_VAR COMMENTSURL></comments>
</TMPL_IF>
<channel>
<title><TMPL_VAR TITLE></title>
<link><TMPL_VAR PAGEURL></link>
+<TMPL_IF COPYRIGHT>
+<copyright><TMPL_VAR COPYRIGHT ESCAPE=HTML></copyright>
+</TMPL_IF>
<description><TMPL_VAR FEEDDESC ESCAPE=HTML></description>
+<generator>ikiwiki</generator>
+<pubDate><TMPL_VAR FEEDDATE_822></pubDate>
<TMPL_VAR CONTENT>
</channel>
</rss>
padding: 2px;
}
-#content, #comments, #footer {
+#content, #enclosure, #comments, #footer {
margin: 1em 2em;
}
* Copyright (C) 2010 Bernd Zeimetz
* Licensed under same license as ikiwiki: GPL v2 or later */
-.page, .pageheader, .sidebar, #content, #comments, .inlinepage, .recentchanges, .pageheader .actions ul, #pagebody {
+.page, .pageheader, .sidebar, #content, #enclosure, #comments, .inlinepage, .recentchanges, .pageheader .actions ul, #pagebody {
border: none;
}
clear: none;
}
-#content a, #comments a, .sidebar a {
+#content a, #enclosure a, #comments a, .sidebar a {
color: #315485;
text-decoration: none;
font-weight: bold;
.pageheader .header span a, .pageheader .actions ul li a, .pageheader .header .parentlinks a {
color #315485;
}
- #content, #comments, #pagebody {
+ #content, #enclosure, #comments, #pagebody {
margin-right: 0;
*margin-right: 0;
border-right: none;
background-color: #f2d98d;
}
-#content a:hover, #comments a:hover, .sidebar a:hover,
-#content a:visited:hover, #comments a:visited:hover, .sidebar a:visited:hover {
+#content a:hover, #enclosure a:hover, #comments a:hover, .sidebar a:hover,
+#content a:visited:hover, #enclosure a:visited:hover, #comments a:visited:hover,
+.sidebar a:visited:hover {
color: red;
}
-#content a:visited, #comments a:visited, .sidebar a:visited {
+#content a:visited, #enclosure a:visited, #comments a:visited,
+.sidebar a:visited {
color: #37485e;
}
* thanks to <http://www.kryogenix.org/days/2002/08/30/external>
*/
#content a[href^="http:"]:after,
-#content a[href^="https:"]:after {
+#content a[href^="https:"]:after,
+#enclosure a[href^="http:"]:after,
+#enclosure a[href^="https:"]:after {
content: "↗";
}
/* you will want to replicate this for your own domain in local.css */
#content a[href^="http://localhost"]:after,
-#content a[href^="http://ikiwiki.info"]:after {
+#content a[href^="http://ikiwiki.info"]:after,
+#enclosure a[href^="http://localhost"]:after,
+#enclosure a[href^="http://ikiwiki.info"]:after {
content: none;
}