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 () { #{{{
32 description => "parent page tags are located under",
38 sub tagpage ($) { #{{{
41 if ($tag !~ m{^\.?/} &&
42 exists $config{tagbase} &&
43 defined $config{tagbase}) {
44 $tag=$config{tagbase}."/".$tag;
50 sub preprocess_tag (@) { #{{{
55 my $page = $params{page};
57 delete $params{destpage};
58 delete $params{preview};
60 foreach my $tag (keys %params) {
61 $tag=IkiWiki::linkpage($tag);
64 push @{$links{$page}}, tagpage($tag);
70 sub preprocess_taglink (@) { #{{{
75 return join(" ", map {
77 my $tag=IkiWiki::linkpage($2);
78 $tags{$params{page}}{$tag}=1;
79 push @{$links{$params{page}}}, tagpage($tag);
80 return htmllink($params{page}, $params{destpage},
82 linktext => IkiWiki::pagetitle($1));
85 my $tag=IkiWiki::linkpage($_);
86 $tags{$params{page}}{$tag}=1;
87 push @{$links{$params{page}}}, tagpage($tag);
88 return htmllink($params{page}, $params{destpage},
93 $_ ne 'page' && $_ ne 'destpage' && $_ ne 'preview'
97 sub pagetemplate (@) { #{{{
99 my $page=$params{page};
100 my $destpage=$params{destpage};
101 my $template=$params{template};
103 $template->param(tags => [
105 link => htmllink($page, $destpage, tagpage($_),
107 }, sort keys %{$tags{$page}}
108 ]) if exists $tags{$page} && %{$tags{$page}} && $template->query(name => "tags");
110 if ($template->query(name => "categories")) {
111 # It's an rss/atom template. Add any categories.
112 if (exists $tags{$page} && %{$tags{$page}}) {
113 $template->param(categories => [map { category => $_ },
114 sort keys %{$tags{$page}}]);