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 (@) { #{{{
61 return join(" ", map {
63 my $tag=IkiWiki::linkpage($2);
64 $tags{$params{page}}{$tag}=1;
65 push @{$links{$params{page}}}, tagpage($tag);
66 return htmllink($params{page}, $params{destpage},
68 linktext => IkiWiki::pagetitle($1));
71 my $tag=IkiWiki::linkpage($_);
72 $tags{$params{page}}{$tag}=1;
73 push @{$links{$params{page}}}, tagpage($tag);
74 return htmllink($params{page}, $params{destpage},
79 $_ ne 'page' && $_ ne 'destpage' && $_ ne 'preview'
83 sub pagetemplate (@) { #{{{
85 my $page=$params{page};
86 my $destpage=$params{destpage};
87 my $template=$params{template};
89 $template->param(tags => [
91 link => htmllink($page, $destpage, tagpage($_),
93 }, sort keys %{$tags{$page}}
94 ]) if exists $tags{$page} && %{$tags{$page}} && $template->query(name => "tags");
96 if ($template->query(name => "categories")) {
97 # It's an rss/atom template. Add any categories.
98 if (exists $tags{$page} && %{$tags{$page}}) {
99 $template->param(categories => [map { category => $_ },
100 sort keys %{$tags{$page}}]);