]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/postal.pm
add pagespec
[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 <bremner@unb.ca>
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 package IkiWiki::Plugin::postal;
23 use warnings;
24 use strict;
25 use IkiWiki 2.00;
26 use Convert::YText 'encode_ytext';
28 \f
29 sub import
30 {
31     hook (type => "pagetemplate", id => "postal", call => \&pagetemplate);
32 }
34 sub pagetemplate (@)
35 {
36     my %params = @_;
37     my $page = IkiWiki::pagetitle($params{page});
38     my $destpage = $params{destpage};
39     my $template = $params{template};
41     my $key = encode_ytext($page);
43     my $pagespec=$config{postal_pagespec} || "!*/comments";
45     if (!pagespec_match($page,$pagespec)){
46         return;
47     }
49     my $subpage_name=$config{postal_pagename} || "comments";
51     my $comment_page=$destpage . "/" . $subpage_name;
53     my $comment_link=undef;
54     if (exists $pagesources{$comment_page}){
55         $comment_link=htmllink($page,$destpage,$comment_page,
56                                linktext=>gettext("Read Comments"));
57     }
59     debug("comment_link=".$comment_link) if (defined($comment_link));
61     $template->param(POSTAL_DIV=>1,
62                      POSTAL_PREFIX=>$config{postal_prefix},
63                      POSTAL_KEY=>$key,
64                      POSTAL_HOST=>$config{postal_host},
65                      defined($comment_link) ? (POSTAL_COMMENT_LINK=>$comment_link) :());
66 }
69 1;