From 7829752f375e6923583c1aa43dbf88828ab4b8e6 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 26 Aug 2008 12:30:35 -0400 Subject: [PATCH] Add a postscan hook. * Add a postscan hook. * search: Use postscan hook, avoid updating index when previewing. (cherry picked from commit 584f3e3061e8983e4caa328d7bc16fdeba849654) --- IkiWiki/Plugin/search.pm | 6 +----- IkiWiki/Plugin/skeleton.pm | 7 +++++++ IkiWiki/Render.pm | 4 ++++ debian/changelog | 2 ++ doc/plugins/write.mdwn | 11 +++++++++++ 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm index 284f477fa..822b5974e 100644 --- a/IkiWiki/Plugin/search.pm +++ b/IkiWiki/Plugin/search.pm @@ -9,7 +9,7 @@ use IkiWiki 2.00; sub import { #{{{ hook(type => "checkconfig", id => "search", call => \&checkconfig); hook(type => "pagetemplate", id => "search", call => \&pagetemplate); - hook(type => "sanitize", id => "search", call => \&index); + hook(type => "postscan", id => "search", call => \&index); hook(type => "delete", id => "search", call => \&delete); hook(type => "cgi", id => "search", call => \&cgi); } # }}} @@ -48,8 +48,6 @@ my $scrubber; my $stemmer; sub index (@) { #{{{ my %params=@_; - - return $params{content} if $IkiWiki::preprocessing{$params{destpage}}; setupfiles(); @@ -132,8 +130,6 @@ sub index (@) { #{{{ $doc->add_term($pageterm); $db->replace_document_by_term($pageterm, $doc); - - return $params{content}; } #}}} sub delete (@) { #{{{ diff --git a/IkiWiki/Plugin/skeleton.pm b/IkiWiki/Plugin/skeleton.pm index 17a2162ff..1af8e4e9d 100644 --- a/IkiWiki/Plugin/skeleton.pm +++ b/IkiWiki/Plugin/skeleton.pm @@ -18,6 +18,7 @@ sub import { #{{{ hook(type => "scan", id => "skeleton", call => \&scan); hook(type => "htmlize", id => "skeleton", call => \&htmlize); hook(type => "sanitize", id => "skeleton", call => \&sanitize); + hook(type => "postscan", id => "skeleton", call => \&postscan); hook(type => "format", id => "skeleton", call => \&format); hook(type => "pagetemplate", id => "skeleton", call => \&pagetemplate); hook(type => "templatefile", id => "skeleton", call => \&templatefile); @@ -89,6 +90,12 @@ sub sanitize (@) { #{{{ return $params{content}; } # }}} +sub postscan (@) { #{{{ + my %params=@_; + + debug("skeleton plugin running as postscan"); +} # }}} + sub format (@) { #{{{ my %params=@_; diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index c241fd40b..e76dcef3d 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -135,6 +135,10 @@ sub genpage ($$) { #{{{ }); $content=$template->output; + + run_hooks(postscan => sub { + shift->(page => $page, content => $content); + }); run_hooks(format => sub { $content=shift->( diff --git a/debian/changelog b/debian/changelog index d36872efb..d1706a77c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,8 @@ ikiwiki (2.54) UNRELEASED; urgency=low * smileys: Some fixes for escaped smileys. * smileys: Note that smileys need to be double-escaped for the escaping to work. Markdown removes one level of escaping. + * Add a postscan hook. + * search: Use postscan hook, avoid updating index when previewing. -- Josh Triplett Wed, 09 Jul 2008 21:30:33 -0700 diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 5def4c679..16fa4ae17 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -214,6 +214,17 @@ modify the body of a page after it has been fully converted to html. The function is passed named parameters: "page", "destpage", and "content", and should return the sanitized content. +### postscan + + hook(type => "postscan", id => "foo", call => \&postscan); + +This hook is called once the full page body is available (but before the +format hook). The most common use is to update search indexes. Added in +ikiwiki 2.54. + +The function is passed named parameters "page" and "content". Its return +value is ignored. + ### format hook(type => "format", id => "foo", call => \&format); -- 2.26.2