]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/postal.pm
borrow some glue from ::attachment
[git.ikiwiki.info.git] / IkiWiki / Plugin / postal.pm
1 # A plugin for ikiwiki to implement adding a footer with a comment URL
2 # based on a template file and a key representing the current page
4 # Copyright © 2007 Thomas Schwinge <tschwinge@gnu.org>
5 # Copyright © 2008 David Bremner <tschwinge@gnu.org>
6 #
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 2, or (at your option) any later
10 # version.
11
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 # for more details.
16
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 \f
21 # A footer with comment information will be added to every rendered page
22 # a file `comments.html' or 'comments.mdwn' is found (using the
23 # same rules as for the sidebar plugin).
25 # You'll need a full wiki-rebuild if your comment header file is changed.
26 #
27 # You can use wiki links in `comments.html'.
28 \f
29 package IkiWiki::Plugin::postal;
31 use warnings;
32 use strict;
33 use IkiWiki 2.00;
34 use Convert::YText 'encode_ytext';
36 \f
37 sub import
38 {
39     hook (type => "pagetemplate", id => "postal", call => \&pagetemplate);
40 }
42 sub pagetemplate (@)
43 {
44     my %params = @_;
45     my $page = IkiWiki::pagetitle($params{page});
46     my $destpage = $params{destpage};
48     my $template = $params{template};
50     if ($template->query (name => "comments") &&
51         ! defined $template->param ('comments'))
52     {
53         debug("adding comments to ".$page);
54         my $key = encode_ytext($page);
55         debug("using key ".$key);
58         my $content;
59         my $comment_page = bestlink ($page, "comments") || return;
60         my $comment_file = $pagesources{$comment_page} || return;
62         $content = readfile (srcfile ($comment_file));
63         if (defined $content && length $content)
64         {
65             $content =~ s/%%KEY%%/$key/g;
66             $content =~ s/%%PAGE%%/$page/g;
68             debug("comment blurb: ". $content);
70             $template->param (comments =>
71                               IkiWiki::linkify ($page, $destpage, $content)) 
72         }
73     }
74 }
77 1;