aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IkiWiki/Plugin/sidebar.pm42
-rw-r--r--debian/changelog2
-rw-r--r--doc/ikiwiki/directive/sidebar.mdwn14
-rw-r--r--doc/plugins/sidebar.mdwn17
4 files changed, 66 insertions, 9 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,
diff --git a/debian/changelog b/debian/changelog
index 03361e6a0..267a2fd7a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -37,6 +37,8 @@ ikiwiki (3.20100415) UNRELEASED; urgency=low
in a tag cloud. This is useful to put in a sidebar.
* Rework example blog front page.
* CSS and templates for sidebar changed to use a class, not an id.
+ * sidebar: Now a sidebar directive can be used to override the sidebar
+ shown on a page.
-- Joey Hess <joeyh@debian.org> Sun, 04 Apr 2010 12:17:11 -0400
diff --git a/doc/ikiwiki/directive/sidebar.mdwn b/doc/ikiwiki/directive/sidebar.mdwn
new file mode 100644
index 000000000..46f016747
--- /dev/null
+++ b/doc/ikiwiki/directive/sidebar.mdwn
@@ -0,0 +1,14 @@
+The `sidebar` directive is supplied by the [[!iki plugins/sidebar desc=sidebar]] plugin.
+
+This directive specifies a custom sidebar to display on the page, instead
+of any sidebar that is displayed globally.
+
+## examples
+
+ \[[!sidebar """
+ This is my custom sidebar for this page.
+
+ \[[!calendar pages="posts/*"]]
+ """]]
+
+[[!meta robots="noindex, follow"]]
diff --git a/doc/plugins/sidebar.mdwn b/doc/plugins/sidebar.mdwn
index 4e356d65a..cd0f0ecf1 100644
--- a/doc/plugins/sidebar.mdwn
+++ b/doc/plugins/sidebar.mdwn
@@ -10,15 +10,16 @@ Typically this will be a page in the root of the wiki, but it can also be a
[[plugins/sidebar|plugins/sidebar]], will be treated as a sidebar for the
[[plugins]] page, and of all of its SubPages, if the plugin is enabled.
-Note that to disable a sidebar for a [[ikiwiki/SubPage]] of a page that has
-a sidebar, you can create a sidebar page that is completely empty. This
-will turn off the sidebar altogether.
+There is also a [[ikiwiki/directive/sidebar]] directive that can be used
+to provide a custom sidebar content for a page.
-Warning: Any change to the sidebar will cause a rebuild of the whole wiki,
-since every page includes a copy that has to be updated. This can
-especially be a problem if the sidebar includes an [[ikiwiki/directive/inline]]
-directive, since any changes to pages inlined into the sidebar
-will change the sidebar and cause a full wiki rebuild.
+----
+
+Warning: Any change to the sidebar page will cause a rebuild of the whole
+wiki, since every page includes a copy that has to be updated. This can
+especially be a problem if the sidebar includes an
+[[ikiwiki/directive/inline]] directive, since any changes to pages inlined
+into the sidebar will change the sidebar and cause a full wiki rebuild.
Instead, if you include a [[ikiwiki/directive/map]] directive on the sidebar,
and it does not use the `show` parameter, only adding or removing pages