]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Render.pm
the problem with coding while drunk -- idiotic mistakes
[ikiwiki.git] / IkiWiki / Render.pm
index f59e54f2934a2c459660eada83b11dff925cd573..86396420736a8e7120815da60b579e9781b8b0cb 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};
@@ -92,7 +93,7 @@ sub genpage ($$$) { #{{{
                $template->param(historyurl => $u);
                $actions++;
        }
-       if ($config{discussion}) {
+       if ($config{discussion} && (length $config{cgiurl} || exists $links{"$page/discussion"})) {
                $template->param(discussionlink => htmllink($page, $page, "Discussion", 1, 1));
                $actions++;
        }
@@ -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;
                        }
                }
        }