diff options
author | Jonas Smedegaard <dr@jones.dk> | 2008-09-30 22:07:22 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2008-09-30 22:07:22 +0200 |
commit | 41a450af8bbe3b9e7238097791db0ab7fa0c15fd (patch) | |
tree | 9deb58db702e6043993ed529e612e4dcfabd889b /perl/IkiWiki/Plugin/farbar.pm | |
parent | fd50465827ce9951ea494f850d38c826f1503a75 (diff) | |
parent | 366929d83dc8b9a6620d49c4a8b96c16cf2de8a0 (diff) |
Merge branch 'wian' into allinone-da
Diffstat (limited to 'perl/IkiWiki/Plugin/farbar.pm')
-rw-r--r-- | perl/IkiWiki/Plugin/farbar.pm | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/perl/IkiWiki/Plugin/farbar.pm b/perl/IkiWiki/Plugin/farbar.pm new file mode 100644 index 0000000..ab4390a --- /dev/null +++ b/perl/IkiWiki/Plugin/farbar.pm @@ -0,0 +1,53 @@ +#!/usr/bin/perl +# Farbar plugin. +# by Jonas Smedegaard <dr@jones.dk> +# Heavily based on Sidebar by Tuomo Valkonen <tuomov at iki dot fi> + +package IkiWiki::Plugin::farbar; + +use warnings; +use strict; +use IkiWiki 2.00; + +sub import { #{{{ + hook(type => "pagetemplate", id => "farbar", call => \&pagetemplate); +} # }}} + +sub farbar_content ($) { #{{{ + my $page=shift; + + my $farbar_page=bestlink($page, "farbar") || return; + my $farbar_file=$pagesources{$farbar_page} || return; + my $farbar_type=pagetype($farbar_file); + + if (defined $farbar_type) { + # FIXME: This isn't quite right; it won't take into account + # adding a new farbar page. So adding such a page + # currently requires a wiki rebuild. + add_depends($page, $farbar_page); + + my $content=readfile(srcfile($farbar_file)); + return unless length $content; + return IkiWiki::htmlize($farbar_page, $page, $farbar_type, + IkiWiki::linkify($farbar_page, $page, + IkiWiki::preprocess($farbar_page, $page, + IkiWiki::filter($farbar_page, $page, $content)))); + } + +} # }}} + +sub pagetemplate (@) { #{{{ + my %params=@_; + + my $page=$params{page}; + my $template=$params{template}; + + if ($template->query(name => "farbar")) { + my $content=farbar_content($page); + if (defined $content && length $content) { + $template->param(farbar => $content); + } + } +} # }}} + +1 |