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};
41 eval q{use HTML::Entities};
42 # Always dencode, even if encoding later, since it might not be
44 $value=decode_entities($value);
48 $meta{$page}.="<link href=\"".encode_entities($value)."\" ".
49 join(" ", map { encode_entities($_)."=\"".encode_entities(decode_entities($params{$_}))."\"" } keys %params).
54 push @{$links{$page}}, $value;
57 elsif ($key eq 'title') {
60 elsif ($key eq 'permalink') {
61 $permalink{$page}=$value;
62 $meta{$page}.="<link rel=\"bookmark\" href=\"".encode_entities($value)."\" />\n";
64 elsif ($key eq 'date') {
65 eval q{use Date::Parse};
67 my $time = str2time($value);
68 $IkiWiki::pagectime{$page}=$time if defined $time;
72 $meta{$page}.="<meta name=\"".encode_entities($key).
73 "\" content=\"".encode_entities($value)."\" />\n";
74 if ($key eq 'author') {
75 $author{$page}=$value;
77 elsif ($key eq 'authorurl') {
78 $authorurl{$page}=$value;
85 sub pagetemplate (@) { #{{{
87 my $page=$params{page};
88 my $template=$params{template};
90 $template->param(meta => $meta{$page})
91 if exists $meta{$page} && $template->query(name => "meta");
92 if (exists $title{$page} && $template->query(name => "title")) {
93 $template->param(title => $title{$page});
94 $template->param(title_overridden => 1);
96 $template->param(permalink => $permalink{$page})
97 if exists $permalink{$page} && $template->query(name => "permalink");
98 $template->param(author => $author{$page})
99 if exists $author{$page} && $template->query(name => "author");
100 $template->param(authorurl => $authorurl{$page})
101 if exists $authorurl{$page} && $template->query(name => "authorurl");