diff options
author | Joey Hess <joey@kitenet.net> | 2010-06-18 16:40:47 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-06-18 16:40:47 -0400 |
commit | 57e56828f5b03f8fb31631f36731f989d4335607 (patch) | |
tree | e98fc8ebe1a920bc69b85b3c989ee310c327bb8c | |
parent | cfcc79ed4c9f11ef8af2ae19e3bb402289e9ea39 (diff) |
store state to avoid needing to rebuild when changing theme
-rw-r--r-- | IkiWiki/Plugin/theme.pm | 30 | ||||
-rw-r--r-- | doc/bugs/underlaydir_file_expose.mdwn | 1 |
2 files changed, 30 insertions, 1 deletions
diff --git a/IkiWiki/Plugin/theme.pm b/IkiWiki/Plugin/theme.pm index ba6966381..03b0816ed 100644 --- a/IkiWiki/Plugin/theme.pm +++ b/IkiWiki/Plugin/theme.pm @@ -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 diff --git a/doc/bugs/underlaydir_file_expose.mdwn b/doc/bugs/underlaydir_file_expose.mdwn index ca492e396..4ee30e39d 100644 --- a/doc/bugs/underlaydir_file_expose.mdwn +++ b/doc/bugs/underlaydir_file_expose.mdwn @@ -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]] |