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 defined $config{tagbase}) {
46 $tag="/".$config{tagbase}."/".$tag;
52 sub taglink ($$$;@) { #{{{
58 my $link=tagpage($tag);
60 # Force tag creation links to create the tag under /tagbase,
61 # if there is a tagbase and this tag used it.
62 $link="/".$link if $tag ne $link;
64 return htmllink($page, $destpage, $link, %opts);
67 sub preprocess_tag (@) { #{{{
72 my $page = $params{page};
74 delete $params{destpage};
75 delete $params{preview};
77 foreach my $tag (keys %params) {
81 push @{$links{$page}}, tagpage($tag);
87 sub preprocess_taglink (@) { #{{{
92 return join(" ", map {
95 $tags{$params{page}}{$tag}=1;
96 push @{$links{$params{page}}}, tagpage($tag);
97 return taglink($params{page}, $params{destpage}, $tag,
98 linktext => pagetitle($1));
101 my $tag=linkpage($_);
102 $tags{$params{page}}{$tag}=1;
103 push @{$links{$params{page}}}, tagpage($tag);
104 return taglink($params{page}, $params{destpage}, $tag);
108 $_ ne 'page' && $_ ne 'destpage' && $_ ne 'preview'
112 sub pagetemplate (@) { #{{{
114 my $page=$params{page};
115 my $destpage=$params{destpage};
116 my $template=$params{template};
118 $template->param(tags => [
120 link => taglink($page, $destpage, $_, rel => "tag")
121 }, sort keys %{$tags{$page}}
122 ]) if exists $tags{$page} && %{$tags{$page}} && $template->query(name => "tags");
124 if ($template->query(name => "categories")) {
125 # It's an rss/atom template. Add any categories.
126 if (exists $tags{$page} && %{$tags{$page}}) {
127 $template->param(categories => [map { category => $_ },
128 sort keys %{$tags{$page}}]);