A generator builds routes based on processed files.
locals argument will get passed into the function, containing the site variables. You should use this argument to get the website data, thereby avoiding having to access the database directly.
||Path not including the prefixing
||Layout. Specify the layouts for rendering. The value can be a string or an array. If it’s ignored then the route will return
When the source files are updated, Hexo will execute all generators and rebuild the routes. Please return the data and do not access the router directly.
Create an archive page at
archives/index.html. We pass all posts as data to the templates. This data is equivalent to the
page variable in templates.
Next, set the
layout attribute to render with the theme templates. We’re setting two layouts in this example: if the
archive layout doesn’t exist, the
index layout will be used instead.
You can use the convenient official tool hexo-pagination to easily build archive pages with pagination.
Iterate over all posts in
locals.posts and create routes for all the posts.
This time we don’t return the data explicitly but instead set
data to a function so the route will build
fs.ReadStream only when needed.