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",
40 description => "if 1, tagged() doesn't match normal WikiLinks to tag pages",
49 if ($tag !~ m{^\.?/} &&
50 defined $config{tagbase}) {
51 $tag="/".$config{tagbase}."/".$tag;
52 $tag=~y#/#/#s; # squash dups
64 return htmllink($page, $destpage, tagpage($tag), %opts);
67 sub preprocess_tag (@) {
72 my $page = $params{page};
74 delete $params{destpage};
75 delete $params{preview};
77 foreach my $tag (keys %params) {
80 add_link($page, tagpage($tag), 'tag');
86 sub preprocess_taglink (@) {
91 return join(" ", map {
94 add_link($params{page}, tagpage($tag), 'tag');
95 return taglink($params{page}, $params{destpage}, $tag,
96 linktext => pagetitle($1));
100 add_link($params{page}, tagpage($tag), 'tag');
101 return taglink($params{page}, $params{destpage}, $tag);
105 $_ ne 'page' && $_ ne 'destpage' && $_ ne 'preview'
109 sub pagetemplate (@) {
111 my $page=$params{page};
112 my $destpage=$params{destpage};
113 my $template=$params{template};
115 my $tags = $typedlinks{$page}{tag};
117 $template->param(tags => [
119 link => taglink($page, $destpage, $_, rel => "tag")
121 ]) if defined $tags && %$tags && $template->query(name => "tags");
123 if ($template->query(name => "categories")) {
124 # It's an rss/atom template. Add any categories.
125 if (defined $tags && %$tags) {
126 $template->param(categories => [map { category => $_ },
132 package IkiWiki::PageSpec;
134 sub match_tagged ($$;@) {
138 if ($IkiWiki::config{tagged_is_strict}) {
139 return match_link($page, IkiWiki::Plugin::tag::tagpage($glob), linktype => 'tag');
142 return match_link($page, IkiWiki::Plugin::tag::tagpage($glob));