<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::google;

use warnings;
use strict;
use IkiWiki 2.00;
use URI;

my $host;

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

sub getsetup () { #{{{
	return
		plugin =&gt; {
			safe =&gt; 1,
			rebuild =&gt; 1,
		},
} #}}}

sub checkconfig () { #{{{
	if (! length $config{url}) {
		error(sprintf(gettext("Must specify %s when using the google search plugin"), "url"));
	}
	my $uri=URI-&gt;new($config{url});
	if (! $uri || ! defined $uri-&gt;host) {
		error(gettext("Failed to parse url, cannot determine domain name"));
	}
	$host=$uri-&gt;host;
} #}}}

my $form;
sub pagetemplate (@) { #{{{
	my %params=@_;
	my $page=$params{page};
	my $template=$params{template};

	# Add search box to page header.
	if ($template-&gt;query(name =&gt; "searchform")) {
		if (! defined $form) {
			my $searchform = template("googleform.tmpl", blind_cache =&gt; 1);
			$searchform-&gt;param(sitefqdn =&gt; $host);
			$form=$searchform-&gt;output;
		}

		$template-&gt;param(searchform =&gt; $form);
	}
} #}}}

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