use warnings;
use strict;
use Encode;
-use IkiWiki 2.00;
+use IkiWiki 3.00;
use URI;
my %knownfeeds;
call => \&IkiWiki::preprocess_inline);
hook(type => "pagetemplate", id => "inline",
call => \&IkiWiki::pagetemplate_inline);
- hook(type => "format", id => "inline", call => \&format);
+ hook(type => "format", id => "inline", call => \&format, first => 1);
# Hook to change to do pinging since it's called late.
# This ensures each page only pings once and prevents slow
# pings interrupting page builds.
sub preprocess_inline (@) {
my %params=@_;
- if (! exists $params{pages}) {
+ if (! exists $params{pages} && ! exists $params{pagenames}) {
error gettext("missing pages parameter");
}
my $raw=yesno($params{raw});
}
my @list;
- foreach my $page (keys %pagesources) {
- next if $page eq $params{page};
- if (pagespec_match($page, $params{pages}, location => $params{page})) {
- push @list, $page;
+
+ if (exists $params{pagenames}) {
+ foreach my $p (qw(sort pages)) {
+ if (exists $params{$p}) {
+ error sprintf(gettext("the %s and %s parameters cannot be used together"),
+ "pagenames", $p);
+ }
}
- }
- if (exists $params{sort} && $params{sort} eq 'title') {
- @list=sort { pagetitle(basename($a)) cmp pagetitle(basename($b)) } @list;
- }
- elsif (exists $params{sort} && $params{sort} eq 'mtime') {
- @list=sort { $pagemtime{$b} <=> $pagemtime{$a} } @list;
- }
- elsif (! exists $params{sort} || $params{sort} eq 'age') {
- @list=sort { $pagectime{$b} <=> $pagectime{$a} } @list;
+ @list = map { bestlink($params{page}, $_) }
+ split ' ', $params{pagenames};
+
+ if (yesno($params{reverse})) {
+ @list=reverse(@list);
+ }
+
+ foreach my $p (@list) {
+ add_depends($params{page}, $p, deptype($quick ? "presence" : "content"));
+ }
}
else {
- error sprintf(gettext("unknown sort type %s"), $params{sort});
- }
+ my $num=0;
+ if ($params{show}) {
+ $num=$params{show};
+ }
+ if ($params{feedshow} && $num < $params{feedshow}) {
+ $num=$params{feedshow};
+ }
+ if ($params{skip}) {
+ $num+=$params{skip};
+ }
- if (yesno($params{reverse})) {
- @list=reverse(@list);
+ @list = pagespec_match_list($params{page}, $params{pages},
+ deptype => deptype($quick ? "presence" : "content"),
+ filter => sub { $_[0] eq $params{page} },
+ sort => exists $params{sort} ? $params{sort} : "age",
+ reverse => yesno($params{reverse}),
+ num => $num,
+ );
}
if (exists $params{skip}) {
- @list=@list[$params{skip} .. scalar @list - 1];
+ @list=@list[$params{skip} .. $#list];
}
my @feedlist;
@list=@list[0..$params{show} - 1];
}
- add_depends($params{page}, $params{pages});
- # Explicitly add all currently displayed pages as dependencies, so
- # that if they are removed or otherwise changed, the inline will be
- # sure to be updated.
- add_depends($params{page}, join(" or ", $#list >= $#feedlist ? @list : @feedlist));
-
if ($feeds && exists $params{feedpages}) {
- @feedlist=grep { pagespec_match($_, $params{feedpages}, location => $params{page}) } @feedlist;
+ @feedlist = pagespec_match_list(
+ $params{page}, "($params{pages}) and ($params{feedpages})",
+ deptype => deptype($quick ? "presence" : "content"),
+ list => \@feedlist,
+ );
}
my ($feedbase, $feednum);
}
}
- my $rssurl=basename($feedbase."rss".$feednum) if $feeds && $rss;
- my $atomurl=basename($feedbase."atom".$feednum) if $feeds && $atom;
+ my $rssurl=abs2rel($feedbase."rss".$feednum, dirname(htmlpage($params{destpage}))) if $feeds && $rss;
+ my $atomurl=abs2rel($feedbase."atom".$feednum, dirname(htmlpage($params{destpage}))) if $feeds && $atom;
my $ret="";
# Add a blog post form, with feed buttons.
my $formtemplate=template("blogpost.tmpl", blind_cache => 1);
$formtemplate->param(cgiurl => $config{cgiurl});
- my $rootpage;
- if (exists $params{rootpage}) {
- $rootpage=bestlink($params{page}, $params{rootpage});
- if (!length $rootpage) {
- $rootpage=$params{rootpage};
- }
- }
- else {
- $rootpage=$params{page};
- }
- $formtemplate->param(rootpage => $rootpage);
+ $formtemplate->param(rootpage => rootpage(%params));
$formtemplate->param(rssurl => $rssurl) if $feeds && $rss;
$formtemplate->param(atomurl => $atomurl) if $feeds && $atom;
if (exists $params{postformtext}) {
my $content=get_inline_content($page, $params{destpage});
$template->param(content => $content);
}
- $template->param(pageurl => urlto(bestlink($params{page}, $page), $params{destpage}));
+ $template->param(pageurl => urlto($page, $params{destpage}));
+ $template->param(inlinepage => $page);
$template->param(title => pagetitle(basename($page)));
$template->param(ctime => displaytime($pagectime{$page}, $params{timeformat}));
$template->param(mtime => displaytime($pagemtime{$page}, $params{timeformat}));
my $file = $pagesources{$page};
my $type = pagetype($file);
if ($config{discussion}) {
- my $discussionlink=gettext("discussion");
- if ($page !~ /.*\/\Q$discussionlink\E$/ &&
+ if ($page !~ /.*\/\Q$config{discussionpage}\E$/ &&
(length $config{cgiurl} ||
- exists $links{$page."/".$discussionlink})) {
+ exists $links{$page."/".$config{discussionpage}})) {
$template->param(have_actions => 1);
$template->param(discussionlink =>
htmllink($page,
$params{destpage},
- gettext("Discussion"),
+ $config{discussionpage},
noimageinline => 1,
forcesubpage => 1));
}
mdate_3339 => date_3339($pagemtime{$p}),
);
- if (exists $pagestate{$p} &&
- exists $pagestate{$p}{meta}{guid}) {
- $itemtemplate->param(guid => $pagestate{$p}{meta}{guid});
+ if (exists $pagestate{$p}) {
+ if (exists $pagestate{$p}{meta}{guid}) {
+ $itemtemplate->param(guid => $pagestate{$p}{meta}{guid});
+ }
+
+ if (exists $pagestate{$p}{meta}{updated}) {
+ $itemtemplate->param(mdate_822 => date_822($pagestate{$p}{meta}{updated}));
+ $itemtemplate->param(mdate_3339 => date_3339($pagestate{$p}{meta}{updated}));
+ }
}
if ($itemtemplate->query(name => "enclosure")) {
exit 0; # daemon done
}
+
+sub rootpage (@) {
+ my %params=@_;
+
+ my $rootpage;
+ if (exists $params{rootpage}) {
+ $rootpage=bestlink($params{page}, $params{rootpage});
+ if (!length $rootpage) {
+ $rootpage=$params{rootpage};
+ }
+ }
+ else {
+ $rootpage=$params{page};
+ }
+ return $rootpage;
+}
+
1