3 # by Tuomo Valkonen <tuomov at iki dot fi>
5 package IkiWiki::Plugin::sidebar;
12 IkiWiki::hook(type => "pagetemplate", id => "sidebar",
13 call => \&pagetemplate);
16 sub sidebar_content ($) { #{{{
19 my $sidebar_page=IkiWiki::bestlink($page, "sidebar") || return;
20 my $sidebar_file=$IkiWiki::pagesources{$sidebar_page} || return;
21 my $sidebar_type=IkiWiki::pagetype($sidebar_file);
23 if (defined $sidebar_type) {
24 IkiWiki::add_depends($page, $sidebar_page);
25 my $content=IkiWiki::readfile(IkiWiki::srcfile($sidebar_file));
26 return unless length $content;
27 return IkiWiki::htmlize($sidebar_type,
28 IkiWiki::preprocess($sidebar_page, $page,
29 IkiWiki::linkify($sidebar_page, $page, $content)));
34 sub pagetemplate (@) { #{{{
37 my $page=$params{page};
38 my $template=$params{template};
40 if ($template->query(name => "sidebar")) {
41 my $content=sidebar_content($page);
42 if (defined $content && length $content) {
43 $template->param(sidebar => $content);