X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/d70ba7cff3fc6cc78ea2f8eb0713212478ab6ba7..f32f6411ff604a879151ab329907afca351ea3b6:/IkiWiki/Plugin/trail.pm
diff --git a/IkiWiki/Plugin/trail.pm b/IkiWiki/Plugin/trail.pm
index 5ee152155..7d2338f9b 100644
--- a/IkiWiki/Plugin/trail.pm
+++ b/IkiWiki/Plugin/trail.pm
@@ -1,6 +1,6 @@
#!/usr/bin/perl
# Copyright © 2008-2011 Joey Hess
-# Copyright © 2009-2011 Simon McVittie
+# Copyright © 2009-2012 Simon McVittie
# Licensed under the GNU GPL, version 2, or any later version published by the
# Free Software Foundation
package IkiWiki::Plugin::trail;
@@ -13,67 +13,46 @@ sub import {
hook(type => "getsetup", id => "trail", call => \&getsetup);
hook(type => "needsbuild", id => "trail", call => \&needsbuild);
hook(type => "preprocess", id => "trailoptions", call => \&preprocess_trailoptions, scan => 1);
- hook(type => "preprocess", id => "trailinline", call => \&preprocess_trailinline, scan => 1);
hook(type => "preprocess", id => "trailitem", call => \&preprocess_trailitem, scan => 1);
hook(type => "preprocess", id => "trailitems", call => \&preprocess_trailitems, scan => 1);
hook(type => "preprocess", id => "traillink", call => \&preprocess_traillink, scan => 1);
hook(type => "pagetemplate", id => "trail", call => \&pagetemplate);
+ hook(type => "build_affected", id => "trail", call => \&build_affected);
}
-=head1 Page state
-
-If a page C<$T> is a trail, then it can have
-
-=over
-
-=item * C<$pagestate{$T}{trail}{contents}>
-
-Reference to an array of lists each containing either:
-
-=over
-
-=item * C<[link, "link"]>
-
-A link specification, pointing to the same page that C<[[link]]> would select
-
-=item * C<[pagespec, "posts/*", "age", 0]>
-
-A match by pagespec; the third array element is the sort order and the fourth
-is whether to reverse sorting
-
-=back
-
-=item * C<$pagestate{$T}{trail}{sort}>
-
-A [[ikiwiki/pagespec/sorting]] order; if absent or undef, the trail is in
-the order given by the links that form it
-
-=item * C<$pagestate{$T}{trail}{circular}>
-
-True if this trail is circular (i.e. going "next" from the last item is
-allowed, and takes you back to the first)
-
-=item * C<$pagestate{$T}{trail}{reverse}>
-
-True if C is to be reversed.
-
-=back
-
-If a page C<$M> is a member of a trail C<$T>, then it has
-
-=over
-
-=item * C<$pagestate{$M}{trail}{item}{$T}[0]>
-
-The page before this one in C<$T> at the last rebuild, or undef.
-
-=item * C<$pagestate{$M}{trail}{item}{$T}[1]>
-
-The page after this one in C<$T> at the last refresh, or undef.
-
-=back
-
-=cut
+# Page state
+#
+# If a page $T is a trail, then it can have
+#
+# * $pagestate{$T}{trail}{contents}
+# Reference to an array of lists each containing either:
+# - [pagenames => "page1", "page2"]
+# Those literal pages
+# - [link => "link"]
+# A link specification, pointing to the same page that [[link]]
+# would select
+# - [pagespec => "posts/*", "age", 0]
+# A match by pagespec; the third array element is the sort order
+# and the fourth is whether to reverse sorting
+#
+# * $pagestate{$T}{trail}{sort}
+# A sorting order; if absent or undef, the trail is in the order given
+# by the links that form it
+#
+# * $pagestate{$T}{trail}{circular}
+# True if this trail is circular (i.e. going "next" from the last item is
+# allowed, and takes you back to the first)
+#
+# * $pagestate{$T}{trail}{reverse}
+# True if C is to be reversed.
+#
+# If a page $M is a member of a trail $T, then it has
+#
+# * $pagestate{$M}{trail}{item}{$T}[0]
+# The page before this one in C<$T> at the last rebuild, or undef.
+#
+# * $pagestate{$M}{trail}{item}{$T}[1]
+# The page after this one in C<$T> at the last refresh, or undef.
sub getsetup () {
return
@@ -123,29 +102,6 @@ sub preprocess_trailoptions (@) {
return "";
}
-sub preprocess_trailinline (@) {
- my %params = @_;
-
- if (! exists $params{sort}) {
- # sort in the same order as [[plugins/inline]]'s default
- $params{sort} = 'age';
- }
-
- if (defined wantarray) {
- scalar preprocess_trailitems(%params);
-
- if (IkiWiki->can("preprocess_inline")) {
- return IkiWiki::preprocess_inline(@_);
- }
- else {
- error("trailinline directive requires the inline plugin");
- }
- }
- else {
- preprocess_trailitems(%params);
- }
-}
-
sub preprocess_trailitem (@) {
my $link = shift;
shift;
@@ -194,8 +150,8 @@ sub preprocess_trailitems (@) {
}
if (exists $params{pagenames}) {
- my @list = map { [link => $_] } split ' ', $params{pagenames};
- push @{$pagestate{$params{page}}{trail}{contents}}, @list;
+ push @{$pagestate{$params{page}}{trail}{contents}},
+ [pagenames => (split ' ', $params{pagenames})];
}
return "";
@@ -299,14 +255,9 @@ sub trails_differ {
my $done_prerender = 0;
-my %origsubs;
-
sub prerender {
return if $done_prerender;
- $origsubs{render_backlinks} = \&IkiWiki::render_backlinks;
- inject(name => "IkiWiki::render_backlinks", call => \&render_backlinks);
-
%trail_to_members = ();
%member_to_trails = ();
@@ -322,6 +273,19 @@ sub prerender {
$c->[1], sort => $c->[2],
reverse => $c->[3]);
}
+ elsif ($c->[0] eq 'pagenames') {
+ my @pagenames = @$c;
+ shift @pagenames;
+ foreach my $page (@pagenames) {
+ if (exists $pagesources{$page}) {
+ push @$members, $page;
+ }
+ else {
+ # rebuild trail if it turns up
+ add_depends($trail, $page, deptype("presence"));
+ }
+ }
+ }
elsif ($c->[0] eq 'link') {
my $best = bestlink($trail, $c->[1]);
push @$members, $best if length $best;
@@ -371,7 +335,7 @@ sub prerender {
if (exists $pagestate{$member}{trail}{item} &&
! exists $member_to_trails{$member}) {
$rebuild_trail_members{$member} = 1;
- delete $pagestate{$member}{trailitem};
+ delete $pagestate{$member}{trail}{item};
}
}
@@ -392,18 +356,14 @@ sub prerender {
$done_prerender = 1;
}
-# This is called at about the right time that we can hijack it to render
-# extra pages.
-sub render_backlinks ($) {
- my $blc = shift;
+sub build_affected {
+ my %affected;
foreach my $member (keys %rebuild_trail_members) {
- next unless exists $pagesources{$member};
-
- IkiWiki::render($pagesources{$member}, sprintf(gettext("building %s, its previous or next page has changed"), $member));
+ $affected{$member} = sprintf(gettext("building %s, its previous or next page has changed"), $member);
}
- $origsubs{render_backlinks}($blc);
+ return %affected;
}
sub title_of ($) {