]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
Merge commit 'smcv/comments'
authorJoey Hess <joey@gnu.kitenet.net>
Sun, 21 Dec 2008 17:50:30 +0000 (12:50 -0500)
committerJoey Hess <joey@gnu.kitenet.net>
Sun, 21 Dec 2008 17:50:30 +0000 (12:50 -0500)
IkiWiki.pm
IkiWiki/Plugin/comments.pm
t/beautify_urlpath.t [new file with mode: 0755]
templates/atomitem.tmpl
templates/rssitem.tmpl

index 47116089bdac0f66b15bb02fbcd8f3410e42d41b..6747a3ba45b7bf11bfec18319f85c7963a82c7c9 100644 (file)
@@ -949,16 +949,16 @@ sub formattime ($;$) {
 sub beautify_urlpath ($) {
        my $url=shift;
 
-       if ($config{usedirs}) {
-               $url =~ s!/index.$config{htmlext}$!/!;
-       }
-
        # Ensure url is not an empty link, and if necessary,
        # add ./ to avoid colon confusion.
-       if ($url !~ /^\// && $url !~ /^\.\.\//) {
+       if ($url !~ /^\// && $url !~ /^\.\.?\//) {
                $url="./$url";
        }
 
+       if ($config{usedirs}) {
+               $url =~ s!/index.$config{htmlext}$!/!;
+       }
+
        return $url;
 }
 
index 644ef1be8ceec33a7185ff8dd3492962bdabe9d6..0ae9eefe320f2b634781375b8c57927844a8d2cc 100644 (file)
@@ -432,8 +432,8 @@ sub sessioncgi ($$) {
 
        if ($form->submitted eq PREVIEW) {
                my $preview = IkiWiki::htmlize($location, $page, '_comment',
-                               IkiWiki::linkify($page, $page,
-                                       IkiWiki::preprocess($page, $page,
+                               IkiWiki::linkify($location, $page,
+                                       IkiWiki::preprocess($location, $page,
                                                IkiWiki::filter($location,
                                                        $page, $content),
                                                0, 1)));
@@ -447,6 +447,12 @@ sub sessioncgi ($$) {
                $template->param(title => $form->field('subject'));
                $template->param(ctime => displaytime(time));
 
+               IkiWiki::run_hooks(pagetemplate => sub {
+                       shift->(page => $location,
+                               destpage => $page,
+                               template => $template);
+               });
+
                $form->tmpl_param(page_preview => $template->output);
        }
        else {
@@ -525,6 +531,8 @@ sub pagetemplate (@) {
        my $page = $params{page};
        my $template = $params{template};
        my $shown = ($template->query(name => 'commentslink') ||
+                    $template->query(name => 'commentsurl') ||
+                    $template->query(name => 'atomcommentsurl') ||
                     $template->query(name => 'comments')) &&
                    commentsshown($page);
 
@@ -554,6 +562,22 @@ sub pagetemplate (@) {
                }
        }
 
+       if ($template->query(name => 'commentsurl')) {
+               if ($shown) {
+                       $template->param(commentsurl =>
+                               urlto($page, undef, 1).'#comments');
+               }
+       }
+
+       if ($template->query(name => 'atomcommentsurl') && $config{usedirs}) {
+               if ($shown) {
+                       # This will 404 until there are some comments, but I
+                       # think that's probably OK...
+                       $template->param(atomcommentsurl =>
+                               urlto($page, undef, 1).'comments.atom');
+               }
+       }
+
        if ($template->query(name => 'commentslink')) {
                # XXX Would be nice to say how many comments there are in
                # the link. But, to update the number, blog pages
diff --git a/t/beautify_urlpath.t b/t/beautify_urlpath.t
new file mode 100755 (executable)
index 0000000..b9d3493
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use Test::More tests => 7;
+
+BEGIN { use_ok("IkiWiki"); }
+
+$IkiWiki::config{usedirs} = 1;
+$IkiWiki::config{htmlext} = "HTML";
+is(IkiWiki::beautify_urlpath("foo/bar"), "./foo/bar");
+is(IkiWiki::beautify_urlpath("../badger"), "../badger");
+is(IkiWiki::beautify_urlpath("./bleh"), "./bleh");
+is(IkiWiki::beautify_urlpath("foo/index.HTML"), "./foo/");
+is(IkiWiki::beautify_urlpath("index.HTML"), "./");
+$IkiWiki::config{usedirs} = 0;
+is(IkiWiki::beautify_urlpath("foo/index.HTML"), "./foo/index.HTML");
index 1ff7f4f4eff5a2a4e4e1ce3d989faaad8401d1b6..768695a2ca0d434e376cdf1b1de7325376b5aa49 100644 (file)
          <TMPL_VAR CONTENT ESCAPE=HTML>
         </content>
        </TMPL_IF>
+       <TMPL_IF NAME="COMMENTSURL">
+       <link rel="comments" href="<TMPL_VAR NAME="COMMENTSURL">" type="text/html" />
+       </TMPL_IF>
+       <TMPL_IF NAME="ATOMCOMMENTSURL">
+       <link rel="comments" href="<TMPL_VAR NAME="ATOMCOMMENTSURL">" type="application/atom+xml" />
+       </TMPL_IF>
 </entry>
index 42936a668f591bf7cf1a9a23fae4e076e3e48988..a61b92b6127505e3f61b068d046e3f706a956d9a 100644 (file)
@@ -23,4 +23,7 @@
        <TMPL_ELSE>
        <description><TMPL_VAR CONTENT ESCAPE=HTML></description>
        </TMPL_IF>
+       <TMPL_IF NAME="COMMENTSURL">
+       <comments><TMPL_VAR NAME="COMMENTSURL"></comments>
+       </TMPL_IF>
 </item>