summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/google.pm
blob: 92b9b29eb63a86d031ed995ee08ab3b5d0a10ce0 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::google;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 2.00;
  6. use URI;
  7. my $host;
  8. sub import { #{{{
  9. hook(type => "getsetup", id => "google", call => \&getsetup);
  10. hook(type => "checkconfig", id => "google", call => \&checkconfig);
  11. hook(type => "pagetemplate", id => "google", call => \&pagetemplate);
  12. } # }}}
  13. sub getsetup () { #{{{
  14. return
  15. plugin => {
  16. safe => 1,
  17. rebuild => 1,
  18. },
  19. } #}}}
  20. sub checkconfig () { #{{{
  21. if (! length $config{url}) {
  22. error(sprintf(gettext("Must specify %s when using the google search plugin"), "url"));
  23. }
  24. my $uri=URI->new($config{url});
  25. if (! $uri || ! defined $uri->host) {
  26. error(gettext("Failed to parse url, cannot determine domain name"));
  27. }
  28. $host=$uri->host;
  29. } #}}}
  30. my $form;
  31. sub pagetemplate (@) { #{{{
  32. my %params=@_;
  33. my $page=$params{page};
  34. my $template=$params{template};
  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(sitefqdn => $host);
  40. $form=$searchform->output;
  41. }
  42. $template->param(searchform => $form);
  43. }
  44. } #}}}
  45. 1