]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/postal.pm
add pagespec
[git.ikiwiki.info.git] / IkiWiki / Plugin / postal.pm
index 57f87914841de230c53b1c51b7456848f0db6404..f9fc955e7dc50339dbbc06a89b1c444b3a176074 100644 (file)
@@ -1,8 +1,8 @@
 # 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 <tschwinge@gnu.org>
-# Copyright © 2008 David Bremner <tschwinge@gnu.org>
+# Copyright © 2007 Thomas Schwinge <tschwinge@gnu.org>
+# Copyright © 2008 David Bremner <bremner@unb.ca>
 #
 # 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
 # with this program; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 \f
-# 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'.
-\f
 package IkiWiki::Plugin::postal;
 
 use warnings;
 use strict;
 use IkiWiki 2.00;
-use Compress::LZF ;
-use MIME::Base64::URLSafe; 
+use Convert::YText 'encode_ytext';
 
 \f
 sub import
@@ -43,35 +34,36 @@ sub import
 sub pagetemplate (@)
 {
     my %params = @_;
-    my $page = $params{page};
+    my $page = IkiWiki::pagetitle($params{page});
     my $destpage = $params{destpage};
-
     my $template = $params{template};
 
-    if ($template->query (name => "comments") &&
-       ! defined $template->param ('comments'))
-    {
-       debug("adding comments to ".$page);
-       my $key = urlsafe_b64encode(compress($page));
-       debug("using key ".$key);
+    my $key = encode_ytext($page);
+
+    my $pagespec=$config{postal_pagespec} || "!*/comments";
 
+    if (!pagespec_match($page,$pagespec)){
+       return;
+    }
 
-       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)
-       {
-           $content =~ s/%%KEY%%/$key/g;
+    my $subpage_name=$config{postal_pagename} || "comments";
 
-           debug("comment blurb: ". $content);
+    my $comment_page=$destpage . "/" . $subpage_name;
 
-           $template->param (comments =>
-             IkiWiki::linkify ($page, $destpage, $content))
-       }
+    my $comment_link=undef;
+    if (exists $pagesources{$comment_page}){
+       $comment_link=htmllink($page,$destpage,$comment_page,
+                              linktext=>gettext("Read Comments"));
     }
+
+    debug("comment_link=".$comment_link) if (defined($comment_link));
+
+    $template->param(POSTAL_DIV=>1,
+                    POSTAL_PREFIX=>$config{postal_prefix},
+                    POSTAL_KEY=>$key,
+                    POSTAL_HOST=>$config{postal_host},
+                    defined($comment_link) ? (POSTAL_COMMENT_LINK=>$comment_link) :());
 }
-\f
-1
+
+
+1;