From b1daba6e9b0201d55926f8590035989df016e947 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Wed, 6 Aug 2008 00:55:29 +0200 Subject: clone plugin sidebar as branding, farbar, footer, and topbar [2/2] --- IkiWiki/Plugin/footer.pm | 63 ++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 31 deletions(-) (limited to 'IkiWiki/Plugin/footer.pm') diff --git a/IkiWiki/Plugin/footer.pm b/IkiWiki/Plugin/footer.pm index c1146b7..af3f158 100644 --- a/IkiWiki/Plugin/footer.pm +++ b/IkiWiki/Plugin/footer.pm @@ -1,17 +1,18 @@ #!/usr/bin/perl -# Sidebar plugin. -# by Tuomo Valkonen +# Footer plugin. +# by Jonas Smedegaard +# Heavily based on Sidebar by Tuomo Valkonen -package IkiWiki::Plugin::sidebar; +package IkiWiki::Plugin::footer; use warnings; use strict; use IkiWiki 3.00; sub import { - hook(type => "getsetup", id => "sidebar", call => \&getsetup); - hook(type => "preprocess", id => "sidebar", call => \&preprocess); - hook(type => "pagetemplate", id => "sidebar", call => \&pagetemplate); + hook(type => "getsetup", id => "footer", call => \&getsetup); + hook(type => "preprocess", id => "footer", call => \&preprocess); + hook(type => "pagetemplate", id => "footer", call => \&pagetemplate); } sub getsetup () { @@ -20,16 +21,16 @@ sub getsetup () { safe => 1, rebuild => 1, }, - global_sidebars => { + global_footers => { type => "boolean", example => 1, - description => "show sidebar page on all pages?", + description => "show footer page on all pages?", safe => 1, rebuild => 1, }, } -my %pagesidebar; +my %pagefooter; sub preprocess (@) { my %params=@_; @@ -38,13 +39,13 @@ sub preprocess (@) { return "" unless $page eq $params{destpage}; if (! defined $params{content}) { - $pagesidebar{$page}=undef; + $pagefooter{$page}=undef; } else { my $file = $pagesources{$page}; my $type = pagetype($file); - $pagesidebar{$page}= + $pagefooter{$page}= IkiWiki::htmlize($page, $page, $type, IkiWiki::linkify($page, $page, IkiWiki::preprocess($page, $page, $params{content}))); @@ -56,39 +57,39 @@ sub preprocess (@) { my $oldfile; my $oldcontent; -sub sidebar_content ($) { +sub footer_content ($) { my $page=shift; - return delete $pagesidebar{$page} if defined $pagesidebar{$page}; + return delete $pagefooter{$page} if defined $pagefooter{$page}; - return if ! exists $pagesidebar{$page} && - defined $config{global_sidebars} && ! $config{global_sidebars}; + return if ! exists $pagefooter{$page} && + defined $config{global_footers} && ! $config{global_footers}; - my $sidebar_page=bestlink($page, "sidebar") || return; - my $sidebar_file=$pagesources{$sidebar_page} || return; - my $sidebar_type=pagetype($sidebar_file); + my $footer_page=bestlink($page, "footer") || return; + my $footer_file=$pagesources{$footer_page} || return; + my $footer_type=pagetype($footer_file); - if (defined $sidebar_type) { + if (defined $footer_type) { # FIXME: This isn't quite right; it won't take into account - # adding a new sidebar page. So adding such a page + # adding a new footer page. So adding such a page # currently requires a wiki rebuild. - add_depends($page, $sidebar_page); + add_depends($page, $footer_page); my $content; - if (defined $oldfile && $sidebar_file eq $oldfile) { + if (defined $oldfile && $footer_file eq $oldfile) { $content=$oldcontent; } else { - $content=readfile(srcfile($sidebar_file)); + $content=readfile(srcfile($footer_file)); $oldcontent=$content; - $oldfile=$sidebar_file; + $oldfile=$footer_file; } return unless length $content; - return IkiWiki::htmlize($sidebar_page, $page, $sidebar_type, - IkiWiki::linkify($sidebar_page, $page, - IkiWiki::preprocess($sidebar_page, $page, - IkiWiki::filter($sidebar_page, $page, $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)))); } } @@ -98,10 +99,10 @@ sub pagetemplate (@) { my $template=$params{template}; if ($params{destpage} eq $params{page} && - $template->query(name => "sidebar")) { - my $content=sidebar_content($params{destpage}); + $template->query(name => "footer")) { + my $content=footer_content($params{destpage}); if (defined $content && length $content) { - $template->param(sidebar => $content); + $template->param(footer => $content); } } } -- cgit v1.2.3