monotone: Deal with format change in version 0.45. (Thanks, Richard Levitte)
[ikiwiki] / IkiWiki / Plugin / google.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::google;
3
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
7 use URI;
8
9 sub import {
10         hook(type => "getsetup", id => "google", call => \&getsetup);
11         hook(type => "checkconfig", id => "google", call => \&checkconfig);
12         hook(type => "pagetemplate", id => "google", call => \&pagetemplate);
13 }
14
15 sub getsetup () {
16         return
17                 plugin => {
18                         safe => 1,
19                         rebuild => 1,
20                 },
21 }
22
23 sub checkconfig () {
24         if (! length $config{url}) {
25                 error(sprintf(gettext("Must specify %s when using the %s plugin"), "url", 'google'));
26         }
27 }
28
29 my $form;
30 sub pagetemplate (@) {
31         my %params=@_;
32         my $page=$params{page};
33         my $template=$params{template};
34
35         # Add search box to page header.
36         if ($template->query(name => "searchform")) {
37                 if (! defined $form) {
38                         my $searchform = template("googleform.tmpl", blind_cache => 1);
39                         $searchform->param(url => $config{url});
40                         $form=$searchform->output;
41                 }
42
43                 $template->param(searchform => $form);
44         }
45 }
46
47 1