bavbavhaus.net/IkiWiki/Plugin/backlinkpages.pm

61 lines
1.6 KiB
Perl

#!/usr/bin/perl
package IkiWiki::Plugin::backlinkpages;
use warnings;
use strict;
use IkiWiki 3.00;
sub import {
hook(type => "pagetemplate", id => "backlinkpages", call => \&pagetemplate);
}
sub pagetemplate (@) {
my %params=@_;
my $template=$params{template};
if (! $template->query(name => "backlinkpages")) {
return;
}
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};
}
my @pages = pagespec_match_list($params{page}, "backlink($params{page})",
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) : ()),
);
my $destpage=$params{destpage};
my @contents;
for (@pages) {
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(backlinkpages => \@contents);
}
1