hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.

Home Page:https://hexo.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a way to make hexo render articles in a specific order ?

hinak0 opened this issue · comments

Check List

  • I have already read Docs page.
  • I have already searched existing issues.

Feature Request

I found that in certain Hexo themes (such as Butterfly), there are repetitive occurrences of the same post covers in the random article cover feature. As a result, I've improved the random algorithm (jerryc127/hexo-theme-butterfly#1384). However, the unchangeable rendering order of articles within the Hexo hook: hexo.extend.filter.register('before_post_render', fn) affects the implementation of my idea.

My question is, is there a way to make Hexo render articles in a specific order, for instance, by sorting them based on their published dates?

Others

No response

warehouse has a sorting function

const posts = locals.posts.sort('-date').toArray();

more example:
https://github.com/search?q=repo%3Ahexojs%2Fhexo%20sort&type=code

warehouse has a sorting function

const posts = locals.posts.sort('-date').toArray();

more example: https://github.com/search?q=repo%3Ahexojs%2Fhexo%20sort&type=code

My question is not about the sort function. The issue is how to sort the post before the execution of the hexo.extend.filter.register('before_post_render', (post) => {}) hook, so that this hook can processes posts in a specific order. I haven't found a suitable event or hook to achieve this. It might not be possible at all—before_post_render could be concurrently executed. To determine this, one would need to examine the Hexo source code, as their documentation is poorly written.

I guess you shouldn't do that, the rendering of posts and pages is asynchronous.

I guess you shouldn't do that, the rendering of posts and pages is asynchronous.

Yes, perhaps the hook I chose is not suitable. I should randomize in another place. Do you know which hook can retrieve and modify all posts before rendering? I haven't found a suitable hook to accomplish this. It seems that getting the local variable 'post' in the event generateBefore only retrieves partial posts, not all of them.

hexo.extend.generator.register('post', function (locals) {} seems works.