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
58 sub htmllink_tag ($$$;@) {
64 return htmllink($page, $destpage, taglink($tag), %opts);
70 if ($config{tag_autocreate}) {
71 my $tagpage=taglink($tag);
72 if ($tagpage=~/^\.\/(.*)/) {
79 my $tagfile = newpagefile($tagpage, $config{default_pageext});
81 add_autofile($tagfile, "tag", sub {
82 debug(sprintf(gettext("creating tag page %s"), $tag));
84 my $template=template("autotag.tmpl");
85 $template->param(tag => $tag);
86 writefile($tagfile, $config{srcdir}, $template->output);
91 sub preprocess_tag (@) {
96 my $page = $params{page};
98 delete $params{destpage};
99 delete $params{preview};
101 foreach my $tag (keys %params) {
105 add_link($page, taglink($tag), 'tag');
113 sub preprocess_taglink (@) {
118 return join(" ", map {
120 my $tag=linkpage($2);
121 add_link($params{page}, taglink($tag), 'tag');
123 return htmllink_tag($params{page}, $params{destpage}, $tag,
124 linktext => pagetitle($1));
127 my $tag=linkpage($_);
128 add_link($params{page}, taglink($tag), 'tag');
130 return htmllink_tag($params{page}, $params{destpage}, $tag);
134 $_ ne 'page' && $_ ne 'destpage' && $_ ne 'preview'
138 sub pagetemplate (@) {
140 my $page=$params{page};
141 my $destpage=$params{destpage};
142 my $template=$params{template};
144 my $tags = $typedlinks{$page}{tag};
146 $template->param(tags => [
148 link => htmllink_tag($page, $destpage, $_, rel => "tag")
150 ]) if defined $tags && %$tags && $template->query(name => "tags");
152 if ($template->query(name => "categories")) {
153 # It's an rss/atom template. Add any categories.
154 if (defined $tags && %$tags) {
155 $template->param(categories => [map { category => $_ },
161 package IkiWiki::PageSpec;
163 sub match_tagged ($$;@) {
164 return match_link($_[0], IkiWiki::Plugin::tag::taglink($_[1]), linktype => 'tag');