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};
30 if (IkiWiki::Plugin::htmlscrubber->can("sanitize")) {
31 return IkiWiki::Plugin::htmlscrubber::sanitize(content => shift);
38 sub preprocess (@) { #{{{
44 my $value=$params{$key};
46 my $page=$params{page};
48 delete $params{destpage};
49 delete $params{preview};
51 eval q{use HTML::Entities};
52 # Always dencode, even if encoding later, since it might not be
54 $value=decode_entities($value);
58 $meta{$page}.=scrub("<link href=\"".encode_entities($value)."\" ".
59 join(" ", map { encode_entities($_)."=\"".encode_entities(decode_entities($params{$_}))."\"" } keys %params).
64 push @{$links{$page}}, $value;
67 elsif ($key eq 'title') {
68 $title{$page}=HTML::Entities::encode_numeric($value);
70 elsif ($key eq 'permalink') {
71 $permalink{$page}=$value;
72 $meta{$page}.=scrub("<link rel=\"bookmark\" href=\"".encode_entities($value)."\" />\n");
74 elsif ($key eq 'date') {
75 eval q{use Date::Parse};
77 my $time = str2time($value);
78 $IkiWiki::pagectime{$page}=$time if defined $time;
81 elsif ($key eq 'stylesheet') {
82 my $rel=exists $params{rel} ? $params{rel} : "alternate stylesheet";
83 my $title=exists $params{title} ? $params{title} : $value;
84 # adding .css to the value prevents using any old web
85 # editable page as a stylesheet
86 my $stylesheet=bestlink($page, $value.".css");
87 if (! length $stylesheet) {
88 return "[[meta ".gettext("stylesheet not found")."]]";
90 $meta{$page}.='<link href="'.$stylesheet.
91 '" rel="'.encode_entities($rel).
92 '" title="'.encode_entities($title).
93 "\" style=\"text/css\" />\n";
95 elsif ($key eq 'openid') {
96 if (exists $params{server}) {
97 $meta{$page}.='<link href="'.encode_entities($params{server}).
98 "\" rel=\"openid.server\" />\n";
100 $meta{$page}.='<link href="'.encode_entities($value).
101 "\" rel=\"openid.delegate\" />\n";
104 $meta{$page}.=scrub("<meta name=\"".encode_entities($key).
105 "\" content=\"".encode_entities($value)."\" />\n");
106 if ($key eq 'author') {
107 $author{$page}=$value;
109 elsif ($key eq 'authorurl') {
110 $authorurl{$page}=$value;
117 sub pagetemplate (@) { #{{{
119 my $page=$params{page};
120 my $template=$params{template};
122 $template->param(meta => $meta{$page})
123 if exists $meta{$page} && $template->query(name => "meta");
124 if (exists $title{$page} && $template->query(name => "title")) {
125 $template->param(title => $title{$page});
126 $template->param(title_overridden => 1);
128 $template->param(permalink => $permalink{$page})
129 if exists $permalink{$page} && $template->query(name => "permalink");
130 $template->param(author => $author{$page})
131 if exists $author{$page} && $template->query(name => "author");
132 $template->param(authorurl => $authorurl{$page})
133 if exists $authorurl{$page} && $template->query(name => "authorurl");