From a629b276b27bb900ec9e544820cd42aa140e8bdc Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Wed, 20 Feb 2013 20:53:50 -0500 Subject: [PATCH] Extract genenclosure(). No functional change intended. --- IkiWiki/Plugin/inline.pm | 45 ++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 8eb033951..20cb8a27c 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -611,6 +611,26 @@ sub absolute_urls ($$) { 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; @@ -650,28 +670,13 @@ sub genfeed ($$$$$@) { } } - 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, - ); - } + my $file=$pagesources{$p}; + my $type=pagetype($file); + if (defined $type) { + $itemtemplate->param(content => $pcontent); } else { - $itemtemplate->param(content => $pcontent); + genenclosure($itemtemplate, $u, $file); } run_hooks(pagetemplate => sub { -- 2.39.5