From f0e36d348497976918bbf941c44e54888115ea3d Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sun, 17 Apr 2011 22:29:17 +0200 Subject: Add footer (clone of sidebar). --- IkiWiki/Plugin/footer.pm | 110 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 IkiWiki/Plugin/footer.pm (limited to 'IkiWiki') 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 +# Heavily based on Sidebar by Tuomo Valkonen + +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 -- cgit v1.2.3