pagespec_match_list: change limit to filter

master
Joey Hess 2009-10-09 13:20:41 -04:00
parent f9f7a6e9f3
commit 6f2cc5ac8c
5 changed files with 12 additions and 12 deletions

View File

@ -1986,8 +1986,8 @@ sub pagespec_match_list ($$;@) {
if $@ || ! defined $sub;
my @candidates;
if (exists $params{limit}) {
@candidates=grep { $params{limit}->($_) } keys %pagesources;
if (exists $params{filter}) {
@candidates=grep { ! $params{filter}->($_) } keys %pagesources;
}
else {
@candidates=keys %pagesources;
@ -2023,7 +2023,7 @@ sub pagespec_match_list ($$;@) {
# clear params, remainder is passed to pagespec
my $num=$params{num};
delete @params{qw{num deptype reverse sort limit}};
delete @params{qw{num deptype reverse sort filter}};
my @matches;
my $firstfail;

View File

@ -218,7 +218,7 @@ sub preprocess_inline (@) {
@list = pagespec_match_list($params{page}, $params{pages},
deptype => deptype($quick ? "presence" : "content"),
limit => sub { $_[0] ne $params{page} },
filter => sub { $_[0] eq $params{page} },
sort => exists $params{sort} ? $params{sort} : "age",
reverse => yesno($params{reverse}),
num => $num,

View File

@ -31,24 +31,24 @@ sub preprocess (@) {
my @orphans=pagespec_match_list($params{page}, $params{pages},
# update when orphans are added/removed
deptype => deptype("presence"),
limit => sub {
filter => sub {
my $page=shift;
# Filter out pages that other pages link to.
return 0 if IkiWiki::backlink_pages($page);
return 1 if IkiWiki::backlink_pages($page);
# Toplevel index is assumed to never be orphaned.
return 0 if $page eq 'index';
return 1 if $page eq 'index';
# If the page has a link to some other page, it's
# indirectly linked via that page's backlinks.
return 0 if grep {
return 1 if grep {
length $_ &&
($_ !~ /\/\Q$config{discussionpage}\E$/i || ! $config{discussion}) &&
bestlink($page, $_) !~ /^(\Q$page\E|)$/
} @{$links{$page}};
return 1;
return 0;
},
);

View File

@ -56,7 +56,7 @@ sub preprocess (@) {
my @list=sort { $params{timehash}->{$b} <=> $params{timehash}->{$a} }
pagespec_match_list($params{page}, $params{pages},
deptype => $deptype,
limit => sub { $_[0] ne $params{page} },
filter => sub { $_[0] eq $params{page} },
);
my @data=eval qq{IkiWiki::Plugin::postsparkline::formula::$formula(\\\%params, \@list)};

View File

@ -643,8 +643,8 @@ Additional named parameters can be specified:
* `deptype` optionally specifies the type of dependency to add. Use the
`deptype` function to generate a dependency type.
* `limit` is a reference to a function, that is called and passed a page,
and must return true for the page to be included.
* `filter` is a reference to a function, that is called and passed a page,
and returns true if the page should be filtered out of the list.
* `sort` specifies a sort order for the list. See
[[ikiwiki/PageSpec/sorting]] for the avilable sort methods.
* `reverse` if true, sorts in reverse.