From 546da9bac7135d7d1b02dce0c0eef2209d939fc6 Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Mon, 18 Feb 2013 16:24:22 -0500 Subject: Make [[!meta enclosure=foo.mp3]] "work" for HTML. --- IkiWiki/Plugin/meta.pm | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'IkiWiki/Plugin/meta.pm') diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index 421f1dc86..cb0768b91 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -121,6 +121,9 @@ sub preprocess (@) { add_link($page, $value); return ""; } + elsif ($key eq 'enclosure') { + $pagestate{$page}{meta}{enclosure}=$value; + } elsif ($key eq 'author') { $pagestate{$page}{meta}{author}=$value; if (exists $params{sortas}) { @@ -318,6 +321,11 @@ sub pagetemplate (@) { $template->param(title_overridden => 1); } + if (exists $pagestate{$page}{meta}{enclosure}) { + # XXX what if the enclosure doesn't exist? + $template->param(enclosure => $pagestate{$page}{meta}{enclosure}); + } + foreach my $field (qw{authorurl}) { eval q{use HTML::Entities}; $template->param($field => HTML::Entities::encode_entities($pagestate{$page}{meta}{$field})) -- cgit v1.2.3 From 0e278c4a848e0b3ddc0162db9dc135e791bd9477 Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Mon, 18 Feb 2013 18:01:13 -0500 Subject: Make enclosure follow WikiLink LinkingRules. --- IkiWiki/Plugin/meta.pm | 8 +++++++- t/podcast.t | 40 +++++++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 10 deletions(-) (limited to 'IkiWiki/Plugin/meta.pm') diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index cb0768b91..c77837e3c 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -122,6 +122,13 @@ sub preprocess (@) { 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); $pagestate{$page}{meta}{enclosure}=$value; } elsif ($key eq 'author') { @@ -322,7 +329,6 @@ sub pagetemplate (@) { } if (exists $pagestate{$page}{meta}{enclosure}) { - # XXX what if the enclosure doesn't exist? $template->param(enclosure => $pagestate{$page}{meta}{enclosure}); } diff --git a/t/podcast.t b/t/podcast.t index 77f146871..993814742 100755 --- a/t/podcast.t +++ b/t/podcast.t @@ -3,16 +3,18 @@ use warnings; use strict; BEGIN { - eval q{use XML::Feed; use HTML::Parser}; + 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 => 77}; + eval q{use Test::More tests => 78}; } } +use Cwd; + my $tmp = 't/tmp'; my $statedir = 't/tinypodcast/.ikiwiki'; @@ -23,8 +25,8 @@ sub simple_podcast { push @command, qw(-set underlaydirbase=underlays -templatedir=templates); push @command, "-url=$baseurl", qw(t/tinypodcast), "$tmp/out"; - ok(! system("mkdir $tmp")); - ok(! system(@command)); + ok(! system("mkdir $tmp"), q{setup}); + ok(! system(@command), q{build}); my %media_types = ( 'simplepost' => undef, @@ -86,7 +88,7 @@ sub simple_podcast { } } - ok(! system("rm -rf $tmp $statedir")); + ok(! system("rm -rf $tmp $statedir"), q{teardown}); } sub single_page_html { @@ -95,8 +97,9 @@ sub single_page_html { push @command, qw(-set underlaydirbase=underlays -templatedir=templates); push @command, qw(t/tinypodcast), "$tmp/out"; - ok(! system("mkdir $tmp")); - ok(! system(@command)); + ok(! system("mkdir $tmp"), q{setup}); + ok(! system(@command), q{build}); + my $html = "$tmp/out/pianopost/index.html"; my $body = _extract_html_content($html, 'content'); @@ -105,10 +108,12 @@ sub single_page_html { my $enclosure = _extract_html_content($html, 'enclosure'); like($enclosure, qr/Download this episode/m, q{html enclosure}); - # XXX die if specified enclosure doesn't exist + my ($href) = _extract_html_links($html, 'piano'); + ok(-f $href, q{html enclosure exists}); + # XXX die if more than one enclosure is specified - ok(! system("rm -rf $tmp $statedir")); + ok(! system("rm -rf $tmp $statedir"), q{teardown}); } sub _extract_html_content { @@ -139,5 +144,22 @@ sub _extract_html_content { 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; +} + simple_podcast(); single_page_html(); -- cgit v1.2.3 From c3b17740aed9e7f2697999163e1a1c4f84b6ef8f Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Mon, 18 Feb 2013 18:19:45 -0500 Subject: Document that last enclosure wins. --- IkiWiki/Plugin/meta.pm | 1 + t/podcast.t | 39 +++++++++++++++--------- t/tinypodcast/attempted_multiple_enclosures.mdwn | 4 +++ 3 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 t/tinypodcast/attempted_multiple_enclosures.mdwn (limited to 'IkiWiki/Plugin/meta.pm') diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index c77837e3c..70233decf 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -130,6 +130,7 @@ sub preprocess (@) { $value=urlto($link, $page); $pagestate{$page}{meta}{enclosure}=$value; + # fallthrough } elsif ($key eq 'author') { $pagestate{$page}{meta}{author}=$value; diff --git a/t/podcast.t b/t/podcast.t index 993814742..3125a7e55 100755 --- a/t/podcast.t +++ b/t/podcast.t @@ -9,7 +9,7 @@ BEGIN { "XML::Feed and/or HTML::Parser not available"}; } else { - eval q{use Test::More tests => 78}; + eval q{use Test::More tests => 81}; } } @@ -25,8 +25,10 @@ sub simple_podcast { 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}); + ok(! system("mkdir $tmp"), + q{setup}); + ok(! system(@command), + q{build}); my %media_types = ( 'simplepost' => undef, @@ -97,21 +99,28 @@ sub single_page_html { 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}); + ok(! system("mkdir $tmp"), + q{setup}); + ok(! system(@command), + q{build}); my $html = "$tmp/out/pianopost/index.html"; - - my $body = _extract_html_content($html, 'content'); - like($body, qr/article has content and/m, q{html body text}); - - my $enclosure = _extract_html_content($html, 'enclosure'); - like($enclosure, qr/Download this episode/m, q{html enclosure}); - + like(_extract_html_content($html, 'content'), qr/has content and/m, + q{html body text}); + like(_extract_html_content($html, 'enclosure'), qr/this episode/m, + q{html enclosure}); my ($href) = _extract_html_links($html, 'piano'); - ok(-f $href, q{html enclosure exists}); - - # XXX die if more than one enclosure is specified + ok(-f $href, + q{html enclosure exists}); + + $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/this episode/m, + q{html enclosure}); + ($href) = _extract_html_links($html, 'walter'); + ok(-f $href, + q{html enclosure exists}); ok(! system("rm -rf $tmp $statedir"), q{teardown}); } diff --git a/t/tinypodcast/attempted_multiple_enclosures.mdwn b/t/tinypodcast/attempted_multiple_enclosures.mdwn new file mode 100644 index 000000000..ea7bae8d0 --- /dev/null +++ b/t/tinypodcast/attempted_multiple_enclosures.mdwn @@ -0,0 +1,4 @@ +[[!meta enclosure="piano.mp3" enclosure="scroll.3gp"]] +[[!meta enclosure="walter.ogg"]] + +this article has content _and_ only one enclosure! -- cgit v1.2.3 From 3d2be49420b0f29f169ec015f11af1f0624b9ec9 Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Wed, 20 Feb 2013 19:14:20 -0500 Subject: Make enclosures absolute (in feeds they have to be). --- IkiWiki/Plugin/meta.pm | 4 ++-- t/podcast.t | 31 ++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 11 deletions(-) (limited to 'IkiWiki/Plugin/meta.pm') diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index 70233decf..f5b9bb521 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -128,7 +128,7 @@ sub preprocess (@) { } add_depends($page, $link, deptype("presence")); - $value=urlto($link, $page); + $value=urlto($link, $page, 1); $pagestate{$page}{meta}{enclosure}=$value; # fallthrough } @@ -330,7 +330,7 @@ sub pagetemplate (@) { } if (exists $pagestate{$page}{meta}{enclosure}) { - $template->param(enclosure => $pagestate{$page}{meta}{enclosure}); + $template->param(enclosure => HTML::Entities::encode_entities(IkiWiki::urlabs($pagestate{$page}{meta}{enclosure}, $config{url}))); } foreach my $field (qw{authorurl}) { diff --git a/t/podcast.t b/t/podcast.t index 235c2e768..88d2ca074 100755 --- a/t/podcast.t +++ b/t/podcast.t @@ -9,7 +9,7 @@ BEGIN { "XML::Feed and/or HTML::Parser not available"}; } else { - eval q{use Test::More tests => 89}; + eval q{use Test::More tests => 92}; } } @@ -110,8 +110,8 @@ sub single_page_html { like(_extract_html_content($html, 'enclosure'), qr/this episode/m, q{html enclosure}); my ($href) = _extract_html_links($html, 'piano'); - ok(-f $href, - q{html enclosure exists}); + 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, @@ -119,8 +119,21 @@ sub single_page_html { like(_extract_html_content($html, 'enclosure'), qr/this episode/m, q{html enclosure}); ($href) = _extract_html_links($html, 'walter'); - ok(-f $href, - q{html enclosure exists}); + 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}); } @@ -146,11 +159,11 @@ sub inlined_pages_html { like($enclosures, qr/this episode/m, q{html enclosure}); my ($href) = _extract_html_links($html, 'piano.mp3'); - ok(-f $href, - q{html enclosure from pianopost exists}); + is($href, '/piano.mp3', + q{html enclosure from pianopost sans -url}); ($href) = _extract_html_links($html, 'walter.ogg'); - ok(-f $href, - q{html enclosure from attempted_multiple_enclosures exists}); + is($href, '/walter.ogg', + q{html enclosure from attempted_multiple_enclosures sans -url}); ok(! system("rm -rf $tmp $statedir"), q{teardown}); } -- cgit v1.2.3 From b25f7700bde4981d1fb69d89c1451abc0c7bb87a Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Thu, 27 Jun 2013 00:21:20 -0400 Subject: Instead of hacking back to $link, just provide it. --- IkiWiki/Plugin/inline.pm | 6 +----- IkiWiki/Plugin/meta.pm | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'IkiWiki/Plugin/meta.pm') diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index e313eb775..455ac3ad5 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -672,11 +672,7 @@ sub genfeed ($$$$$@) { if (exists $pagestate{$p}{meta}{enclosure}) { my $absurl = $pagestate{$p}{meta}{enclosure}; - - # XXX better way to compute relative to srcdir? - my $file = $absurl; - $file =~ s|^$config{url}/||; - + my $file = $pagestate{$p}{meta}{enclosurefile}; genenclosure($itemtemplate, $absurl, $file); $fancy_enclosure_seen = 1; } diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index 794f6d861..e7b96bdf1 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -130,6 +130,7 @@ sub preprocess (@) { $value=urlto($link, $page, 1); $pagestate{$page}{meta}{enclosure}=$value; + $pagestate{$page}{meta}{enclosurefile}=$link; # fallthrough } elsif ($key eq 'author') { -- cgit v1.2.3