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