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, $params{content
})));
59 sub sidebar_content
($) {
62 return delete $pagesidebar{$page} if defined $pagesidebar{$page};
64 return if ! exists $pagesidebar{$page} &&
65 defined $config{global_sidebars
} && ! $config{global_sidebars
};
67 my $sidebar_page=bestlink
($page, "sidebar") || return;
68 my $sidebar_file=$pagesources{$sidebar_page} || return;
69 my $sidebar_type=pagetype
($sidebar_file);
71 if (defined $sidebar_type) {
72 # FIXME: This isn't quite right; it won't take into account
73 # adding a new sidebar page. So adding such a page
74 # currently requires a wiki rebuild.
75 add_depends
($page, $sidebar_page);
78 if (defined $oldfile && $sidebar_file eq $oldfile) {
82 $content=readfile
(srcfile
($sidebar_file));
84 $oldfile=$sidebar_file;
87 return unless length $content;
88 return IkiWiki
::htmlize
($sidebar_page, $page, $sidebar_type,
89 IkiWiki
::linkify
($sidebar_page, $page,
90 IkiWiki
::preprocess
($sidebar_page, $page,
91 IkiWiki
::filter
($sidebar_page, $page, $content))));
96 sub pagetemplate
(@
) {
99 my $template=$params{template
};
100 if ($params{destpage
} eq $params{page
} &&
101 $template->query(name
=> "sidebar")) {
102 my $content=sidebar_content
($params{destpage
});
103 if (defined $content && length $content) {
104 $template->param(sidebar
=> $content);