]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/postal.pm
don't try to use title as page name
[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 = $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=$page . "/" . $subpage_name;
52     add_depends($params{page},$comment_page);
55     my $about_link=undef;
56     my $about_page=bestlink($page,"about_comments");
58     if ($about_page){
59         $about_link=htmllink($page,$destpage,$about_page,
60                                linktext=>gettext("About Comments"));
61     }   
62     
63     my $comment_link=undef;
64 #    debug("pagesources{$comment_page}=$pagesources{$comment_page}\n");
65     if (exists $pagesources{$comment_page}){
66 #       debug("looking for htmlink $page $destpage $comment_page\n");
67         $comment_link=htmllink($page,$destpage,$comment_page,
68                                linktext=>gettext("Read Comments"));
69     }
71     $template->param(POSTAL_DIV=>1,
72                      POSTAL_PREFIX=>$config{postal_prefix},
73                      POSTAL_KEY=>$key,
74                      POSTAL_HOST=>$config{postal_host},
75                      defined($about_link) ? (POSTAL_ABOUT_LINK=>$about_link):(),
76                      defined($comment_link) ? (POSTAL_COMMENT_LINK=>$comment_link) :());
77 }
80 1;