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 => "preprocess", id => "sidebar", call => \&preprocess);
14 hook(type => "pagetemplate", id => "sidebar", call => \&pagetemplate);
26 description => "show sidebar page on all pages?",
37 my $page=$params{page};
38 return "" unless $page eq $params{destpage};
40 if (! defined $params{content}) {
41 $pagesidebar{$page}=undef;
44 my $file = $pagesources{$page};
45 my $type = pagetype($file);
48 IkiWiki::htmlize($page, $page, $type,
49 IkiWiki::linkify($page, $page,
50 IkiWiki::preprocess($page, $page,
51 IkiWiki::filter($page, $page, $params{content}))));
60 sub sidebar_content ($) {
63 return delete $pagesidebar{$page} if defined $pagesidebar{$page};
65 return if ! exists $pagesidebar{$page} &&
66 defined $config{global_sidebars} && ! $config{global_sidebars};
68 my $sidebar_page=bestlink($page, "sidebar") || return;
69 my $sidebar_file=$pagesources{$sidebar_page} || return;
70 my $sidebar_type=pagetype($sidebar_file);
72 if (defined $sidebar_type) {
73 # FIXME: This isn't quite right; it won't take into account
74 # adding a new sidebar page. So adding such a page
75 # currently requires a wiki rebuild.
76 add_depends($page, $sidebar_page);
79 if (defined $oldfile && $sidebar_file eq $oldfile) {
83 $content=readfile(srcfile($sidebar_file));
85 $oldfile=$sidebar_file;
88 return unless length $content;
89 return IkiWiki::htmlize($sidebar_page, $page, $sidebar_type,
90 IkiWiki::linkify($sidebar_page, $page,
91 IkiWiki::preprocess($sidebar_page, $page,
92 IkiWiki::filter($sidebar_page, $page, $content, 'fullpage'))));
97 sub pagetemplate (@) {
100 my $template=$params{template};
101 if ($params{destpage} eq $params{page} &&
102 $template->query(name => "sidebar")) {
103 my $content=sidebar_content($params{destpage});
104 if (defined $content && length $content) {
105 $template->param(sidebar => $content);