return $needsbuild;
}
+my $scanned = 0;
+
=for wiki
The `trail` directive is supplied by the [[plugins/contrib/trail]]
sub preprocess_trail (@) {
my %params = @_;
+ # avoid collecting everything in the preprocess stage if we already
+ # did in the scan stage
+ if (defined wantarray) {
+ return "" if $scanned;
+ }
+ else {
+ $scanned = 1;
+ }
+
+ # trail members from a pagespec ought to be in some sort of order,
+ # and path is a nice obvious default
+ $params{sortthese} = 'path' unless exists $params{sortthese};
+ $params{reversethese} = 'no' unless exists $params{reversethese};
+
if (exists $params{circular}) {
$pagestate{$params{page}}{trail}{circular} =
IkiWiki::yesno($params{circular});
}
if (exists $params{pages}) {
- push @{$pagestate{$params{page}}{trail}{contents}}, "pagespec $params{pages}";
+ push @{$pagestate{$params{page}}{trail}{contents}},
+ ["pagespec" => $params{pages}, $params{sortthese},
+ IkiWiki::yesno($params{reversethese})];
}
if (exists $params{pagenames}) {
- my @list = map { "link $_" } split ' ', $params{pagenames};
+ my @list = map { [link => $_] } split ' ', $params{pagenames};
push @{$pagestate{$params{page}}{trail}{contents}}, @list;
}
=cut
sub preprocess_trailinline (@) {
- preprocess_trail(@_);
- return unless defined wantarray;
+ my %params = @_;
- if (IkiWiki->can("preprocess_inline")) {
- return IkiWiki::preprocess_inline(@_);
+ if (exists $params{sort}) {
+ $params{sortthese} = $params{sort};
+ delete $params{sort};
}
else {
- error("trailinline directive requires the inline plugin");
+ # sort in the same order as [[plugins/inline]]'s default
+ $params{sortthese} = 'age';
+ }
+
+ if (exists $params{reverse}) {
+ $params{reversethese} = $params{reverse};
+ delete $params{reverse};
+ }
+
+ if (exists $params{trailsort}) {
+ $params{sort} = $params{trailsort};
+ }
+
+ if (exists $params{trailreverse}) {
+ $params{reverse} = $params{trailreverse};
+ }
+
+ if (defined wantarray) {
+ scalar preprocess_trail(%params);
+
+ if (IkiWiki->can("preprocess_inline")) {
+ return IkiWiki::preprocess_inline(@_);
+ }
+ else {
+ error("trailinline directive requires the inline plugin");
+ }
+ }
+ else {
+ preprocess_trail(%params);
}
}
my $link = shift;
shift;
+ # avoid collecting everything in the preprocess stage if we already
+ # did in the scan stage
+ if (defined wantarray) {
+ return "" if $scanned;
+ }
+ else {
+ $scanned = 1;
+ }
+
my %params = @_;
my $trail = $params{page};
$link = linkpage($link);
add_link($params{page}, $link, 'trail');
- push @{$pagestate{$params{page}}{trail}{contents}}, "link $link";
+ push @{$pagestate{$params{page}}{trail}{contents}}, [link => $link];
return "";
}
$link = linkpage($2);
add_link($params{page}, $link, 'trail');
- push @{$pagestate{$params{page}}{trail}{contents}}, "link $link";
+
+ # avoid collecting everything in the preprocess stage if we already
+ # did in the scan stage
+ my $already;
+ if (defined wantarray) {
+ $already = $scanned;
+ }
+ else {
+ $scanned = 1;
+ }
+
+ push @{$pagestate{$params{page}}{trail}{contents}}, [link => $link] unless $already;
if (defined $linktext) {
$linktext = pagetitle($linktext);
my $members = [];
my @contents = @{$pagestate{$trail}{trail}{contents}};
-
foreach my $c (@contents) {
- if ($c =~ m/^pagespec (.*)$/) {
- push @$members, pagespec_match_list($trail, $1);
+ if ($c->[0] eq 'pagespec') {
+ push @$members, pagespec_match_list($trail,
+ $c->[1], sort => $c->[2],
+ reverse => $c->[3]);
}
- elsif ($c =~ m/^link (.*)$/) {
- my $best = bestlink($trail, $1);
+ elsif ($c->[0] eq 'link') {
+ my $best = bestlink($trail, $c->[1]);
push @$members, $best if length $best;
}
}