3 # by Tuomo Valkonen <tuomov at iki dot fi>
5 package IkiWiki::Plugin::sidebar;
12 hook(type => "getsetup", id => "sidebar", call => \&getsetup);
13 hook(type => "pagetemplate", id => "sidebar", call => \&pagetemplate);
16 sub getsetup () { #{{{
24 sub sidebar_content ($) { #{{{
27 my $sidebar_page=bestlink($page, "sidebar") || return;
28 my $sidebar_file=$pagesources{$sidebar_page} || return;
29 my $sidebar_type=pagetype($sidebar_file);
31 if (defined $sidebar_type) {
32 # FIXME: This isn't quite right; it won't take into account
33 # adding a new sidebar page. So adding such a page
34 # currently requires a wiki rebuild.
35 add_depends($page, $sidebar_page);
37 my $content=readfile(srcfile($sidebar_file));
38 return unless length $content;
39 return IkiWiki::htmlize($sidebar_page, $page, $sidebar_type,
40 IkiWiki::linkify($sidebar_page, $page,
41 IkiWiki::preprocess($sidebar_page, $page,
42 IkiWiki::filter($sidebar_page, $page, $content))));
47 sub pagetemplate (@) { #{{{
50 my $page=$params{page};
51 my $template=$params{template};
53 if ($template->query(name => "sidebar")) {
54 my $content=sidebar_content($page);
55 if (defined $content && length $content) {
56 $template->param(sidebar => $content);