summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IkiWiki.pm10
-rw-r--r--IkiWiki/Plugin/comments.pm28
-rwxr-xr-xt/beautify_urlpath.t16
-rw-r--r--templates/atomitem.tmpl6
-rw-r--r--templates/rssitem.tmpl3
5 files changed, 56 insertions, 7 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index 47116089b..6747a3ba4 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -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;
}
diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm
index 644ef1be8..0ae9eefe3 100644
--- a/IkiWiki/Plugin/comments.pm
+++ b/IkiWiki/Plugin/comments.pm
@@ -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
index 000000000..b9d3493a2
--- /dev/null
+++ b/t/beautify_urlpath.t
@@ -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");
diff --git a/templates/atomitem.tmpl b/templates/atomitem.tmpl
index 1ff7f4f4e..768695a2c 100644
--- a/templates/atomitem.tmpl
+++ b/templates/atomitem.tmpl
@@ -39,4 +39,10 @@
<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>
diff --git a/templates/rssitem.tmpl b/templates/rssitem.tmpl
index 42936a668..a61b92b61 100644
--- a/templates/rssitem.tmpl
+++ b/templates/rssitem.tmpl
@@ -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>