summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/sidebar.pm
blob: 1685d37a4a7312e559f42f68e6efa6f35dd93f43 (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;
  8. sub import { #{{{
  9. IkiWiki::hook(type => "pagetemplate", id => "sidebar",
  10. call => \&pagetemplate);
  11. } # }}}
  12. sub sidebar_content ($) { #{{{
  13. my $page=shift;
  14. my $sidebar_page=IkiWiki::bestlink($page, "sidebar") || return;
  15. my $sidebar_file=$IkiWiki::pagesources{$sidebar_page} || return;
  16. my $sidebar_type=IkiWiki::pagetype($sidebar_file);
  17. if (defined $sidebar_type) {
  18. IkiWiki::add_depends($page, $sidebar_page);
  19. my $content=IkiWiki::readfile(IkiWiki::srcfile($sidebar_file));
  20. return unless length $content;
  21. return IkiWiki::htmlize($sidebar_type,
  22. IkiWiki::preprocess($sidebar_page, $page,
  23. IkiWiki::linkify($sidebar_page, $page,
  24. IkiWiki::filter($sidebar_page, $content))));
  25. }
  26. } # }}}
  27. sub pagetemplate (@) { #{{{
  28. my %params=@_;
  29. my $page=$params{page};
  30. my $template=$params{template};
  31. if ($template->query(name => "sidebar")) {
  32. my $content=sidebar_content($page);
  33. if (defined $content && length $content) {
  34. $template->param(sidebar => $content);
  35. }
  36. }
  37. } # }}}
  38. 1