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 () { #{{{
35 description => "parent page tags are located under",
41 sub tagpage ($) { #{{{
44 if ($tag !~ m{^\.?/} &&
45 exists $config{tagbase} &&
46 defined $config{tagbase}) {
47 $tag=$config{tagbase}."/".$tag;
53 sub preprocess_tag (@) { #{{{
58 my $page = $params{page};
60 delete $params{destpage};
61 delete $params{preview};
63 foreach my $tag (keys %params) {
64 $tag=IkiWiki::linkpage($tag);
67 push @{$links{$page}}, tagpage($tag);
73 sub preprocess_taglink (@) { #{{{
78 return join(" ", map {
80 my $tag=IkiWiki::linkpage($2);
81 $tags{$params{page}}{$tag}=1;
82 push @{$links{$params{page}}}, tagpage($tag);
83 return htmllink($params{page}, $params{destpage},
85 linktext => IkiWiki::pagetitle($1));
88 my $tag=IkiWiki::linkpage($_);
89 $tags{$params{page}}{$tag}=1;
90 push @{$links{$params{page}}}, tagpage($tag);
91 return htmllink($params{page}, $params{destpage},
96 $_ ne 'page' && $_ ne 'destpage' && $_ ne 'preview'
100 sub pagetemplate (@) { #{{{
102 my $page=$params{page};
103 my $destpage=$params{destpage};
104 my $template=$params{template};
106 $template->param(tags => [
108 link => htmllink($page, $destpage, tagpage($_),
110 }, sort keys %{$tags{$page}}
111 ]) if exists $tags{$page} && %{$tags{$page}} && $template->query(name => "tags");
113 if ($template->query(name => "categories")) {
114 # It's an rss/atom template. Add any categories.
115 if (exists $tags{$page} && %{$tags{$page}}) {
116 $template->param(categories => [map { category => $_ },
117 sort keys %{$tags{$page}}]);