summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/google.pm
blob: 48ad4c8cea058f9a024bfdf99c01f5fcca8f4ca8 (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. section => "web",
  18. },
  19. }
  20. sub checkconfig () {
  21. if (! length $config{url}) {
  22. error(sprintf(gettext("Must specify %s when using the %s plugin"), "url", 'google'));
  23. }
  24. }
  25. my $form;
  26. sub pagetemplate (@) {
  27. my %params=@_;
  28. my $page=$params{page};
  29. my $template=$params{template};
  30. # Add search box to page header.
  31. if ($template->query(name => "searchform")) {
  32. if (! defined $form) {
  33. my $searchform = template("googleform.tmpl", blind_cache => 1);
  34. $searchform->param(url => $config{url});
  35. $form=$searchform->output;
  36. }
  37. $template->param(searchform => $form);
  38. }
  39. }
  40. 1