]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/theme.pm
Add modified opengraph plugin.
[git.ikiwiki.info.git] / IkiWiki / Plugin / theme.pm
index ba6966381d6da42e646b9fe785b9e0e86b4f50a2..9b84ea7f023d10c6db947f136adb4ed8b8ec72e0 100644 (file)
@@ -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 () {
@@ -22,7 +24,7 @@ sub getsetup () {
                        example => "actiontabs",
                        description => "name of theme to enable",
                        safe => 1,
-                       rebuild => 1,
+                       rebuild => 0,
                },
 }
 
@@ -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