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});
35 description => "parent page tags are located under",
44 if ($tag !~ m{^\.?/} &&
45 defined $config{tagbase}) {
46 $tag="/".$config{tagbase}."/".$tag;
47 $tag=~y#/#/#s; # squash dups
59 return htmllink($page, $destpage, tagpage($tag), %opts);
62 sub preprocess_tag (@) {
67 my $page = $params{page};
69 delete $params{destpage};
70 delete $params{preview};
72 foreach my $tag (keys %params) {
76 add_link($page, tagpage($tag));
82 sub preprocess_taglink (@) {
87 return join(" ", map {
90 $tags{$params{page}}{$tag}=1;
91 add_link($params{page}, tagpage($tag));
92 return taglink($params{page}, $params{destpage}, $tag,
93 linktext => pagetitle($1));
97 $tags{$params{page}}{$tag}=1;
98 add_link($params{page}, tagpage($tag));
99 return taglink($params{page}, $params{destpage}, $tag);
103 $_ ne 'page' && $_ ne 'destpage' && $_ ne 'preview'
107 sub pagetemplate (@) {
109 my $page=$params{page};
110 my $destpage=$params{destpage};
111 my $template=$params{template};
113 $template->param(tags => [
115 link => taglink($page, $destpage, $_, rel => "tag")
116 }, sort keys %{$tags{$page}}
117 ]) if exists $tags{$page} && %{$tags{$page}} && $template->query(name => "tags");
119 if ($template->query(name => "categories")) {
120 # It's an rss/atom template. Add any categories.
121 if (exists $tags{$page} && %{$tags{$page}}) {
122 $template->param(categories => [map { category => $_ },
123 sort keys %{$tags{$page}}]);
128 package IkiWiki::PageSpec;
130 sub match_tagged ($$;@) {
133 return match_link($page, IkiWiki::Plugin::tag::tagpage($glob));