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 ($tag !~ m{^\.?/} &&
29 exists $config{tagbase} &&
30 defined $config{tagbase}) {
31 $tag=$config{tagbase}."/".$tag;
37 sub preprocess_tag (@) { #{{{
42 my $page = $params{page};
44 delete $params{destpage};
45 delete $params{preview};
47 foreach my $tag (keys %params) {
48 $tag=IkiWiki::linkpage($tag);
51 push @{$links{$page}}, tagpage($tag);
57 sub preprocess_taglink (@) { #{{{
62 return join(" ", map {
64 my $tag=IkiWiki::linkpage($2);
65 $tags{$params{page}}{$tag}=1;
66 push @{$links{$params{page}}}, tagpage($tag);
67 return htmllink($params{page}, $params{destpage},
69 linktext => IkiWiki::pagetitle($1));
72 my $tag=IkiWiki::linkpage($_);
73 $tags{$params{page}}{$tag}=1;
74 push @{$links{$params{page}}}, tagpage($tag);
75 return htmllink($params{page}, $params{destpage},
80 $_ ne 'page' && $_ ne 'destpage' && $_ ne 'preview'
84 sub pagetemplate (@) { #{{{
86 my $page=$params{page};
87 my $destpage=$params{destpage};
88 my $template=$params{template};
90 $template->param(tags => [
92 link => htmllink($page, $destpage, tagpage($_),
94 }, sort keys %{$tags{$page}}
95 ]) if exists $tags{$page} && %{$tags{$page}} && $template->query(name => "tags");
97 if ($template->query(name => "categories")) {
98 # It's an rss/atom template. Add any categories.
99 if (exists $tags{$page} && %{$tags{$page}}) {
100 $template->param(categories => [map { category => $_ },
101 sort keys %{$tags{$page}}]);