- Adds a tag plugin that allows more easily tagging pages.
[ikiwiki.git] / IkiWiki / Plugin / tag.pm
1 #!/usr/bin/perl
2 # Ikiwiki tag plugin.
3 package IkiWiki::Plugin::tag;
4
5 use warnings;
6 use strict;
7 use IkiWiki;
8
9 my %tags;
10
11 sub import { #{{{
12         IkiWiki::hook(type => "preprocess", id => "tag",
13                 call => \&preprocess);
14         IkiWiki::hook(type => "pagetemplate", id => "tag",
15                 call => \&pagetemplate);
16 } # }}}
17
18 sub preprocess (@) { #{{{
19         if (! @_) {
20                 return "";
21         }
22         my %params=@_;
23         my $page = $params{page};
24         delete $params{page};
25
26         $tags{$page} = [];
27         foreach my $tag (keys %params) {
28                 push @{$tags{$page}}, $tag;
29                 # hidden WikiLink
30                 push @{$IkiWiki::links{$page}}, $tag;
31         }
32                 
33         return "";
34 } # }}}
35
36 sub pagetemplate ($$) { #{{{
37         my $page=shift;
38         my $template=shift;
39
40         $template->param(tags => join(', ', 
41                         map { IkiWiki::htmllink($page, $page, $_) } 
42                                 @{$tags{$page}}))
43                 if exists $tags{$page} && $template->query(name => "tags");
44 } # }}}
45
46 1