summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorintrigeri <intrigeri@boum.org>2008-11-02 17:56:15 +0100
committerintrigeri <intrigeri@boum.org>2008-11-02 17:56:15 +0100
commit502a3433c410369eca4eb36b8fb8be5bc4a34a2d (patch)
tree3a6d6af1f58093c57ec23e7315695671b7c9555f
parent9643ce20d8988da38f192689468075fe44709703 (diff)
po plugin: replace tweakbestlink hook with a wrapper function
... thanks to the new inject() feature. Signed-off-by: intrigeri <intrigeri@boum.org>
-rw-r--r--IkiWiki/Plugin/po.pm28
1 files changed, 17 insertions, 11 deletions
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,