bavbavhaus.net/IkiWiki/Plugin/inlinepages.pm

75 lines
1.7 KiB
Perl

#!/usr/bin/perl
package IkiWiki::Plugin::inlinepages;
use warnings;
use strict;
use IkiWiki 3.00;
my @inlinepages;
sub import {
hook(type => "preprocess", id => "inlinepages", call => \&preprocess);
hook(type => "pagetemplate", id => "inlinepages", call => \&pagetemplate);
}
sub preprocess (@) {
my %params=@_;
if (! exists $params{pages}) {
error gettext("missing pages parameter");
}
my $quick=exists $params{quick} ? IkiWiki::yesno($params{quick}) : 0;
my $num=0;
if ($params{limit}) {
$num=$params{limit};
}
if ($params{feedlimit} && $num < $params{feedlimit} && $num > 0) {
$num=$params{feedlimit};
}
if ($params{skip} && $num) {
$num+=$params{skip};
}
@inlinepages=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 title",
reverse => IkiWiki::yesno($params{reverse}),
($num ? (num => $num) : ()),
);
return "";
}
sub pagetemplate (@) {
my %params=@_;
my $template=$params{template};
my $destpage=$params{destpage};
if (! $template->query(name => "inlinepages")) {
return;
}
my @contents;
for (@inlinepages) {
if ($pagesources{$_}) {
my $title = $pagestate{$_}{meta}{title};
push @contents, {
content => IkiWiki::get_inline_content($_, $destpage),
pageurl => urlto($_, $destpage),
title => $title ? $title : pagetitle(IkiWiki::basename($_)),
ctime => displaytime($IkiWiki::pagectime{$_}, $params{timeformat}, 1),
mtime => displaytime($IkiWiki::pagemtime{$_}, $params{timeformat})
}
}
}
$template->param(inlinepages => \@contents);
}
1