]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/tag.pm
more destpage improvements
[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         delete $params{destpage};
26
27         $tags{$page} = [];
28         foreach my $tag (keys %params) {
29                 push @{$tags{$page}}, $tag;
30                 # hidden WikiLink
31                 push @{$IkiWiki::links{$page}}, $tag;
32         }
33                 
34         return "";
35 } # }}}
36
37 sub pagetemplate (@) { #{{{
38         my %params=@_;
39         my $page=$params{page};
40         my $destpage=$params{destpage};
41         my $template=$params{template};
42
43         $template->param(tags => join(', ', 
44                         map { IkiWiki::htmllink($page, $destpage, $_) } 
45                                 @{$tags{$page}}))
46                 if exists $tags{$page} && $template->query(name => "tags");
47 } # }}}
48
49 1