<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
package IkiWiki::Plugin::theme;

use warnings;
use strict;
use IkiWiki 3.00;

sub import {
	hook(type =&gt; "getsetup", id =&gt; "theme", call =&gt; \&amp;getsetup);
	hook(type =&gt; "checkconfig", id =&gt; "theme", call =&gt; \&amp;checkconfig);
	hook(type =&gt; "needsbuild", id =&gt; "theme", call =&gt; \&amp;needsbuild);
}

sub getsetup () {
	return
		plugin =&gt; {
			safe =&gt; 1,
			rebuild =&gt; 0,
			section =&gt; "web",
		},
		theme =&gt; {
			type =&gt; "string",
			example =&gt; "actiontabs",
			description =&gt; "name of theme to enable",
			safe =&gt; 1,
			rebuild =&gt; 0,
		},
}

my $added=0;
sub checkconfig () {
	if (! $added &amp;&amp; exists $config{theme} &amp;&amp; $config{theme} =~ /^\w+$/) {
		add_underlay("themes/".$config{theme});
		$added=1;
	}
}

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 { $_ =&gt; 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 &amp;&amp; defined eval { srcfile($f) }) {
					push @$needsbuild, $f;
				}
			}
		}
		
		$wikistate{theme}{currenttheme}=$config{theme};
	}
	return $needsbuild;
}

1
</pre></body></html>