summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/farbar.pm
blob: ab4390ab643eb563ea0953eae6d71a3f3dfcec56 (plain)
  1. #!/usr/bin/perl
  2. # Farbar 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::farbar;
  6. use warnings;
  7. use strict;
  8. use IkiWiki 2.00;
  9. sub import { #{{{
  10. hook(type => "pagetemplate", id => "farbar", call => \&pagetemplate);
  11. } # }}}
  12. sub farbar_content ($) { #{{{
  13. my $page=shift;
  14. my $farbar_page=bestlink($page, "farbar") || return;
  15. my $farbar_file=$pagesources{$farbar_page} || return;
  16. my $farbar_type=pagetype($farbar_file);
  17. if (defined $farbar_type) {
  18. # FIXME: This isn't quite right; it won't take into account
  19. # adding a new farbar page. So adding such a page
  20. # currently requires a wiki rebuild.
  21. add_depends($page, $farbar_page);
  22. my $content=readfile(srcfile($farbar_file));
  23. return unless length $content;
  24. return IkiWiki::htmlize($farbar_page, $page, $farbar_type,
  25. IkiWiki::linkify($farbar_page, $page,
  26. IkiWiki::preprocess($farbar_page, $page,
  27. IkiWiki::filter($farbar_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 => "farbar")) {
  35. my $content=farbar_content($page);
  36. if (defined $content && length $content) {
  37. $template->param(farbar => $content);
  38. }
  39. }
  40. } # }}}
  41. 1