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?",
39 my $page=$params{page};
40 return "" unless $page eq $params{destpage};
42 if (! defined $content) {
43 $pagesidebar{$page}=undef;
46 my $file = $pagesources{$page};
47 my $type = pagetype($file);
50 IkiWiki::htmlize($page, $page, $type,
51 IkiWiki::linkify($page, $page,
52 IkiWiki::preprocess($page, $page,
53 IkiWiki::filter($page, $page, $content))));
62 sub sidebar_content ($) {
65 return $pagesidebar{$page} if defined $pagesidebar{$page};
67 return if ! exists $pagesidebar{$page} &&
68 defined $config{global_sidebars} && ! $config{global_sidebars};
70 my $sidebar_page=bestlink($page, "sidebar") || return;
71 my $sidebar_file=$pagesources{$sidebar_page} || return;
72 my $sidebar_type=pagetype($sidebar_file);
74 if (defined $sidebar_type) {
75 # FIXME: This isn't quite right; it won't take into account
76 # adding a new sidebar page. So adding such a page
77 # currently requires a wiki rebuild.
78 add_depends($page, $sidebar_page);
81 if (defined $oldfile && $sidebar_file eq $oldfile) {
85 $content=readfile(srcfile($sidebar_file));
87 $oldfile=$sidebar_file;
90 return unless length $content;
91 return IkiWiki::htmlize($sidebar_page, $page, $sidebar_type,
92 IkiWiki::linkify($sidebar_page, $page,
93 IkiWiki::preprocess($sidebar_page, $page,
94 IkiWiki::filter($sidebar_page, $page, $content))));
99 sub pagetemplate (@) {
102 my $page=$params{page};
103 my $template=$params{template};
105 if ($template->query(name => "sidebar")) {
106 my $content=sidebar_content($page);
107 if (defined $content && length $content) {
108 $template->param(sidebar => $content);