2 # Ikiwiki metadata plugin.
3 package IkiWiki::Plugin::meta;
16 IkiWiki::hook(type => "preprocess", id => "meta",
17 call => \&preprocess);
18 IkiWiki::hook(type => "filter", id => "meta",
20 IkiWiki::hook(type => "pagetemplate", id => "meta",
21 call => \&pagetemplate);
27 $meta{$params{page}}='';
29 return $params{content};
32 sub preprocess (@) { #{{{
38 my $value=$params{$key};
40 my $page=$params{page};
42 delete $params{destpage};
44 eval q{use HTML::Entities};
45 # Always dencode, even if encoding later, since it might not be
47 $value=decode_entities($value);
51 $meta{$page}.="<link href=\"".encode_entities($value)."\" ".
52 join(" ", map { encode_entities($_)."=\"".encode_entities(decode_entities($params{$_}))."\"" } keys %params).
57 push @{$IkiWiki::links{$page}}, $value;
60 elsif ($key eq 'title') {
63 elsif ($key eq 'permalink') {
64 $permalink{$page}=$value;
65 $meta{$page}.="<link rel=\"bookmark\" href=\"".encode_entities($value)."\" />\n";
68 $meta{$page}.="<meta name=\"".encode_entities($key).
69 "\" content=\"".encode_entities($value)."\" />\n";
70 if ($key eq 'author') {
71 $author{$page}=$value;
73 elsif ($key eq 'authorurl') {
74 $authorurl{$page}=$value;
81 sub pagetemplate (@) { #{{{
83 my $page=$params{page};
84 my $template=$params{template};
86 $template->param(meta => $meta{$page})
87 if exists $meta{$page} && $template->query(name => "meta");
88 $template->param(title => $title{$page})
89 if exists $title{$page} && $template->query(name => "title");
90 $template->param(permalink => $permalink{$page})
91 if exists $permalink{$page} && $template->query(name => "permalink");
92 $template->param(author => $author{$page})
93 if exists $author{$page} && $template->query(name => "author");
94 $template->param(authorurl => $authorurl{$page})
95 if exists $authorurl{$page} && $template->query(name => "authorurl");