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