]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki.pm
Merge commit 'origin/master' into prv/po
[git.ikiwiki.info.git] / IkiWiki.pm
index e75175a8dfb3cc6115a018b3bf63aa2674e82496..67cd2147d2eb65b7d74356208b63205de231f9bb 100644 (file)
@@ -807,6 +807,7 @@ sub will_render ($$;$) { #{{{
 sub bestlink ($$) { #{{{
        my $page=shift;
        my $link=shift;
+       my $res=undef;
        
        my $cwd=$page;
        if ($link=~s/^\/+//) {
@@ -821,25 +822,35 @@ sub bestlink ($$) { #{{{
                $l.=$link;
 
                if (exists $links{$l}) {
-                       return $l;
+                       $res=$l;
                }
                elsif (exists $pagecase{lc $l}) {
-                       return $pagecase{lc $l};
+                       $res=$pagecase{lc $l};
                }
-       } while $cwd=~s{/?[^/]+$}{};
+       } while ($cwd=~s{/?[^/]+$}{} && ! defined $res);
 
-       if (length $config{userdir}) {
+       if (! defined $res && length $config{userdir}) {
                my $l = "$config{userdir}/".lc($link);
                if (exists $links{$l}) {
-                       return $l;
+                       $res=$l;
                }
                elsif (exists $pagecase{lc $l}) {
-                       return $pagecase{lc $l};
+                       $res=$pagecase{lc $l};
                }
        }
 
-       #print STDERR "warning: page $page, broken link: $link\n";
-       return "";
+       if (defined $res) {
+               run_hooks(tweakbestlink => sub {
+                       $res=shift->(
+                               page => $page,
+                               link => $res);
+               });
+               return $res;
+       }
+       else {
+               #print STDERR "warning: page $page, broken link: $link\n";
+               return "";
+       }
 } #}}}
 
 sub isinlinableimage ($) { #{{{
@@ -909,6 +920,23 @@ sub abs2rel ($$) { #{{{
 } #}}}
 
 sub displaytime ($;$) { #{{{
+       my $time=shift;
+       my $format=shift;
+       if (exists $hooks{displaytime}) {
+               my $ret;
+               run_hooks(displaytime => sub {
+                       $ret=shift->($time, $format)
+               });
+               return $ret;
+       }
+       else {
+               return formattime($time, $format);
+       }
+} #}}}
+
+sub formattime ($;$) { #{{{
+       # Plugins can override this function to mark up the time for
+       # display.
        my $time=shift;
        my $format=shift;
        if (! defined $format) {
@@ -927,7 +955,7 @@ sub beautify_urlpath ($) { #{{{
                $url =~ s!/index.$config{htmlext}$!/!;
        }
 
-       run_hooks(urlpath => sub {
+       run_hooks(tweakurlpath => sub {
                $url=shift->(url => $url);
        });