summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/tag.pm
blob: c4e12e61dd01f4dc31d4777d00d78a63300f503b (plain)
  1. #!/usr/bin/perl
  2. # Ikiwiki tag plugin.
  3. package IkiWiki::Plugin::tag;
  4. use warnings;
  5. use strict;
  6. use IkiWiki;
  7. my %tags;
  8. sub import { #{{{
  9. IkiWiki::hook(type => "preprocess", id => "tag",
  10. call => \&preprocess);
  11. IkiWiki::hook(type => "pagetemplate", id => "tag",
  12. call => \&pagetemplate);
  13. } # }}}
  14. sub preprocess (@) { #{{{
  15. if (! @_) {
  16. return "";
  17. }
  18. my %params=@_;
  19. my $page = $params{page};
  20. delete $params{page};
  21. delete $params{destpage};
  22. $tags{$page} = [];
  23. foreach my $tag (keys %params) {
  24. push @{$tags{$page}}, $tag;
  25. # hidden WikiLink
  26. push @{$IkiWiki::links{$page}}, $tag;
  27. }
  28. return "";
  29. } # }}}
  30. sub pagetemplate (@) { #{{{
  31. my %params=@_;
  32. my $page=$params{page};
  33. my $destpage=$params{destpage};
  34. my $template=$params{template};
  35. $template->param(tags => [
  36. map { link => IkiWiki::htmllink($page, $destpage, $_) },
  37. @{$tags{$page}}
  38. ]) if exists $tags{$page} && @{$tags{$page}} && $template->query(name => "tags");
  39. } # }}}
  40. 1