This is a late answer, but I feel that there is a simple pagination answer with current hexo libraries. However, they must have default initialization.
Take a look at hexo-generator-index , it uses hexo-pagination to create an array of pages.
Each of these pages will contain posts for these pages. Your pages will also receive .prev and .next , among other things, through hexo-pagination . Pages will also be automatically sent to the renderer. You only need to install this module with
npm install hexo-generator-index
Hexo automatically looks for packages starting with hexo-* and require these modules during initialization. Pay attention to config.index_generator.path in the code. You can specify in the _config.yml default blogs initialized with hexo init a-blog , now type the following yaml
# Home page setting
These messages will be available in your templates. Just use page.posts . Have you looked at the line where layout: ['index', 'archive'] appears layout: ['index', 'archive'] ? This means that index.ejs will be used as a template for your pages. If it cannot find index.ejs , archive.ejs used as a backup. The project will default to index.ejs , which calls themes/layouts/_partial/archive.ejs as a partial file. Here is a sample from the _partial / archive.ejs file, accessing the page messages:
<% page.posts.each(function(post){ %> <%- partial('article', {post: post, index: true}) %> <% }) %>
One tip, however, page.posts not an array. This is actually a wrapped array (a query object, to be precise, a search warehouse, a database for hexo, if you're interested). This is why it is possible to use page.posts.each , where each javascript function has an Array.prototype.forEach value.
In the same file you will also find
<% if (page.total > 1){ %> <nav id="page-nav"> <% var prev_text = "« " + __('prev');var next_text = __('next') + " »"%> <%- paginator({ prev_text: prev_text, next_text: next_text }) %> </nav> <% } %>
See the paginator helper and source code . Basically, this is a function that takes a javascript object and writes a string that encodes <a> tags. You can also register your own helper and paginate as you like.
Return to index generator. Note that whatever you use for the path field, you will get the index.html file generated for you in that path. Therefore, if you enter path: cats , you can visit it at yoursite.com/cats/ , because after creating a shared folder, the cats/index.html file will exist in the cats/index.html file. Page 2, if you are not supplying anything for config.pagination_dir (or just pagination_dir in your _config.yml ), you can visit yoursite.com/cats/page/2/ .
hexo-generate-index will index all your posts. There are other modules for indexing posts and will be paginated for tags and categories. Look at the plugins and type "generat".