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",
42 description => "Autocreate new tag pages",
51 if ($tag !~ m{^\.?/} &&
52 defined $config{tagbase}) {
53 $tag="/".$config{tagbase}."/".$tag;
54 $tag=~y#/#/#s; # squash dups
66 return htmllink($page, $destpage, tagpage($tag), %opts);
71 if (defined $config{tag_autocreate} && $config{tag_autocreate}) {
72 my $tagfile = newpagefile(tagpage($tag), $config{default_pageext});
74 return if (srcfile($tagfile,1));
76 debug(sprintf(gettext("creating tag page %s"), $tag));
78 my $template=template("autotag.tmpl");
79 $template->param(tag => $tag);
80 writefile($tagfile, $config{srcdir}, $template->output);
84 sub preprocess_tag (@) {
89 my $page = $params{page};
91 delete $params{destpage};
92 delete $params{preview};
94 foreach my $tag (keys %params) {
98 # add tagpage if necessary
102 add_link($page, tagpage($tag));
108 sub preprocess_taglink (@) {
113 return join(" ", map {
115 my $tag=linkpage($2);
116 $tags{$params{page}}{$tag}=1;
117 add_link($params{page}, tagpage($tag));
118 return taglink($params{page}, $params{destpage}, $tag,
119 linktext => pagetitle($1));
122 my $tag=linkpage($_);
123 $tags{$params{page}}{$tag}=1;
124 add_link($params{page}, tagpage($tag));
125 return taglink($params{page}, $params{destpage}, $tag);
129 $_ ne 'page' && $_ ne 'destpage' && $_ ne 'preview'
133 sub pagetemplate (@) {
135 my $page=$params{page};
136 my $destpage=$params{destpage};
137 my $template=$params{template};
139 $template->param(tags => [
141 link => taglink($page, $destpage, $_, rel => "tag")
142 }, sort keys %{$tags{$page}}
143 ]) if exists $tags{$page} && %{$tags{$page}} && $template->query(name => "tags");
145 if ($template->query(name => "categories")) {
146 # It's an rss/atom template. Add any categories.
147 if (exists $tags{$page} && %{$tags{$page}}) {
148 $template->param(categories => [map { category => $_ },
149 sort keys %{$tags{$page}}]);
154 package IkiWiki::PageSpec;
156 sub match_tagged ($$;@) {
159 return match_link($page, IkiWiki::Plugin::tag::tagpage($glob));