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.
You can define the
priority means that it will be executed first. The default
priority is 10.
||Arguments. This must be an array.|
The first argument passed into each filter is
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:
Here is a list of filters used by Hexo.
Executed before a post is rendered. Refer to post rendering to learn the execution steps.
For example, to transform the title to lower case:
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:
Executed before Hexo is about to exit – this will run right after
hexo.exit is called.
Executed before generation begins.
Executed after generation finishes.
Modify local variables in templates.
For example, to add the current time to the local variables of templates:
Executed after Hexo is initialized – this will run right after
Executed when creating a post to determine the path of new posts.
Used to determine the permalink of posts.
Executed after rendering finishes. You can see rendering for more info.
Add middleware to the server.
app is a Connect instance.
For example, to add
X-Powered-By: Hexo to the response header: