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 # FIXME: This isn't quite right; it won't take into account
25 # adding a new sidebar page. So adding such a page
26 # currently requires a wiki rebuild.
27 IkiWiki::add_depends($page, $sidebar_page);
29 my $content=IkiWiki::readfile(IkiWiki::srcfile($sidebar_file));
30 return unless length $content;
31 return IkiWiki::htmlize($page, $sidebar_type,
32 IkiWiki::linkify($sidebar_page, $page,
33 IkiWiki::preprocess($sidebar_page, $page,
34 IkiWiki::filter($sidebar_page, $content))));
39 sub pagetemplate (@) { #{{{
42 my $page=$params{page};
43 my $template=$params{template};
45 if ($template->query(name => "sidebar")) {
46 my $content=sidebar_content($page);
47 if (defined $content && length $content) {
48 $template->param(sidebar => $content);