3 package IkiWiki::Plugin::tag;
12 IkiWiki::hook(type => "getopt", id => "tag",
14 IkiWiki::hook(type => "preprocess", id => "tag",
15 call => \&preprocess);
16 IkiWiki::hook(type => "pagetemplate", id => "tag",
17 call => \&pagetemplate);
21 eval q{use Getopt::Long};
22 Getopt::Long::Configure('pass_through');
23 GetOptions("tagbase=s" => \$IkiWiki::config{tagbase});
26 sub tagpage ($) { #{{{
29 if (exists $IkiWiki::config{tagbase} &&
30 defined $IkiWiki::config{tagbase}) {
31 $tag=$IkiWiki::config{tagbase}."/".$tag;
37 sub preprocess (@) { #{{{
42 my $page = $params{page};
44 delete $params{destpage};
47 foreach my $tag (keys %params) {
48 push @{$tags{$page}}, $tag;
50 push @{$IkiWiki::links{$page}}, tagpage($tag);
56 sub pagetemplate (@) { #{{{
58 my $page=$params{page};
59 my $destpage=$params{destpage};
60 my $template=$params{template};
62 $template->param(tags => [
64 link => IkiWiki::htmllink($page, $destpage, tagpage($_))
66 ]) if exists $tags{$page} && @{$tags{$page}} && $template->query(name => "tags");
68 if ($template->query(name => "pubdate")) {
69 # It's an rss template. Add any categories.
70 if (exists $tags{$page} && @{$tags{$page}}) {
71 $template->param(categories => [map { category => $_ }, @{$tags{$page}}]);