sub import { #{{{
hook(type => "needsbuild", id => "meta", call => \&needsbuild);
- hook(type => "preprocess", id => "meta", call => \&preprocess);
+ hook(type => "preprocess", id => "meta", call => \&preprocess, scan => 1);
hook(type => "pagetemplate", id => "meta", call => \&pagetemplate);
} # }}}
}
} #}}}
+sub htmlize ($$$) { #{{{
+ my $page = shift;
+ my $destpage = shift;
+
+ return IkiWiki::htmlize($page, pagetype($pagesources{$page}),
+ IkiWiki::linkify($page, $destpage,
+ IkiWiki::preprocess($page, $destpage, shift)));
+}
+
sub preprocess (@) { #{{{
return "" unless @_;
my %params=@_;
# fully encoded.
$value=decode_entities($value);
+ # Metadata collection that needs to happen during the scan pass.
if ($key eq 'title') {
$title{$page}=HTML::Entities::encode_numeric($value);
}
- elsif ($key eq 'permalink') {
- $permalink{$page}=$value;
- push @{$meta{$page}}, scrub('<link rel="bookmark" href="'.encode_entities($value).'" />');
+ elsif ($key eq 'license') {
+ push @{$meta{$page}}, '<link rel="license" href="#page_license" />';
+ $license{$page}=$value;
+ return "";
+ }
+ elsif ($key eq 'copyright') {
+ push @{$meta{$page}}, '<link rel="copyright" href="#page_copyright" />';
+ $copyright{$page}=$value;
+ return "";
+ }
+ elsif ($key eq 'link' && ! %params) {
+ # hidden WikiLink
+ push @{$links{$page}}, $value;
+ return "";
+ }
+ elsif ($key eq 'author') {
+ $author{$page}=$value;
+ # fallthorough
+ }
+ elsif ($key eq 'authorurl') {
+ $authorurl{$page}=$value;
+ # fallthrough
+ }
+
+ if (! defined wantarray) {
+ # avoid collecting duplicate data during scan pass
+ return;
}
- elsif ($key eq 'date') {
+
+ # Metadata collection that happens only during preprocessing pass.
+ if ($key eq 'date') {
eval q{use Date::Parse};
if (! $@) {
my $time = str2time($value);
$IkiWiki::pagectime{$page}=$time if defined $time;
}
}
+ elsif ($key eq 'permalink') {
+ $permalink{$page}=$value;
+ push @{$meta{$page}}, scrub('<link rel="bookmark" href="'.encode_entities($value).'" />');
+ }
elsif ($key eq 'stylesheet') {
my $rel=exists $params{rel} ? $params{rel} : "alternate stylesheet";
my $title=exists $params{title} ? $params{title} : $value;
push @{$meta{$page}}, '<link href="'.encode_entities($value).
'" rel="openid.delegate" />';
}
- elsif ($key eq 'license') {
- push @{$meta{$page}}, '<link rel="license" href="#page_license" />';
- $license{$page}=$value;
- }
- elsif ($key eq 'copyright') {
- push @{$meta{$page}}, '<link rel="copyright" href="#page_copyright" />';
- $copyright{$page}=$value;
- }
elsif ($key eq 'redir') {
return "" if $page ne $destpage;
my $safe=0;
push @{$meta{$page}}, $redir;
}
elsif ($key eq 'link') {
- return "[[meta ".gettext("link is no longer supported")."]]";
+ if (%params) {
+ push @{$meta{$page}}, scrub("<link href=\"".encode_entities($value)."\" ".
+ join(" ", map {
+ encode_entities($_)."=\"".encode_entities(decode_entities($params{$_}))."\""
+ } keys %params).
+ " />\n");
+ }
}
else {
push @{$meta{$page}}, scrub('<meta name="'.encode_entities($key).
'" content="'.encode_entities($value).'" />');
- if ($key eq 'author') {
- $author{$page}=$value;
- }
- elsif ($key eq 'authorurl') {
- $authorurl{$page}=$value;
- }
}
return "";
if exists $author{$page} && $template->query(name => "author");
$template->param(authorurl => $authorurl{$page})
if exists $authorurl{$page} && $template->query(name => "authorurl");
-
- if ($page ne $destpage &&
- ((exists $license{$page} && ! exists $license{$destpage}) ||
- (exists $copyright{$page} && ! exists $copyright{$destpage}))) {
- # Force a scan of the destpage to get its copyright/license
- # info. If the info is declared after an inline, it will
- # otherwise not be available at this point.
- IkiWiki::scan($pagesources{$destpage});
- }
if (exists $license{$page} && $template->query(name => "license") &&
($page eq $destpage || ! exists $license{$destpage} ||
$license{$page} ne $license{$destpage})) {
- $template->param(license => IkiWiki::linkify($page, $destpage, $license{$page}));
+ $template->param(license => htmlize($page, $destpage, $license{$page}));
}
if (exists $copyright{$page} && $template->query(name => "copyright") &&
($page eq $destpage || ! exists $copyright{$destpage} ||
$copyright{$page} ne $copyright{$destpage})) {
- $template->param(copyright => IkiWiki::linkify($page, $destpage, $copyright{$page}));
+ $template->param(copyright => htmlize($page, $destpage, $copyright{$page}));
}
} # }}}