If the title of a trail or trail-member changes, rebuild affected pages
authorSimon McVittie <smcv@debian.org>
Wed, 2 Jan 2013 19:14:26 +0000 (19:14 +0000)
committerSimon McVittie <smcv@debian.org>
Wed, 2 Jan 2013 19:19:32 +0000 (19:19 +0000)
If the title of a trail changes, each member of that trail must be
rebuilt, for its prev/up/next box to reflect the new title.

If the title of a member changes, its next and previous items (if any)
must be rebuilt, for their prev/up/next boxes to reflect the new title.

IkiWiki/Plugin/trail.pm
t/trail.t

index 86c94642aca4232d9f379d325b929a2877e43163..b1bb6d5b532fb25120f6da1d4a371e43e04cfb72 100644 (file)
@@ -62,12 +62,20 @@ sub getsetup () {
                },
 }
 
                },
 }
 
+# Cache of pages' old titles, so we can tell whether they changed
+my %old_trail_titles;
+
 sub needsbuild (@) {
        my $needsbuild=shift;
 sub needsbuild (@) {
        my $needsbuild=shift;
+
        foreach my $page (keys %pagestate) {
                if (exists $pagestate{$page}{trail}) {
                        if (exists $pagesources{$page} &&
                            grep { $_ eq $pagesources{$page} } @$needsbuild) {
        foreach my $page (keys %pagestate) {
                if (exists $pagestate{$page}{trail}) {
                        if (exists $pagesources{$page} &&
                            grep { $_ eq $pagesources{$page} } @$needsbuild) {
+                               # Remember its title, so we can know whether
+                               # it changed.
+                               $old_trail_titles{$page} = title_of($page);
+
                                # Remove state, it will be re-added
                                # if the preprocessor directive is still
                                # there during the rebuild. {item} is the
                                # Remove state, it will be re-added
                                # if the preprocessor directive is still
                                # there during the rebuild. {item} is the
@@ -78,6 +86,7 @@ sub needsbuild (@) {
                        }
                }
        }
                        }
                }
        }
+
        return $needsbuild;
 }
 
        return $needsbuild;
 }
 
@@ -230,6 +239,12 @@ sub trails_differ {
                if (! exists $new->{$trail}) {
                        return 1;
                }
                if (! exists $new->{$trail}) {
                        return 1;
                }
+
+               if (exists $old_trail_titles{$trail} &&
+                       title_of($trail) ne $old_trail_titles{$trail}) {
+                       return 1;
+               }
+
                my ($old_p, $old_n) = @{$old->{$trail}};
                my ($new_p, $new_n) = @{$new->{$trail}};
                $old_p = "" unless defined $old_p;
                my ($old_p, $old_n) = @{$old->{$trail}};
                my ($new_p, $new_n) = @{$new->{$trail}};
                $old_p = "" unless defined $old_p;
@@ -239,9 +254,20 @@ sub trails_differ {
                if ($old_p ne $new_p) {
                        return 1;
                }
                if ($old_p ne $new_p) {
                        return 1;
                }
+
+               if (exists $old_trail_titles{$old_p} &&
+                       title_of($old_p) ne $old_trail_titles{$old_p}) {
+                       return 1;
+               }
+
                if ($old_n ne $new_n) {
                        return 1;
                }
                if ($old_n ne $new_n) {
                        return 1;
                }
+
+               if (exists $old_trail_titles{$old_n} &&
+                       title_of($old_n) ne $old_trail_titles{$old_n}) {
+                       return 1;
+               }
        }
 
        foreach my $trail (keys %$new) {
        }
 
        foreach my $trail (keys %$new) {
index 59eb0d4d618e4a3096bb62ad5c505a6ce57fb671..dce3b3c7e4df551984c30c6ed0a0cecac53631ed 100755 (executable)
--- a/t/trail.t
+++ b/t/trail.t
@@ -275,21 +275,15 @@ check_trail("limited/c.html", "n=limited/d p=limited/b");
 check_trail("limited/d.html", "n= p=limited/c");
 # Also, b and d should pick up the change to c. This regressed with the
 # change to using a presence dependency.
 check_trail("limited/d.html", "n= p=limited/c");
 # Also, b and d should pick up the change to c. This regressed with the
 # change to using a presence dependency.
-TODO: {
-local $TODO = "trail members don't pick up other members' title changes";
 $blob = readfile("t/tmp/out/limited/b.html");
 ok($blob =~ /New C page &gt;/m);
 $blob = readfile("t/tmp/out/limited/d.html");
 ok($blob =~ /&lt; New C page/m);
 $blob = readfile("t/tmp/out/limited/b.html");
 ok($blob =~ /New C page &gt;/m);
 $blob = readfile("t/tmp/out/limited/d.html");
 ok($blob =~ /&lt; New C page/m);
-}
 
 # Members of a retitled trail should pick up that change.
 # This regressed with the change to using a presence dependency.
 
 # Members of a retitled trail should pick up that change.
 # This regressed with the change to using a presence dependency.
-TODO: {
-local $TODO = "trail members don't pick up the trail's title changes";
 $blob = readfile("t/tmp/out/retitled/a.html");
 ok($blob =~ /\^ the new title \^/m);
 $blob = readfile("t/tmp/out/retitled/a.html");
 ok($blob =~ /\^ the new title \^/m);
-}
 
 # untrail is no longer a trail, so these are no longer in it.
 check_no_trail("untrail/a.html");
 
 # untrail is no longer a trail, so these are no longer in it.
 check_no_trail("untrail/a.html");