3 package IkiWiki::Plugin::tag;
12 hook(type => "getopt", id => "tag", call => \&getopt);
13 hook(type => "preprocess", id => "tag", call => \&preprocess, scan => 1);
14 hook(type => "pagetemplate", id => "tag", call => \&pagetemplate);
18 eval q{use Getopt::Long};
20 Getopt::Long::Configure('pass_through');
21 GetOptions("tagbase=s" => \$config{tagbase});
24 sub tagpage ($) { #{{{
27 if (exists $config{tagbase} &&
28 defined $config{tagbase}) {
29 $tag=$config{tagbase}."/".$tag;
35 sub preprocess (@) { #{{{
40 my $page = $params{page};
42 delete $params{destpage};
43 delete $params{preview};
45 foreach my $tag (keys %params) {
48 push @{$links{$page}}, tagpage($tag);
54 sub pagetemplate (@) { #{{{
56 my $page=$params{page};
57 my $destpage=$params{destpage};
58 my $template=$params{template};
60 $template->param(tags => [
62 link => htmllink($page, $destpage, tagpage($_))
63 }, sort keys %{$tags{$page}}
64 ]) if exists $tags{$page} && %{$tags{$page}} && $template->query(name => "tags");
66 if ($template->query(name => "categories")) {
67 # It's an rss/atom template. Add any categories.
68 if (exists $tags{$page} && %{$tags{$page}}) {
69 $template->param(categories => [map { category => $_ },
70 sort keys %{$tags{$page}}]);