]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Render.pm
break out fast_file_copy
[ikiwiki.git] / IkiWiki / Render.pm
index 959279fc8a906508db1d1b8561cd390e5cc62326..2cdec421f1da745e6f6aa2060be1ce46b566a822 100644 (file)
@@ -156,10 +156,6 @@ sub scan ($) { #{{{
                my $page=pagename($file);
                will_render($page, htmlpage($page), 1);
 
-               # Always needs to be done, since filters might add links
-               # to the content.
-               $content=filter($page, $page, $content);
-       
                if ($config{discussion}) {
                        # Discussion links are a special case since they're
                        # not in the text of the page, but on its template.
@@ -184,6 +180,30 @@ sub scan ($) { #{{{
        }
 } #}}}
 
+sub fast_file_copy ($$$$$) { #{{{
+       my $srcfile=shift;
+       my $destfile=shift;
+       my $srcfd=shift;
+       my $destfd=shift;
+       my $cleanup=shift;
+
+       my $blksize = 16384;
+       my ($len, $buf, $written);
+       while ($len = sysread $srcfd, $buf, $blksize) {
+               if (! defined $len) {
+                       next if $! =~ /^Interrupted/;
+                       error("failed to read $srcfile: $!", $cleanup);
+               }
+               my $offset = 0;
+               while ($len) {
+                       defined($written = syswrite $destfd, $buf, $len, $offset)
+                               or error("failed to write $destfile: $!", $cleanup);
+                       $len -= $written;
+                       $offset += $written;
+               }
+       }
+}
+
 sub render ($) { #{{{
        my $file=shift;
        
@@ -195,7 +215,7 @@ sub render ($) { #{{{
                will_render($page, htmlpage($page), 1);
                return if $type=~/^_/;
                
-               my $content=htmlize($page, $type,
+               my $content=htmlize($page, $page, $type,
                        linkify($page, $page,
                        preprocess($page, $page,
                        filter($page, $page,
@@ -214,29 +234,12 @@ sub render ($) { #{{{
                        if (link($srcfile, $config{destdir}."/".$file)) {
                                return;
                        }
-                       # if hardlink fails, fall back top copying
+                       # if hardlink fails, fall back to copying
                }
                
                my $srcfd=readfile($srcfile, 1, 1);
                writefile($file, $config{destdir}, undef, 1, sub {
-                       my $destfd=shift;
-                       my $cleanup=shift;
-
-                       my $blksize = 16384;
-                       my ($len, $buf, $written);
-                       while ($len = sysread $srcfd, $buf, $blksize) {
-                               if (! defined $len) {
-                                       next if $! =~ /^Interrupted/;
-                                       error("failed to read $srcfile: $!", $cleanup);
-                               }
-                               my $offset = 0;
-                               while ($len) {
-                                       defined($written = syswrite $destfd, $buf, $len, $offset)
-                                               or error("failed to write $file: $!", $cleanup);
-                                       $len -= $written;
-                                       $offset += $written;
-                               }
-                       }
+                       fast_file_copy($srcfile, $file, $srcfd, @_);
                });
        }
 } #}}}
@@ -508,8 +511,6 @@ sub refresh () { #{{{
 } #}}}
 
 sub commandline_render () { #{{{
-       loadplugins();
-       checkconfig();
        lockwiki();
        loadindex();
        unlockwiki();
@@ -526,7 +527,7 @@ sub commandline_render () { #{{{
        $content=filter($page, $page, $content);
        $content=preprocess($page, $page, $content);
        $content=linkify($page, $page, $content);
-       $content=htmlize($page, $type, $content);
+       $content=htmlize($page, $page, $type, $content);
        $pagemtime{$page}=(stat($srcfile))[9];
 
        print genpage($page, $content);