2 # Ikiwiki metadata plugin.
3 package IkiWiki::Plugin::meta;
16 hook(type => "preprocess", id => "meta", call => \&preprocess, scan => 1);
17 hook(type => "filter", id => "meta", call => \&filter);
18 hook(type => "pagetemplate", id => "meta", call => \&pagetemplate);
24 $meta{$params{page}}='';
26 return $params{content};
29 sub preprocess (@) { #{{{
35 my $value=$params{$key};
37 my $page=$params{page};
39 delete $params{destpage};
40 delete $params{preview};
42 eval q{use HTML::Entities};
43 # Always dencode, even if encoding later, since it might not be
45 $value=decode_entities($value);
49 $meta{$page}.="<link href=\"".encode_entities($value)."\" ".
50 join(" ", map { encode_entities($_)."=\"".encode_entities(decode_entities($params{$_}))."\"" } keys %params).
55 push @{$links{$page}}, $value;
58 elsif ($key eq 'title') {
61 elsif ($key eq 'permalink') {
62 $permalink{$page}=$value;
63 $meta{$page}.="<link rel=\"bookmark\" href=\"".encode_entities($value)."\" />\n";
65 elsif ($key eq 'date') {
66 eval q{use Date::Parse};
68 my $time = str2time($value);
69 $IkiWiki::pagectime{$page}=$time if defined $time;
73 $meta{$page}.="<meta name=\"".encode_entities($key).
74 "\" content=\"".encode_entities($value)."\" />\n";
75 if ($key eq 'author') {
76 $author{$page}=$value;
78 elsif ($key eq 'authorurl') {
79 $authorurl{$page}=$value;
86 sub pagetemplate (@) { #{{{
88 my $page=$params{page};
89 my $template=$params{template};
91 $template->param(meta => $meta{$page})
92 if exists $meta{$page} && $template->query(name => "meta");
93 if (exists $title{$page} && $template->query(name => "title")) {
94 $template->param(title => $title{$page});
95 $template->param(title_overridden => 1);
97 $template->param(permalink => $permalink{$page})
98 if exists $permalink{$page} && $template->query(name => "permalink");
99 $template->param(author => $author{$page})
100 if exists $author{$page} && $template->query(name => "author");
101 $template->param(authorurl => $authorurl{$page})
102 if exists $authorurl{$page} && $template->query(name => "authorurl");