3 package IkiWiki::Plugin::tag;
12 hook(type => "getopt", id => "tag", call => \&getopt);
13 hook(type => "preprocess", id => "tag", call => \&preprocess_tag, scan => 1);
14 hook(type => "preprocess", id => "taglink", call => \&preprocess_taglink, scan => 1);
15 hook(type => "pagetemplate", id => "tag", call => \&pagetemplate);
19 eval q{use Getopt::Long};
21 Getopt::Long::Configure('pass_through');
22 GetOptions("tagbase=s" => \$config{tagbase});
25 sub tagpage ($) { #{{{
28 if (exists $config{tagbase} &&
29 defined $config{tagbase}) {
30 $tag=$config{tagbase}."/".$tag;
36 sub preprocess_tag (@) { #{{{
41 my $page = $params{page};
43 delete $params{destpage};
44 delete $params{preview};
46 foreach my $tag (keys %params) {
47 $tag=IkiWiki::linkpage($tag);
50 push @{$links{$page}}, tagpage($tag);
56 sub preprocess_taglink (@) { #{{{
63 delete $params{destpage};
64 delete $params{preview};
65 return join(" ", map { "[[$_]]" } keys %params);
68 sub pagetemplate (@) { #{{{
70 my $page=$params{page};
71 my $destpage=$params{destpage};
72 my $template=$params{template};
74 $template->param(tags => [
76 link => htmllink($page, $destpage, tagpage($_),
78 }, sort keys %{$tags{$page}}
79 ]) if exists $tags{$page} && %{$tags{$page}} && $template->query(name => "tags");
81 if ($template->query(name => "categories")) {
82 # It's an rss/atom template. Add any categories.
83 if (exists $tags{$page} && %{$tags{$page}}) {
84 $template->param(categories => [map { category => $_ },
85 sort keys %{$tags{$page}}]);