2006-07-27 23:38:02 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# Ikiwiki tag plugin.
|
|
|
|
package IkiWiki::Plugin::tag;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use IkiWiki;
|
|
|
|
|
2006-07-28 01:08:03 +02:00
|
|
|
my %tags;
|
2006-07-27 23:38:02 +02:00
|
|
|
|
|
|
|
sub import { #{{{
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "getopt", id => "tag", call => \&getopt);
|
2006-10-28 07:07:56 +02:00
|
|
|
hook(type => "preprocess", id => "tag", call => \&preprocess, scan => 1);
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "pagetemplate", id => "tag", call => \&pagetemplate);
|
2006-07-27 23:38:02 +02:00
|
|
|
} # }}}
|
|
|
|
|
2006-07-28 07:26:49 +02:00
|
|
|
sub getopt () { #{{{
|
|
|
|
eval q{use Getopt::Long};
|
2006-11-08 22:03:33 +01:00
|
|
|
error($@) if $@;
|
2006-07-28 07:26:49 +02:00
|
|
|
Getopt::Long::Configure('pass_through');
|
2006-09-10 00:50:27 +02:00
|
|
|
GetOptions("tagbase=s" => \$config{tagbase});
|
2006-07-28 07:26:49 +02:00
|
|
|
} #}}}
|
|
|
|
|
2006-07-29 09:25:17 +02:00
|
|
|
sub tagpage ($) { #{{{
|
|
|
|
my $tag=shift;
|
|
|
|
|
2006-09-10 00:50:27 +02:00
|
|
|
if (exists $config{tagbase} &&
|
|
|
|
defined $config{tagbase}) {
|
|
|
|
$tag=$config{tagbase}."/".$tag;
|
2006-07-29 09:25:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $tag;
|
|
|
|
} #}}}
|
|
|
|
|
2006-07-27 23:38:02 +02:00
|
|
|
sub preprocess (@) { #{{{
|
|
|
|
if (! @_) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
my %params=@_;
|
|
|
|
my $page = $params{page};
|
|
|
|
delete $params{page};
|
2006-07-28 01:47:13 +02:00
|
|
|
delete $params{destpage};
|
2007-03-07 06:53:47 +01:00
|
|
|
delete $params{preview};
|
2006-07-27 23:38:02 +02:00
|
|
|
|
|
|
|
foreach my $tag (keys %params) {
|
2007-02-14 05:05:08 +01:00
|
|
|
$tags{$page}{$tag}=1;
|
2006-07-27 23:38:02 +02:00
|
|
|
# hidden WikiLink
|
2006-09-10 00:50:27 +02:00
|
|
|
push @{$links{$page}}, tagpage($tag);
|
2006-07-27 23:38:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
} # }}}
|
|
|
|
|
2006-07-28 01:41:58 +02:00
|
|
|
sub pagetemplate (@) { #{{{
|
|
|
|
my %params=@_;
|
|
|
|
my $page=$params{page};
|
|
|
|
my $destpage=$params{destpage};
|
|
|
|
my $template=$params{template};
|
2006-07-28 01:08:03 +02:00
|
|
|
|
2006-07-28 02:21:13 +02:00
|
|
|
$template->param(tags => [
|
2006-07-29 09:25:17 +02:00
|
|
|
map {
|
2006-09-10 00:50:27 +02:00
|
|
|
link => htmllink($page, $destpage, tagpage($_))
|
2007-02-14 05:05:08 +01:00
|
|
|
}, sort keys %{$tags{$page}}
|
|
|
|
]) if exists $tags{$page} && %{$tags{$page}} && $template->query(name => "tags");
|
2006-07-29 09:25:17 +02:00
|
|
|
|
2007-01-14 21:14:36 +01:00
|
|
|
if ($template->query(name => "categories")) {
|
|
|
|
# It's an rss/atom template. Add any categories.
|
2007-02-14 05:05:08 +01:00
|
|
|
if (exists $tags{$page} && %{$tags{$page}}) {
|
|
|
|
$template->param(categories => [map { category => $_ },
|
|
|
|
sort keys %{$tags{$page}}]);
|
2006-07-29 09:25:17 +02:00
|
|
|
}
|
|
|
|
}
|
2006-07-28 01:08:03 +02:00
|
|
|
} # }}}
|
|
|
|
|
2006-07-27 23:38:02 +02:00
|
|
|
1
|