summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/google.pm
blob: 68cde261c66748c5d32475657986ce9d465fbbbf (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. # This is a mass dependency, so if the search form template
  25. # changes, every page is rebuilt.
  26. add_depends("", "templates/googleform.tmpl");
  27. }
  28. my $form;
  29. sub pagetemplate (@) {
  30. my %params=@_;
  31. my $page=$params{page};
  32. my $template=$params{template};
  33. # Add search box to page header.
  34. if ($template->query(name => "searchform")) {
  35. if (! defined $form) {
  36. my $searchform = template("googleform.tmpl", blind_cache => 1);
  37. $searchform->param(url => $config{url});
  38. $searchform->param(html5 => $config{html5});
  39. $form=$searchform->output;
  40. }
  41. $template->param(searchform => $form);
  42. }
  43. }
  44. 1