3 # by Tuomo Valkonen <tuomov at iki dot fi>
5 package IkiWiki::Plugin::sidebar;
12 hook(type => "pagetemplate", id => "sidebar", call => \&pagetemplate);
15 sub sidebar_content ($) { #{{{
18 my $sidebar_page=bestlink($page, "sidebar") || return;
19 my $sidebar_file=$pagesources{$sidebar_page} || return;
20 my $sidebar_type=pagetype($sidebar_file);
22 if (defined $sidebar_type) {
23 # FIXME: This isn't quite right; it won't take into account
24 # adding a new sidebar page. So adding such a page
25 # currently requires a wiki rebuild.
26 add_depends($page, $sidebar_page);
28 my $content=readfile(srcfile($sidebar_file));
29 return unless length $content;
30 return IkiWiki::htmlize($page, $sidebar_type,
31 IkiWiki::linkify($sidebar_page, $page,
32 IkiWiki::preprocess($sidebar_page, $page,
33 IkiWiki::filter($sidebar_page, $page, $content))));
38 sub pagetemplate (@) { #{{{
41 my $page=$params{page};
42 my $template=$params{template};
44 if ($template->query(name => "sidebar")) {
45 my $content=sidebar_content($page);
46 if (defined $content && length $content) {
47 $template->param(sidebar => $content);