A filter is used to modify some specified data. Hexo passes data to filters in sequence and the filters then modify the data one after the other. This concept was borrowed from WordPress.
Synopsis
|
You can define the priority
. Lower priority
means that it will be executed first. The default priority
is 10.
Execute Filters
|
Option | Description |
---|---|
context |
Context |
args |
Arguments. This must be an array. |
The first argument passed into each filter is data
. The data
passed into the next filter can be modified by returning a new value. If nothing is returned, the data remains unmodified. You can even use args
to specify other arguments in filters. For example:
|
You can also use the following methods to execute filters:
|
Unregister Filters
|
Filter List
Here is a list of filters used by Hexo.
before_post_render
Executed before a post is rendered. Refer to post rendering to learn the execution steps.
For example, to transform the title to lower case:
|
after_post_render
Executed after a post is rendered. Refer to post rendering to learn the execution steps.
For example, to replace @username
with a link to a Twitter profile:
|
before_exit
Executed before Hexo is about to exit – this will run right after hexo.exit
is called.
|
before_generate
Executed before generation begins.
|
after_generate
Executed after generation finishes.
|
template_locals
Modify local variables in templates.
For example, to add the current time to the local variables of templates:
|
after_init
Executed after Hexo is initialized – this will run right after hexo.init
completes.
|
new_post_path
Executed when creating a post to determine the path of new posts.
|
post_permalink
Used to determine the permalink of posts.
|
after_render
Executed after rendering finishes. You can see rendering for more info.
server_middleware
Add middleware to the server. app
is a Connect instance.
For example, to add X-Powered-By: Hexo
to the response header:
|