]> sipb.mit.edu Git - ikiwiki.git/commitdiff
po plugin: replace tweakbestlink hook with a wrapper function
authorintrigeri <intrigeri@boum.org>
Sun, 2 Nov 2008 16:56:15 +0000 (17:56 +0100)
committerintrigeri <intrigeri@boum.org>
Sun, 2 Nov 2008 16:56:15 +0000 (17:56 +0100)
... thanks to the new inject() feature.

Signed-off-by: intrigeri <intrigeri@boum.org>
IkiWiki/Plugin/po.pm

index a1f7476a303e2a9637814e6373d8eff123001f8a..fa250f3a4991c4b56798a9f775130324f9b68088 100644 (file)
@@ -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,