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-07-28 07:26:49 +02:00
|
|
|
IkiWiki::hook(type => "getopt", id => "tag",
|
|
|
|
call => \&getopt);
|
2006-07-28 01:08:03 +02:00
|
|
|
IkiWiki::hook(type => "preprocess", id => "tag",
|
|
|
|
call => \&preprocess);
|
|
|
|
IkiWiki::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};
|
|
|
|
Getopt::Long::Configure('pass_through');
|
|
|
|
GetOptions("tagbase=s" => \$IkiWiki::config{tagbase});
|
|
|
|
} #}}}
|
|
|
|
|
2006-07-29 09:25:17 +02:00
|
|
|
sub tagpage ($) { #{{{
|
|
|
|
my $tag=shift;
|
|
|
|
|
|
|
|
if (exists $IkiWiki::config{tagbase} &&
|
|
|
|
defined $IkiWiki::config{tagbase}) {
|
|
|
|
$tag=$IkiWiki::config{tagbase}."/".$tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
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};
|
2006-07-27 23:38:02 +02:00
|
|
|
|
2006-07-28 01:08:03 +02:00
|
|
|
$tags{$page} = [];
|
2006-07-27 23:38:02 +02:00
|
|
|
foreach my $tag (keys %params) {
|
2006-07-28 01:08:03 +02:00
|
|
|
push @{$tags{$page}}, $tag;
|
2006-07-27 23:38:02 +02:00
|
|
|
# hidden WikiLink
|
2006-07-29 09:25:17 +02:00
|
|
|
push @{$IkiWiki::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 {
|
|
|
|
link => IkiWiki::htmllink($page, $destpage, tagpage($_))
|
|
|
|
}, @{$tags{$page}}
|
2006-07-28 02:21:13 +02:00
|
|
|
]) if exists $tags{$page} && @{$tags{$page}} && $template->query(name => "tags");
|
2006-07-29 09:25:17 +02:00
|
|
|
|
2006-07-31 02:34:18 +02:00
|
|
|
if ($template->query(name => "pubdate")) {
|
|
|
|
# It's an rss template. Add any categories.
|
|
|
|
if (exists $tags{$page} && @{$tags{$page}}) {
|
|
|
|
$template->param(categories => [map { category => $_ }, @{$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
|