3 package IkiWiki::Plugin::tag;
12 hook(type => "getopt", id => "tag", call => \&getopt);
13 hook(type => "getsetup", id => "tag", call => \&getsetup);
14 hook(type => "preprocess", id => "tag", call => \&preprocess_tag, scan => 1);
15 hook(type => "preprocess", id => "taglink", call => \&preprocess_taglink, scan => 1);
16 hook(type => "pagetemplate", id => "tag", call => \&pagetemplate);
20 eval q{use Getopt::Long};
22 Getopt::Long::Configure('pass_through');
23 GetOptions("tagbase=s" => \$config{tagbase});
26 sub getsetup () { #{{{
31 description => "parent page tags are located under",
37 sub tagpage ($) { #{{{
40 if ($tag !~ m{^\.?/} &&
41 exists $config{tagbase} &&
42 defined $config{tagbase}) {
43 $tag=$config{tagbase}."/".$tag;
49 sub preprocess_tag (@) { #{{{
54 my $page = $params{page};
56 delete $params{destpage};
57 delete $params{preview};
59 foreach my $tag (keys %params) {
60 $tag=IkiWiki::linkpage($tag);
63 push @{$links{$page}}, tagpage($tag);
69 sub preprocess_taglink (@) { #{{{
74 return join(" ", map {
76 my $tag=IkiWiki::linkpage($2);
77 $tags{$params{page}}{$tag}=1;
78 push @{$links{$params{page}}}, tagpage($tag);
79 return htmllink($params{page}, $params{destpage},
81 linktext => IkiWiki::pagetitle($1));
84 my $tag=IkiWiki::linkpage($_);
85 $tags{$params{page}}{$tag}=1;
86 push @{$links{$params{page}}}, tagpage($tag);
87 return htmllink($params{page}, $params{destpage},
92 $_ ne 'page' && $_ ne 'destpage' && $_ ne 'preview'
96 sub pagetemplate (@) { #{{{
98 my $page=$params{page};
99 my $destpage=$params{destpage};
100 my $template=$params{template};
102 $template->param(tags => [
104 link => htmllink($page, $destpage, tagpage($_),
106 }, sort keys %{$tags{$page}}
107 ]) if exists $tags{$page} && %{$tags{$page}} && $template->query(name => "tags");
109 if ($template->query(name => "categories")) {
110 # It's an rss/atom template. Add any categories.
111 if (exists $tags{$page} && %{$tags{$page}}) {
112 $template->param(categories => [map { category => $_ },
113 sort keys %{$tags{$page}}]);