From: intrigeri Date: Mon, 20 Oct 2008 12:33:19 +0000 (+0200) Subject: Merge commit 'origin/master' into prv/po X-Git-Tag: 3.15~409^2 X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/fadb26bc1507f7fc2caaa873ad32c12f75c378aa?ds=inline;hp=-c Merge commit 'origin/master' into prv/po --- fadb26bc1507f7fc2caaa873ad32c12f75c378aa diff --combined IkiWiki.pm index 36e85d413,207ca87fb..67cd2147d --- a/IkiWiki.pm +++ b/IkiWiki.pm @@@ -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/^\/+//) { @@@ -822,35 -810,25 +822,35 @@@ $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 884c7eefb,856b34ba1..857d176d5 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@@ -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: