summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2010-04-15 16:40:01 -0400
committerJoey Hess <joey@gnu.kitenet.net>2010-04-15 16:51:27 -0400
commit358fa953e189d6f8a7925be8533fe7b7c5699503 (patch)
tree01d777ac3ab15c972a0cf005affb8e2895c3a374 /IkiWiki/Plugin
parent843ce484fc9a65a814be62ab9617fc461640fbeb (diff)
sidebar: Now a sidebar directive can be used to override the sidebar shown on a page.
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r--IkiWiki/Plugin/sidebar.pm42
1 files changed, 41 insertions, 1 deletions
diff --git a/IkiWiki/Plugin/sidebar.pm b/IkiWiki/Plugin/sidebar.pm
index 41812e1c1..d63cb5246 100644
--- a/IkiWiki/Plugin/sidebar.pm
+++ b/IkiWiki/Plugin/sidebar.pm
@@ -10,6 +10,7 @@ use IkiWiki 3.00;
sub import {
hook(type => "getsetup", id => "sidebar", call => \&getsetup);
+ hook(type => "preprocess", id => "sidebar", call => \&preprocess);
hook(type => "pagetemplate", id => "sidebar", call => \&pagetemplate);
}
@@ -21,9 +22,39 @@ sub getsetup () {
},
}
+my %pagesidebar;
+
+sub preprocess (@) {
+ my %params=@_;
+ my $content=shift;
+ shift;
+
+ if (! defined $content) {
+ error(gettext("sidebar content not specified"));
+ }
+
+ my $page=$params{page};
+ return "" unless $page eq $params{destpage};
+ my $file = $pagesources{$page};
+ my $type = pagetype($file);
+
+ $pagesidebar{$page}=
+ IkiWiki::htmlize($page, $page, $type,
+ IkiWiki::linkify($page, $page,
+ IkiWiki::preprocess($page, $page,
+ IkiWiki::filter($page, $page, $content))));
+
+ return "";
+}
+
+my $oldfile;
+my $oldcontent;
+
sub sidebar_content ($) {
my $page=shift;
+ return $pagesidebar{$page} if exists $pagesidebar{$page};
+
my $sidebar_page=bestlink($page, "sidebar") || return;
my $sidebar_file=$pagesources{$sidebar_page} || return;
my $sidebar_type=pagetype($sidebar_file);
@@ -34,7 +65,16 @@ sub sidebar_content ($) {
# currently requires a wiki rebuild.
add_depends($page, $sidebar_page);
- my $content=readfile(srcfile($sidebar_file));
+ my $content;
+ if (defined $oldfile && $sidebar_file eq $oldfile) {
+ $content=$oldcontent;
+ }
+ else {
+ $content=readfile(srcfile($sidebar_file));
+ $oldcontent=$content;
+ $oldfile=$sidebar_file;
+ }
+
return unless length $content;
return IkiWiki::htmlize($sidebar_page, $page, $sidebar_type,
IkiWiki::linkify($sidebar_page, $page,