title |
---|
Hooks |
Using hooks, your plugin can exercise fine-grained control over various aspects of the build process. If your plugin defines any hooks, Jekyll will call them at pre-defined points.
Hooks are registered to a container and an event name. To register one, you call Jekyll::Hooks.register, and pass the container, event name, and code to call whenever the hook is triggered. For example, if you want to execute some custom functionality every time Jekyll renders a post, you could register a hook like this:
{% highlight ruby %} Jekyll::Hooks.register :posts, :post_render do |post|
end {% endhighlight %}
Jekyll provides hooks for :site
, :pages
,
:posts
, and :documents
. In all cases, Jekyll calls your
hooks with the container object as the first callback parameter. But in the
case of :pre_render
, your hook will also receive a payload hash as
a second parameter which allows you full control over the variables that are
available while rendering.
The complete list of available hooks is below:
Container | Event | Called |
---|---|---|
|
|
Just after site reset |
|
|
After site data has been read and loaded from disk |
|
|
Just before rendering the whole site |
|
|
After rendering the whole site, but before writing any files |
|
|
After writing the whole site to disk |
|
|
Whenever a page is initialized |
|
|
Just before rendering a page |
|
|
After rendering a page, but before writing it to disk |
|
|
After writing a page to disk |
|
|
Whenever a post is initialized |
|
|
Just before rendering a post |
|
|
After rendering a post, but before writing it to disk |
|
|
After writing a post to disk |
|
|
Whenever a document is initialized |
|
|
Just before rendering a document |
|
|
After rendering a document, but before writing it to disk |
|
|
After writing a document to disk |