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 => "Autocreate new 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);
69 if (defined $config{tag_autocreate} && $config{tag_autocreate}) {
70 my $tagfile = newpagefile(tagpage($tag), $config{default_pageext});
73 return if (! add_autofile($tagfile, "tag"));
75 debug(sprintf(gettext("creating tag page %s"), $tag));
77 my $template=template("autotag.tmpl");
78 $template->param(tag => $tag);
79 writefile($tagfile, $config{srcdir}, $template->output);
83 sub preprocess_tag (@) {
88 my $page = $params{page};
90 delete $params{destpage};
91 delete $params{preview};
93 foreach my $tag (keys %params) {
97 add_link($page, tagpage($tag), 'tag');
99 # add tagpage if necessary
106 sub preprocess_taglink (@) {
111 return join(" ", map {
113 my $tag=linkpage($2);
114 add_link($params{page}, tagpage($tag), 'tag');
115 return taglink($params{page}, $params{destpage}, $tag,
116 linktext => pagetitle($1));
119 my $tag=linkpage($_);
120 add_link($params{page}, tagpage($tag), 'tag');
121 return taglink($params{page}, $params{destpage}, $tag);
125 $_ ne 'page' && $_ ne 'destpage' && $_ ne 'preview'
129 sub pagetemplate (@) {
131 my $page=$params{page};
132 my $destpage=$params{destpage};
133 my $template=$params{template};
135 my $tags = $typedlinks{$page}{tag};
137 $template->param(tags => [
139 link => taglink($page, $destpage, $_, rel => "tag")
141 ]) if defined $tags && %$tags && $template->query(name => "tags");
143 if ($template->query(name => "categories")) {
144 # It's an rss/atom template. Add any categories.
145 if (defined $tags && %$tags) {
146 $template->param(categories => [map { category => $_ },
152 package IkiWiki::PageSpec;
154 sub match_tagged ($$;@) {
155 return match_link($_[0], IkiWiki::Plugin::tag::tagpage($_[1]), linktype => 'tag');