- # Handle backlinks; if a page has added/removed links, update the
- # pages it links to. Also handles rebuilding dependant pages.
- # TODO: inefficient; pages may get rendered above and again here;
- # problem is the backlinks could be wrong in the first pass render
- # above
- if (%rendered || @del) {
- foreach my $f (@files) {
- my $p=pagename($f);
- if (exists $depends{$p}) {
- foreach my $file (keys %rendered, @del) {
- next if $f eq $file;
- my $page=pagename($file);
- if (pagespec_match($page, $depends{$p})) {
- debug("rendering $f, which depends on $page");
- render($f);
- $rendered{$f}=1;
- last;
- }
+sub derender_internal ($) {
+ my $file=shift;
+ my $page=pagename($file);
+ delete $depends{$page};
+ delete $depends_simple{$page};
+ foreach my $old (@{$renderedfiles{$page}}) {
+ delete $destsources{$old};
+ }
+ $renderedfiles{$page}=[];
+}
+
+sub render_linkers ($) {
+ my $f=shift;
+ my $p=pagename($f);
+ foreach my $page (keys %{$backlinks{$p}}) {
+ my $file=$pagesources{$page};
+ render($file, sprintf(gettext("building %s, which links to %s"), $file, $p));
+ }
+}
+
+sub remove_unrendered () {
+ foreach my $src (keys %rendered) {
+ my $page=pagename($src);
+ foreach my $file (@{$oldrenderedfiles{$page}}) {
+ if (! grep { $_ eq $file } @{$renderedfiles{$page}}) {
+ debug(sprintf(gettext("removing %s, no longer built by %s"), $file, $page));
+ prune($config{destdir}."/".$file);
+ }
+ }
+ }
+}
+
+sub calculate_changed_links ($$$) {
+ my ($changed, $del, $oldlink_targets)=@_;
+
+ my (%backlinkchanged, %linkchangers);
+
+ foreach my $file (@$changed, @$del) {
+ my $page=pagename($file);
+
+ if (exists $links{$page}) {
+ foreach my $l (@{$links{$page}}) {
+ my $target=bestlink($page, $l);
+ if (! exists $oldlink_targets->{$page}{$l} ||
+ $target ne $oldlink_targets->{$page}{$l}) {
+ $backlinkchanged{$target}=1;
+ $linkchangers{lc($page)}=1;