X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/062ed44f47d61c3bbbf2e8a7944a9b4e423b735a..07d39ce5bf320940c210b0e67dd293c43351cd47:/IkiWiki/Plugin/theme.pm diff --git a/IkiWiki/Plugin/theme.pm b/IkiWiki/Plugin/theme.pm index 5e6e4b092..9b84ea7f0 100644 --- a/IkiWiki/Plugin/theme.pm +++ b/IkiWiki/Plugin/theme.pm @@ -8,6 +8,8 @@ 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); + hook(type => "pagetemplate", id => "theme", call => \&pagetemplate); } sub getsetup () { @@ -34,4 +36,40 @@ 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}; + } + return $needsbuild; +} + +sub pagetemplate (@) { + my %params=@_; + my $template=$params{template}; + if (exists $config{theme} && length $config{theme}) { + $template->param("theme_$config{theme}" => 1); + } +} + 1