]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/postal.pm
add pagespec
[git.ikiwiki.info.git] / IkiWiki / Plugin / postal.pm
index 9f3f231cbd201be1572f23d206cc399e59e80c18..f9fc955e7dc50339dbbc06a89b1c444b3a176074 100644 (file)
 # 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;
@@ -44,34 +36,33 @@ sub pagetemplate (@)
     my %params = @_;
     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 = encode_ytext($page);
-       debug("using key ".$key);
+    my $key = encode_ytext($page);
+
+    my $pagespec=$config{postal_pagespec} || "!*/comments";
+
+    if (!pagespec_match($page,$pagespec)){
+       return;
+    }
 
+    my $subpage_name=$config{postal_pagename} || "comments";
 
-       my $content;
-       my $comment_page = bestlink ($page, "_comments") || return;
-       my $comment_file = $pagesources{$comment_page} || return;
+    my $comment_page=$destpage . "/" . $subpage_name;
 
-       $content = readfile (srcfile ($comment_file));
-       if (defined $content && length $content)
-       {
-           $content =~ s/%%KEY%%/$key/g;
-           $content =~ s/%%PAGE%%/$page/g;
+    my $comment_link=undef;
+    if (exists $pagesources{$comment_page}){
+       $comment_link=htmllink($page,$destpage,$comment_page,
+                              linktext=>gettext("Read Comments"));
+    }
 
-           debug("comment blurb: ". $content);
+    debug("comment_link=".$comment_link) if (defined($comment_link));
 
-    $template->param(POSTAL_COMMENTS=>1,
+    $template->param(POSTAL_DIV=>1,
                     POSTAL_PREFIX=>$config{postal_prefix},
                     POSTAL_KEY=>$key,
                     POSTAL_HOST=>$config{postal_host},
-                    POSTAL_COMMENT_LINK=>$comment_link );
+                    defined($comment_link) ? (POSTAL_COMMENT_LINK=>$comment_link) :());
 }