store state to avoid needing to rebuild when changing theme
authorJoey Hess <joey@kitenet.net>
Fri, 18 Jun 2010 20:40:47 +0000 (16:40 -0400)
committerJoey Hess <joey@kitenet.net>
Fri, 18 Jun 2010 20:40:47 +0000 (16:40 -0400)
IkiWiki/Plugin/theme.pm
doc/bugs/underlaydir_file_expose.mdwn

index ba6966381d6da42e646b9fe785b9e0e86b4f50a2..03b0816ed6fc5a6c42f0da916d898c6633eb7d15 100644 (file)
@@ -8,6 +8,7 @@ use IkiWiki 3.00;
 sub import {
        hook(type => "getsetup", id => "theme", call => \&getsetup);
        hook(type => "checkconfig", id => "theme", call => \&checkconfig);
+       hook(type => "needsbuild", id => "theme", call => \&needsbuild);
 }
 
 sub getsetup () {
@@ -22,7 +23,7 @@ sub getsetup () {
                        example => "actiontabs",
                        description => "name of theme to enable",
                        safe => 1,
-                       rebuild => 1,
+                       rebuild => 0,
                },
 }
 
@@ -34,4 +35,31 @@ sub checkconfig () {
        }
 }
 
+sub needsbuild ($) {
+       my $needsbuild=shift;
+       if (($config{theme} || '') ne ($wikistate{theme}{currenttheme} || '')) {
+               # theme changed; ensure all files in the theme are built
+               my %needsbuild=map { $_ => 1 } @$needsbuild;
+               if ($config{theme}) {
+                       foreach my $file (glob("$config{underlaydirbase}/themes/$config{theme}/*")) {
+                               if (-f $file) {
+                                       my $f=IkiWiki::basename($file);
+                                       push @$needsbuild, $f
+                                               unless $needsbuild{$f};
+                               }
+                       }
+               }
+               elsif ($wikistate{theme}{currenttheme}) {
+                       foreach my $file (glob("$config{underlaydirbase}/themes/$wikistate{theme}{currenttheme}/*")) {
+                               my $f=IkiWiki::basename($file);
+                               if (-f $file && defined eval { srcfile($f) }) {
+                                       push @$needsbuild, $f;
+                               }
+                       }
+               }
+               
+               $wikistate{theme}{currenttheme}=$config{theme};
+       }
+}
+
 1
index ca492e396ea2170bb9c461a0fad4a7bbefcb9ff5..4ee30e39d9cac966e319b8619c127cda4d9e3aaf 100644 (file)
@@ -9,4 +9,5 @@ gets rebuilt.)
 > A related problem occurs if changing a site's theme with the
 > [[plugins/theme]] plugin. The style.css of the old and new theme
 > often has the same mtime, so ikiwiki does not update it w/o a rebuild.
+> This is worked around in theme.pm with a special-purpose needsbuild hook.
 > --[[Joey]]