3 package IkiWiki::Plugin::tag;
10 hook(type => "getopt", id => "tag", call => \&getopt);
11 hook(type => "getsetup", id => "tag", call => \&getsetup);
12 hook(type => "preprocess", id => "tag", call => \&preprocess_tag, scan => 1);
13 hook(type => "preprocess", id => "taglink", call => \&preprocess_taglink, scan => 1);
14 hook(type => "pagetemplate", id => "tag", call => \&pagetemplate);
18 eval q{use Getopt::Long};
20 Getopt::Long::Configure('pass_through');
21 GetOptions("tagbase=s" => \$config{tagbase});
33 description => "parent page tags are located under",
42 if ($tag !~ m{^\.?/} &&
43 defined $config{tagbase}) {
44 $tag="/".$config{tagbase}."/".$tag;
45 $tag=~y#/#/#s; # squash dups
57 return htmllink($page, $destpage, tagpage($tag), %opts);
60 sub preprocess_tag (@) {
65 my $page = $params{page};
67 delete $params{destpage};
68 delete $params{preview};
70 foreach my $tag (keys %params) {
73 add_link($page, tagpage($tag), 'tag');
79 sub preprocess_taglink (@) {
84 return join(" ", map {
87 add_link($params{page}, tagpage($tag), 'tag');
88 return taglink($params{page}, $params{destpage}, $tag,
89 linktext => pagetitle($1));
93 add_link($params{page}, tagpage($tag), 'tag');
94 return taglink($params{page}, $params{destpage}, $tag);
98 $_ ne 'page' && $_ ne 'destpage' && $_ ne 'preview'
102 sub pagetemplate (@) {
104 my $page=$params{page};
105 my $destpage=$params{destpage};
106 my $template=$params{template};
108 my $tags = $typedlinks{$page}{tag};
110 $template->param(tags => [
112 link => taglink($page, $destpage, $_, rel => "tag")
114 ]) if defined $tags && %$tags && $template->query(name => "tags");
116 if ($template->query(name => "categories")) {
117 # It's an rss/atom template. Add any categories.
118 if (defined $tags && %$tags) {
119 $template->param(categories => [map { category => $_ },
125 package IkiWiki::PageSpec;
127 sub match_tagged ($$;@) {
128 return match_link($_[0], IkiWiki::Plugin::tag::tagpage($_[1]), linktype => 'tag');