]> scripts.mit.edu Git - www/ikiwiki.git/commitdiff
Merge commit 'origin/master' into prv/po
authorintrigeri <intrigeri@boum.org>
Mon, 20 Oct 2008 12:33:19 +0000 (14:33 +0200)
committerintrigeri <intrigeri@boum.org>
Mon, 20 Oct 2008 12:33:19 +0000 (14:33 +0200)
1  2 
IkiWiki.pm
doc/plugins/write.mdwn

diff --combined IkiWiki.pm
index 36e85d4135f146e321c5e07b4917444afcbc232e,207ca87fb4d96dbecacddc897015647559d91a62..67cd2147d2eb65b7d74356208b63205de231f9bb
@@@ -647,19 -647,8 +647,19 @@@ sub newpagefile ($$) { #{{
  sub targetpage ($$) { #{{{
        my $page=shift;
        my $ext=shift;
 -      
 -      if (! $config{usedirs} || $page eq 'index') {
 +
 +      my $targetpage='';
 +      run_hooks(targetpage => sub {
 +              $targetpage=shift->(
 +                      page => $page,
 +                      ext => $ext,
 +              );
 +      });
 +
 +      if (defined $targetpage && (length($targetpage) > 0)) {
 +              return $targetpage;
 +      }
 +      elsif (! $config{usedirs} || $page eq 'index') {
                return $page.".".$ext;
        }
        else {
@@@ -807,7 -796,6 +807,7 @@@ sub will_render ($$;$) { #{{
  sub bestlink ($$) { #{{{
        my $page=shift;
        my $link=shift;
 +      my $res=undef;
        
        my $cwd=$page;
        if ($link=~s/^\/+//) {
                $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 ($) { #{{{
@@@ -920,6 -898,23 +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) {
@@@ -938,10 -933,6 +955,10 @@@ sub beautify_urlpath ($) { #{{
                $url =~ s!/index.$config{htmlext}$!/!;
        }
  
 +      run_hooks(tweakurlpath => sub {
 +              $url=shift->(url => $url);
 +      });
 +
        # Ensure url is not an empty link, and
        # if it's relative, make that explicit to avoid colon confusion.
        if ($url !~ /^\//) {
diff --combined doc/plugins/write.mdwn
index 884c7eefb3ab979580f0ff8c89ce59ed932da7ed,856b34ba1e1a262794c54a5684d78acdf2cd00f1..857d176d5e172d6b263335f833a997e70024560f
@@@ -196,7 -196,6 +196,6 @@@ generating the page
  
        hook(type => "pagetemplate", id => "foo", call => \&pagetemplate);
  
  [[Templates|wikitemplates]] are filled out for many different things in
  ikiwiki, like generating a page, or part of a blog page, or an rss feed, or
  a cgi. This hook allows modifying the variables available on those
@@@ -361,6 -360,13 +360,13 @@@ This hook is called whenever ikiwiki no
  the state is saved. The function can save other state, modify values before
  they're saved, etc.
  
+ ### displaytime
+       hook(type => "displaytime", id => "foo", call => \&display);
+ This hook can be registered to override the regular `displaytime` function.
+ Only the last displaytime hook will be used.
  ### renamepage
  
        hook(type => "renamepage", id => "foo", call => \&renamepage);
@@@ -428,36 -434,6 +434,36 @@@ describes the plugin as a whole. For ex
    and undef if a rebuild could be needed in some circumstances, but is not
    strictly required.
  
 +### targetpage
 +
 +      hook(type => "targetpage", id => "foo", call => \&targetpage);
 +
 +This hook can be used to override the name of the file a page should
 +be compiled into. 
 +
 +It should return the target filename.
 +
 +### tweakurlpath
 +
 +      hook(type => "tweakurlpath", id => "foo", call => \&tweakurlpath);
 +
 +This hook can be used to modify the internal urls generated by
 +ikiwiki; it is run just after ikiwiki has removed the trailing
 +`index.html`, in case `usedirs` is enabled.
 +
 +It should return the modified url.
 +
 +### tweakbestlink
 +
 +      hook(type => "tweakbestlink", id => "foo", call => \&tweakbestlink);
 +
 +This hook can be used to modify the page returned by `bestlink`. It is
 +passed named parameters `page` and `link`. These are, respectively,
 +the page where the link will appear and the link ikiwiki would choose
 +as the best one, if no `tweakbestlink` hook was in effect.
 +
 +It should return the modified link.
 +
  ## Plugin interface
  
  To import the ikiwiki plugin interface: