summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/sidebar.pm
blob: f0dd0ca0352ce1077141079bd349906572f00bea (plain)
  1. #!/usr/bin/perl
  2. # Sidebar plugin.
  3. # by Tuomo Valkonen <tuomov at iki dot fi>
  4. package IkiWiki::Plugin::sidebar;
  5. use warnings;
  6. use strict;
  7. use IkiWiki 2.00;
  8. sub import { #{{{
  9. hook(type => "pagetemplate", id => "sidebar", call => \&pagetemplate);
  10. } # }}}
  11. sub sidebar_content ($) { #{{{
  12. my $page=shift;
  13. my $sidebar_page=bestlink($page, "sidebar") || return;
  14. my $sidebar_file=$pagesources{$sidebar_page} || return;
  15. my $sidebar_type=pagetype($sidebar_file);
  16. if (defined $sidebar_type) {
  17. # FIXME: This isn't quite right; it won't take into account
  18. # adding a new sidebar page. So adding such a page
  19. # currently requires a wiki rebuild.
  20. add_depends($page, $sidebar_page);
  21. my $content=readfile(srcfile($sidebar_file));
  22. return unless length $content;
  23. return IkiWiki::htmlize($page, $sidebar_type,
  24. IkiWiki::linkify($sidebar_page, $page,
  25. IkiWiki::preprocess($sidebar_page, $page,
  26. IkiWiki::filter($sidebar_page, $content))));
  27. }
  28. } # }}}
  29. sub pagetemplate (@) { #{{{
  30. my %params=@_;
  31. my $page=$params{page};
  32. my $template=$params{template};
  33. if ($template->query(name => "sidebar")) {
  34. my $content=sidebar_content($page);
  35. if (defined $content && length $content) {
  36. $template->param(sidebar => $content);
  37. }
  38. }
  39. } # }}}
  40. 1