blob: 41d096e0ea9cdd440eac14325112d643981944d2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#!/usr/bin/perl
# Ikiwiki metadata plugin.
package IkiWiki::Plugin::meta;
use warnings;
use strict;
use IkiWiki;
my %meta;
my %title;
sub import { #{{{
IkiWiki::hook(type => "preprocess", id => "meta",
call => \&preprocess);
IkiWiki::hook(type => "pagetemplate", id => "meta",
call => \&pagetemplate);
} # }}}
sub preprocess (@) { #{{{
if (! @_) {
return "";
}
my %params=@_;
my $key=shift;
my $value=$params{$key};
delete $params{$key};
my $page=$params{page};
delete $params{page};
eval q{use CGI 'escapeHTML'};
if ($key eq 'link') {
if (%params) {
$meta{$page}='' unless exists $meta{$page};
$meta{$page}.="<link href=\"".escapeHTML($value)."\" ".
join(" ", map { escapeHTML("$_=\"$params{$_}\"") } keys %params).
" />\n";
}
else {
# hidden WikiLink
push @{$IkiWiki::links{$page}}, $value;
}
}
elsif ($key eq 'title') {
$title{$page}=escapeHTML($value);
}
else {
$meta{$page}='' unless exists $meta{$page};
$meta{$page}.="<meta name=\"".escapeHTML($key)."\" content=\"".escapeHTML($value)."\" />\n";
}
return "";
} # }}}
sub pagetemplate ($$) { #{{{
my $page=shift;
my $template=shift;
$template->param(meta => $meta{$page}) if exists $meta{$page};
$template->param(title => $title{$page}) if exists $title{$page};
} # }}}
1
|