summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/meta.pm
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki/Plugin/meta.pm')
-rw-r--r--IkiWiki/Plugin/meta.pm72
1 files changed, 43 insertions, 29 deletions
diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
index 88c942fa4..586dbcb81 100644
--- a/IkiWiki/Plugin/meta.pm
+++ b/IkiWiki/Plugin/meta.pm
@@ -16,7 +16,7 @@ my %copyright;
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);
} # }}}
@@ -77,13 +77,10 @@ sub preprocess (@) { #{{{
# 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 'date') {
eval q{use Date::Parse};
if (! $@) {
@@ -91,6 +88,40 @@ sub preprocess (@) { #{{{
$IkiWiki::pagectime{$page}=$time if defined $time;
}
}
+ 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;
+ }
+
+ # Metadata collection that happens only during preprocessing pass.
+ if ($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;
@@ -113,14 +144,6 @@ sub preprocess (@) { #{{{
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;
@@ -160,17 +183,17 @@ sub preprocess (@) { #{{{
push @{$meta{$page}}, $redir;
}
elsif ($key eq 'link') {
- return "[[meta ".gettext("link is no longer supported")."]]";
+ if (%params) {
+ $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 "";
@@ -197,15 +220,6 @@ sub pagetemplate (@) { #{{{
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} ||