
While working on my Hexo blog, I wanted to pin some posts and hide others from the homepage. The existing options covered parts of that: one plugin handled pinning, another hid categories or tags, and hiding posts in a theme caused pagination problems. I forked the official index generator, added the rules I needed, and published hexo-generator-index-custom.
Ordering the posts
The plugin reads top, sticky, and hide from post frontmatter. It applies the configured order_by, removes posts with hide set to true, sorts by pinning value, and passes the result to hexo-pagination.
This version adds top and sticky to calculate the pinning value. Larger values appear first:
posts.data = posts.data.sort(
(a, b) =>
((b.sticky || 0) + (b.top || 0)) -
((a.sticky || 0) + (a.top || 0))
);Posts using either field can therefore participate in the same ordering. Setting hide: true removes a post from the index.
---
title: A pinned post
top: 10
---
Filtering before pagination
When a theme hides a post during rendering, that post has already counted toward its page. Hiding several posts can leave the first page with fewer visible entries.
Filtering in the generator gives pagination the final list of visible posts instead. I fixed a bug in the last-page count in v1.0.1, then left a “light speed” comment in the development notes.
The plugin keeps the official generator's path, per_page, order_by, and pagination_dir options and registers through Hexo's index-generator extension point. It replaces the existing index generator rather than running alongside it.
Source code · npm · Development notes
