There are two methods for rendering files or strings in Hexo: the asynchronous hexo.render.render
method and the synchronous hexo.render.renderSync
method. Unsurprisingly, the two methods are very similar so only the asynchronous hexo.render.render
will be further discussed in the below paragraphs.
Render a String
When rendering a string, you must specify an engine
to let Hexo know which rendering engine it should use.
|
Render a File
When rendering a file, it’s not necessary to specify an engine
because Hexo will detect the relevant rendering engine automatically based on the extension of the file. Of course, you are also allowed to explicitly define the engine
.
|
Render Options
You can pass in an options object as the second argument.
|
after_render Filters
When rendering is complete, Hexo will execute the corresponding after_render
filters. For example, we can use this feature to implement a JavaScript minifier.
|
Check Whether a File is Renderable
You can use the isRenderable
or isRenderableSync
method to check whether a file path is renderable. Only when a corresponding renderer has been registered will this method return true.
|
Get the Output Extension
Use the getOutput
method to get the extension of the rendered output. If a file is not renderable, the method will return an empty string.
|