From 502a3433c410369eca4eb36b8fb8be5bc4a34a2d Mon Sep 17 00:00:00 2001 From: intrigeri Date: Sun, 2 Nov 2008 17:56:15 +0100 Subject: po plugin: replace tweakbestlink hook with a wrapper function ... thanks to the new inject() feature. Signed-off-by: intrigeri --- IkiWiki/Plugin/po.pm | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index a1f7476a3..fa250f3a4 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -18,6 +18,7 @@ use Memoize; my %translations; our %filtered; +my $origbestlink=\&bestlink; ## FIXME: makes some test cases cry once every two tries; this may be ## related to the artificial way the testsuite is run, or not. # memoize("istranslatable"); @@ -30,10 +31,10 @@ sub import { hook(type => "needsbuild", id => "po", call => \&needsbuild); hook(type => "targetpage", id => "po", call => \&targetpage); hook(type => "tweakurlpath", id => "po", call => \&tweakurlpath); - hook(type => "tweakbestlink", id => "po", call => \&tweakbestlink); hook(type => "filter", id => "po", call => \&filter); hook(type => "htmlize", id => "po", call => \&htmlize); hook(type => "pagetemplate", id => "po", call => \&pagetemplate); + inject(name => "IkiWiki::bestlink", call => \&mybestlink); } sub getsetup () { #{{{ @@ -246,17 +247,22 @@ sub tweakurlpath ($) { #{{{ return $url; } #}}} -sub tweakbestlink ($$) { #{{{ - my %params = @_; - my $page=$params{page}; - my $link=$params{link}; - if ($config{po_link_to} eq "current" - && istranslatable($link) - && istranslation($page)) { - my ($masterpage, $curlang) = ($page =~ /(.*)[.]([a-z]{2})$/); - return $link . "." . $curlang; +sub mybestlink ($$) { #{{{ + my $page=shift; + my $link=shift; + my $res=$origbestlink->($page, $link); + if (length $res) { + if ($config{po_link_to} eq "current" + && istranslatable($res) + && istranslation($page)) { + my ($masterpage, $curlang) = ($page =~ /(.*)[.]([a-z]{2})$/); + return $res . "." . $curlang; + } + else { + return $res; + } } - return $link; + return ""; } #}}} # We use filter to convert PO to the master page's type, -- cgit v1.2.3