summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r--IkiWiki/Plugin/footer.pm110
1 files changed, 110 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/footer.pm b/IkiWiki/Plugin/footer.pm
new file mode 100644
index 0000000..b4d7b50
--- /dev/null
+++ b/IkiWiki/Plugin/footer.pm
@@ -0,0 +1,110 @@
+#!/usr/bin/perl
+# Footer plugin.
+# by Jonas Smedegaard <dr@jones.dk>
+# Heavily based on Sidebar by Tuomo Valkonen <tuomov at iki dot fi>
+
+package IkiWiki::Plugin::footer;
+
+use warnings;
+use strict;
+use IkiWiki 3.00;
+
+sub import {
+ hook(type => "getsetup", id => "footer", call => \&getsetup);
+ hook(type => "preprocess", id => "footer", call => \&preprocess);
+ hook(type => "pagetemplate", id => "footer", call => \&pagetemplate);
+}
+
+sub getsetup () {
+ return
+ plugin => {
+ safe => 1,
+ rebuild => 1,
+ },
+ global_footers => {
+ type => "boolean",
+ example => 1,
+ description => "show footer page on all pages?",
+ safe => 1,
+ rebuild => 1,
+ },
+}
+
+my %pagefooter;
+
+sub preprocess (@) {
+ my %params=@_;
+
+ my $page=$params{page};
+ return "" unless $page eq $params{destpage};
+
+ if (! defined $params{content}) {
+ $pagefooter{$page}=undef;
+ }
+ else {
+ my $file = $pagesources{$page};
+ my $type = pagetype($file);
+
+ $pagefooter{$page}=
+ IkiWiki::htmlize($page, $page, $type,
+ IkiWiki::linkify($page, $page,
+ IkiWiki::preprocess($page, $page, $params{content})));
+ }
+
+ return "";
+}
+
+my $oldfile;
+my $oldcontent;
+
+sub footer_content ($) {
+ my $page=shift;
+
+ return delete $pagefooter{$page} if defined $pagefooter{$page};
+
+ return if ! exists $pagefooter{$page} &&
+ defined $config{global_footers} && ! $config{global_footers};
+
+ my $footer_page=bestlink($page, "footer") || return;
+ my $footer_file=$pagesources{$footer_page} || return;
+ my $footer_type=pagetype($footer_file);
+
+ if (defined $footer_type) {
+ # FIXME: This isn't quite right; it won't take into account
+ # adding a new footer page. So adding such a page
+ # currently requires a wiki rebuild.
+ add_depends($page, $footer_page);
+
+ my $content;
+ if (defined $oldfile && $footer_file eq $oldfile) {
+ $content=$oldcontent;
+ }
+ else {
+ $content=readfile(srcfile($footer_file));
+ $oldcontent=$content;
+ $oldfile=$footer_file;
+ }
+
+ return unless length $content;
+ return IkiWiki::htmlize($footer_page, $page, $footer_type,
+ IkiWiki::linkify($footer_page, $page,
+ IkiWiki::preprocess($footer_page, $page,
+ IkiWiki::filter($footer_page, $page, $content))));
+ }
+
+}
+
+sub pagetemplate (@) {
+ my %params=@_;
+
+ my $template=$params{template};
+ if ($params{destpage} eq $params{page} &&
+ $template->query(name => "footer")) {
+ my $content=footer_content($params{destpage});
+ if (defined $content && length $content) {
+ $template->param(footer => $content);
+ }
+ }
+}
+
+1