Closed tomap closed 4 years ago
I've been looking forward to this feature for a long time. The earlier merged, the better.
By the way, I found some theme such as hexo-theme-next, hexo-theme-melody etc.
They had added sticky
style.
Maybe use sticky
replace priority
is ok?
The parameter config.index_generator.order_by
is ignored
The parameter
config.index_generator.order_by
is ignored
That's the intention.
note that if your posts have a `priority` property, it will be used to order your post taking precedence over `order_by`.
That's the intention.
note that if your posts have a
priority
property, it will be used to order your post taking precedence overorder_by
.
But how about posts with same priority? It does not match the description.
well, I just looked at the code again, and it is not what I intended... I was trying to reproduce the work of https://github.com/hexojs/hexo-generator-index/pull/6 But what we have here is something that will break the parameter config.index_generator.order_by in all cases, which is not good
I believe the configuration config.index_generator.order_by can be used to order by priority, if a priority has been defined on all posts What might be missing is a was to order by priority first, if there is a priority defined, it goes on top If not, the config.index_generator.order_by is used I'm not sure how to code that :)
Yes, the issue is: When two or more posts have the same priority
, the sorting should fall back to config.index_generator.order_by
, but not
if(a.priority == b.priority) return b.date - a.date;
But what we have here is something that will break the parameter config.index_generator.order_by in all cases, which is not good
@tomap I think you are talking about the stability of the sorting algorithm. Node.js 12+ uses stable sorting algorithms by default: https://v8.dev/features/stable-sort . Therefore, you can sort locals.posts
by config.index_generator.order_by
(e.g. '-date') first, and then sort locals.posts.data
according to the value of sticky
or priority
parameter. For older Nodejs versions, lodash
is required to implement this method.
@stevenjoezhang
can you create another PR with your patch? This PR has been inactive for a while...
cc @stevenjoezhang
@curbengh @SukkaW Superseded by https://github.com/hexojs/hexo-generator-index/pull/51
Bump minor, because there could be a minor change in behavior if some user already have a priority parameter on their posts
Based upon the work of #6