New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sorting with priority #2201
Sorting with priority #2201
Conversation
I noticed a typo which broke formatting (line 259), and while fixing that I tidied up some other bits.
Proofread: fix typos, grammar, markup
ignore=E501 | ||
ignore = E501 | ||
|
||
[easy_install] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete that
👍 from me Correct indentation: thing.sort(key=lambda p:
(int(p.meta('priority')) if p.meta('priority') else 0,
p.date, p.source_path)) |
There are some more places where posts are sorted, for example for tag pages, archives, ... Should these also respect priority? That would require some more changes. How about having the |
Is sorting things multiple times a good thing to do in the first place? |
Of course, you could also rewrite a lot of code to ensure that resorting isn't needed. Anyway, even if that is done, putting the sort key into a function of |
4ee60d2
to
e5f2ca4
Compare
Modified as suggested by @Kwpolska. @felixfontein, I agree with your idea. I'd definitively like to see the behavior of post sorting can be somehow customized. How do you plan to expose this functionality to users? Also via plugins? Since this commit is just a small change, you and @Kwpolska could adopt it as a temporary solution (with some TODO comments, if needed), but of course I'd like to see or implement a more elegant way of doing this. :) |
So, I don't know :-) @Kwpolska if you +1 this, let's merge it. I prefer not to have PR rot (and we have some already) |
As discussed with ChrisWarrick, nikola currently implements sorting in
nikola/nikola.py
instead of the separatedscan_posts
plugin. Since the "sticky posts" is a very useful and desirable feature (at least for CMS and blog sites), I guess the most direct and simple way is to extend the original sorting key:(p.date, p.source_path)
with an additional sorting key which can override the order. The problem is whether to directly inject the code intonikola.py
or try to move the sorting functionality to an individual plugin or toscan_posts
plugin. This PR demonstrates a possible way to incoporate intonikola.py
and it works without breaking the original behavior. Users can optionally use.. priority: 1
to make a post sticky (which means the default is 0). They can also use other number to give a finer order control.