summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/inline.pm2
-rw-r--r--IkiWiki/Plugin/meta.pm61
-rw-r--r--IkiWiki/Render.pm28
3 files changed, 79 insertions, 12 deletions
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index 6ecdf0d38..b22109a93 100644
--- a/IkiWiki/Plugin/inline.pm
+++ b/IkiWiki/Plugin/inline.pm
@@ -100,7 +100,7 @@ sub get_inline_content ($$) { #{{{
my $file=$pagesources{$page};
my $type=pagetype($file);
if ($type ne 'unknown') {
- return htmlize($type, linkify($page, $parentpage, readfile(srcfile($file))));
+ return htmlize($type, preprocess($page, linkify($page, $parentpage, readfile(srcfile($file))), 1));
}
else {
return "";
diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
new file mode 100644
index 000000000..8244cf718
--- /dev/null
+++ b/IkiWiki/Plugin/meta.pm
@@ -0,0 +1,61 @@
+#!/usr/bin/perl
+# Ikiwiki metadata plugin.
+package IkiWiki::Plugin::meta;
+
+use warnings;
+use strict;
+use IkiWiki;
+
+my %meta;
+my %title;
+
+sub import { #{{{
+ IkiWiki::hook(type => "preprocess", id => "meta",
+ call => \&preprocess);
+ IkiWiki::hook(type => "pagetemplate", id => "meta",
+ call => \&pagetemplate);
+} # }}}
+
+sub preprocess (@) { #{{{
+ if (! @_) {
+ return "";
+ }
+ my %params=@_;
+ my $key=shift;
+ my $value=$params{$key};
+ delete $params{$key};
+ my $page=$params{page};
+ delete $params{page};
+
+ if ($key eq 'link') {
+ if (%params) {
+ $meta{$page}='' unless exists $meta{$page};
+ $meta{$page}.="<link href=\"$value\" ".
+ join(" ", map { "$_=\"$params{$_}\"" } keys %params).
+ " />\n";
+ }
+ else {
+ # hidden WikiLink
+ push @{$IkiWiki::links{$page}}, $value;
+ }
+ }
+ elsif ($key eq 'title') {
+ $title{$page}=$value;
+ }
+ else {
+ $meta{$page}='' unless exists $meta{$page};
+ $meta{$page}.="<meta name=\"$key\" content=\"$value\" />\n";
+ }
+
+ return "";
+} # }}}
+
+sub pagetemplate ($$) { #{{{
+ my $page=shift;
+ my $template=shift;
+
+ $template->param(meta => $meta{$page}) if exists $meta{$page};
+ $template->param(title => $title{$page}) if exists $title{$page};
+} # }}}
+
+1
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index 886a30f6b..0dfa03cd4 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -95,9 +95,10 @@ sub parentlinks ($) { #{{{
return @ret;
} #}}}
-sub preprocess ($$) { #{{{
+sub preprocess ($$;$) { #{{{
my $page=shift;
my $content=shift;
+ my $onlystrip=shift || 0; # strip directives without processing
my $handle=sub {
my $escape=shift;
@@ -106,12 +107,17 @@ sub preprocess ($$) { #{{{
if (length $escape) {
return "[[$command $params]]";
}
+ elsif ($onlystrip) {
+ return "";
+ }
elsif (exists $hooks{preprocess}{$command}) {
- my %params;
- while ($params =~ /(\w+)=\"([^"]+)"(\s+|$)/g) {
- $params{$1}=$2;
+ # Note: preserve order of params, some plugins may
+ # consider it significant.
+ my @params;
+ while ($params =~ /(\w+)=\"?([^"]+)"?(\s+|$)/g) {
+ push @params, $1, $2;
}
- return $hooks{preprocess}{$command}{call}->(page => $page, %params);
+ return $hooks{preprocess}{$command}{call}->(@params, page => $page);
}
else {
return "[[$command not processed]]";
@@ -190,12 +196,6 @@ sub genpage ($$$) { #{{{
$template->param(have_actions => 1);
}
- if (exists $hooks{pagetemplate}) {
- foreach my $id (keys %{$hooks{pagetemplate}}) {
- $hooks{pagetemplate}{$id}{call}->($page, $template);
- }
- }
-
$template->param(
title => $title,
wikiname => $config{wikiname},
@@ -205,6 +205,12 @@ sub genpage ($$$) { #{{{
mtime => displaytime($mtime),
styleurl => styleurl($page),
);
+
+ if (exists $hooks{pagetemplate}) {
+ foreach my $id (keys %{$hooks{pagetemplate}}) {
+ $hooks{pagetemplate}{$id}{call}->($page, $template);
+ }
+ }
return $template->output;
} #}}}