]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/search.pm
web commit by joey
[git.ikiwiki.info.git] / IkiWiki / Plugin / search.pm
index 213ed45ff29c00c19769cbee3ec00faf991ae667..c8e0dd580224a7dc810208c1ac3f294633b1f5ab 100644 (file)
@@ -9,6 +9,8 @@ use IkiWiki;
 sub import { #{{{
        IkiWiki::hook(type => "checkconfig", id => "hyperestraier",
                call => \&checkconfig);
+       IkiWiki::hook(type => "pagetemplate", id => "hyperestraier",
+               call => \&pagetemplate);
        IkiWiki::hook(type => "delete", id => "hyperestraier",
                call => \&delete);
        IkiWiki::hook(type => "change", id => "hyperestraier",
@@ -23,16 +25,24 @@ sub checkconfig () { #{{{
                        IkiWiki::error("Must specify $required when using the search plugin\n");
                }
        }
+} #}}}
+
+my $form;
+sub pagetemplate (@) { #{{{
+       my %params=@_;
+       my $page=$params{page};
+       my $template=$params{template};
+
+       # Add search box to page header.
+       if ($template->query(name => "searchform")) {
+               if (! defined $form) {
+                       my $searchform = IkiWiki::template("searchform.tmpl", blind_cache => 1);
+                       $searchform->param(searchaction => $IkiWiki::config{cgiurl});
+                       $form=$searchform->output;
+               }
 
-       $IkiWiki::config{headercontent}.=qq{
-<form method="get" action="$IkiWiki::config{cgiurl}" id="searchform">
-<div>
-<input type="text" name="phrase" value="" size="16" />
-<input type="hidden" name="enc" value="UTF-8" />
-<input type="hidden" name="do" value="hyperestraier" />
-</div>
-</form>
-};
+               $template->param(searchform => $form);
+       }
 } #}}}
 
 sub delete (@) { #{{{
@@ -45,7 +55,7 @@ sub change (@) { #{{{
        IkiWiki::debug("updating hyperestraier search index");
        IkiWiki::estcmd("gather -cm -bc -cl -sd",
                map {
-                       $IkiWiki::config{destdir}."/".$IkiWiki::renderedfiles{IkiWiki::pagename($_)}
+                       Encode::encode_utf8($IkiWiki::config{destdir}."/".$IkiWiki::renderedfiles{IkiWiki::pagename($_)})
                } @_
        );
        IkiWiki::estcfg();
@@ -79,9 +89,7 @@ sub estcfg () { #{{{
        close TEMPLATE;
        open(TEMPLATE, ">$estdir/$cgi.conf") ||
                error("write $estdir/$cgi.conf: $!");
-       my $template=HTML::Template->new(
-               filename => "$config{templatedir}/estseek.conf"
-       );
+       my $template=template("estseek.conf");
        eval q{use Cwd 'abs_path'};
        $template->param(
                index => $estdir,