]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/meta.pm
* Add processed date to aggregate preprocessor directive status output.
[git.ikiwiki.info.git] / IkiWiki / Plugin / meta.pm
1 #!/usr/bin/perl
2 # Ikiwiki metadata plugin.
3 package IkiWiki::Plugin::meta;
5 use warnings;
6 use strict;
7 use IkiWiki;
9 my %meta;
10 my %title;
11 my %permalink;
12 my %author;
13 my %authorurl;
15 sub import { #{{{
16         IkiWiki::hook(type => "preprocess", id => "meta", 
17                 call => \&preprocess);
18         IkiWiki::hook(type => "filter", id => "meta", 
19                 call => \&filter);
20         IkiWiki::hook(type => "pagetemplate", id => "meta", 
21                 call => \&pagetemplate);
22 } # }}}
24 sub filter (@) { #{{{
25         my %params=@_;
26         
27         $meta{$params{page}}='';
29         return $params{content};
30 } # }}}
32 sub preprocess (@) { #{{{
33         if (! @_) {
34                 return "";
35         }
36         my %params=@_;
37         my $key=shift;
38         my $value=$params{$key};
39         delete $params{$key};
40         my $page=$params{page};
41         delete $params{page};
42         delete $params{destpage};
44         eval q{use HTML::Entities};
45         # Always dencode, even if encoding later, since it might not be
46         # fully encoded.
47         $value=decode_entities($value);
49         if ($key eq 'link') {
50                 if (%params) {
51                         $meta{$page}.="<link href=\"".encode_entities($value)."\" ".
52                                 join(" ", map { encode_entities($_)."=\"".encode_entities(decode_entities($params{$_}))."\"" } keys %params).
53                                 " />\n";
54                 }
55                 else {
56                         # hidden WikiLink
57                         push @{$IkiWiki::links{$page}}, $value;
58                 }
59         }
60         elsif ($key eq 'title') {
61                 $title{$page}=$value;
62         }
63         elsif ($key eq 'permalink') {
64                 $permalink{$page}=$value;
65                 $meta{$page}.="<link rel=\"bookmark\" href=\"".encode_entities($value)."\" />\n";
66         }
67         else {
68                 $meta{$page}.="<meta name=\"".encode_entities($key).
69                         "\" content=\"".encode_entities($value)."\" />\n";
70                 if ($key eq 'author') {
71                         $author{$page}=$value;
72                 }
73                 elsif ($key eq 'authorurl') {
74                         $authorurl{$page}=$value;
75                 }
76         }
78         return "";
79 } # }}}
81 sub pagetemplate (@) { #{{{
82         my %params=@_;
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         if (exists $title{$page} && $template->query(name => "title")) {
89                 $template->param(title => $title{$page});
90                 $template->param(title_overridden => 1);
91         }
92         $template->param(permalink => $permalink{$page})
93                 if exists $permalink{$page} && $template->query(name => "permalink");
94         $template->param(author => $author{$page})
95                 if exists $author{$page} && $template->query(name => "author");
96         $template->param(authorurl => $authorurl{$page})
97                 if exists $authorurl{$page} && $template->query(name => "authorurl");
98         
99 } # }}}