]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Render.pm
* Add support for links of the form [../foo]], this links to the page
[git.ikiwiki.info.git] / IkiWiki / Render.pm
index f59e54f2934a2c459660eada83b11dff925cd573..4033468b23a7917aadc01c0fd9fc9fed416c4573 100644 (file)
@@ -11,6 +11,7 @@ my %backlinks;
 my $backlinks_calculated=0;
 
 sub calculate_backlinks () { #{{{
+       return if $backlinks_calculated;
        %backlinks=();
        foreach my $page (keys %links) {
                foreach my $link (@{$links{$page}}) {
@@ -26,7 +27,7 @@ sub calculate_backlinks () { #{{{
 sub backlinks ($) { #{{{
        my $page=shift;
 
-       calculate_backlinks() unless $backlinks_calculated;
+       calculate_backlinks();
 
        my @links;
        return unless $backlinks{$page};
@@ -154,8 +155,8 @@ sub scan ($) { #{{{
                        push @links, titlepage($2);
                }
                if ($config{discussion}) {
-                       # Discussion links are a special case since they're not in the
-                       # text of the page, but on its template.
+                       # Discussion links are a special case since they're
+                       # not in the text of the page, but on its template.
                        push @links, "$page/discussion";
                }
                $links{$page}=\@links;
@@ -212,11 +213,12 @@ sub refresh () { #{{{
        my %exists;
        my @files;
        eval q{use File::Find};
+       error($@) if $@;
        find({
                no_chdir => 1,
                wanted => sub {
                        $_=decode_utf8($_);
-                       if (/$config{wiki_file_prune_regexp}/) {
+                       if (file_pruned($_, $config{srcdir})) {
                                $File::Find::prune=1;
                        }
                        elsif (! -d $_ && ! -l $_) {
@@ -236,7 +238,7 @@ sub refresh () { #{{{
                no_chdir => 1,
                wanted => sub {
                        $_=decode_utf8($_);
-                       if (/$config{wiki_file_prune_regexp}/) {
+                       if (file_pruned($_, $config{underlaydir})) {
                                $File::Find::prune=1;
                        }
                        elsif (! -d $_ && ! -l $_) {
@@ -303,6 +305,7 @@ sub refresh () { #{{{
                        scan($file);
                }
        }
+       calculate_backlinks();
 
        # render changed and new pages
        foreach my $file (@changed) {
@@ -311,22 +314,16 @@ sub refresh () { #{{{
                $rendered{$file}=1;
        }
        
-       # if any files were added or removed, check to see if each page
-       # needs an update due to linking to them or inlining them
+       # rebuild pages that link to added or removed pages
        if (@add || @del) {
-FILE:          foreach my $file (@files) {
-                       next if $rendered{$file};
-                       my $page=pagename($file);
-                       foreach my $f (@add, @del) {
-                               my $p=pagename($f);
-                               foreach my $link (@{$links{$page}}) {
-                                       if (bestlink($page, $link) eq $p) {
-                                               debug("rendering $file, which links to $p");
-                                               render($file);
-                                               $rendered{$file}=1;
-                                               next FILE;
-                                       }
-                               }
+               foreach my $f (@add, @del) {
+                       my $p=pagename($f);
+                       foreach my $page (keys %{$backlinks{$p}}) {
+                               my $file=$pagesources{$page};
+                               next if $rendered{$file};
+                               debug("rendering $file, which links to $p");
+                               render($file);
+                               $rendered{$file}=1;
                        }
                }
        }