From a999458df6e5999e29abb053488ca074e196fd04 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Fri, 20 Jun 2008 08:40:17 +0200 Subject: [PATCH] unconditional adding of template. Needs digest computation --- IkiWiki/Plugin/postal.pm | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 IkiWiki/Plugin/postal.pm diff --git a/IkiWiki/Plugin/postal.pm b/IkiWiki/Plugin/postal.pm new file mode 100644 index 000000000..e5915afe8 --- /dev/null +++ b/IkiWiki/Plugin/postal.pm @@ -0,0 +1,68 @@ +# A plugin for ikiwiki to implement adding a footer with a comment URL +# based on a template file and a key representing the current page + +# Copyright © 2007 Thomas Schwinge +# Copyright © 2008 David Bremner +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# A footer with comment information will be added to every rendered page +# a file `comments.html' or 'comments.mdwn' is found (using the +# same rules as for the sidebar plugin). + +# You'll need a full wiki-rebuild if your comment header file is changed. +# +# You can use wiki links in `comments.html'. + +package IkiWiki::Plugin::postal; + +use warnings; +use strict; +use IkiWiki 2.00; + +sub import +{ + hook (type => "pagetemplate", id => "postal", call => \&pagetemplate); +} + +sub pagetemplate (@) +{ + my %params = @_; + my $page = $params{page}; + my $destpage = $params{destpage}; + + my $template = $params{template}; + + if ($template->query (name => "comments") && + ! defined $template->param ('comments')) + { + debug('got template'); + my $content; + my $comment_page = bestlink ($page, "comments") || return; + my $comment_file = $pagesources{$comment_page} || return; + #my $pagetype = pagetype ($comment_file); + # Check if ``$pagetype eq 'html'''? + $content = readfile (srcfile ($comment_file)); + + if (defined $content && length $content) + { + debug('got comment file'); + $template->param (comments => + IkiWiki::linkify ($page, $destpage, $content)) + } + } +} + +1 -- 2.26.2