summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/tag.pm
blob: f1f3b77f5fc6ea8566607279ba3f6c6d4104e1b3 (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. $tags{$page} = [];
  22. foreach my $tag (keys %params) {
  23. push @{$tags{$page}}, $tag;
  24. # hidden WikiLink
  25. push @{$IkiWiki::links{$page}}, $tag;
  26. }
  27. return "";
  28. } # }}}
  29. sub pagetemplate (@) { #{{{
  30. my %params=@_;
  31. my $page=$params{page};
  32. my $destpage=$params{destpage};
  33. my $template=$params{template};
  34. $template->param(tags => join(', ',
  35. map { IkiWiki::htmllink($page, $destpage, $_) }
  36. @{$tags{$page}}))
  37. if exists $tags{$page} && $template->query(name => "tags");
  38. } # }}}
  39. 1