-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
Blog posts page: custom sorting logic #5692
Comments
Yes we can add that option. Just curious if someone came up with more concrete needs? Does it mean that we'll never add something like a "year separator" in the paginated view? |
This has been requested two / three times on Discord but... they didn't provide a use-case🤦♂️ I was just dumping all sane feature requests that I saw on Discord :P
If that's actually on the roadmap (I never saw a feature request for that anyways), then yeah, it won't make much sense otherwise. One use-case I can think of is the blog plugin being used for more general-purpose content posting, like Trello or as an online wiki🤪 |
I'd like to create a plugin for myself to create a digital garden / second brain / Zettelkasken / Obsidian / Roam Research / whatever you name it for interconnected thoughts and public note-taking. I'm not sure it makes sense to try to adapt the blog plugin to this use-case, maybe a new separate plugin could be a better idea? |
Do you see the option here more as some enumerated option (alphabetic/chrono etc.) or rather the lambda for sorting function should be provided? |
As a function. We are providing an API anyways, and by Sebastien's philosophy we should make it as general-purpose as possible. |
@cerkiewny This is the FR that I would actually think twice before rushing to implement. It's trivial to add, but is it really worth it? I'm only putting it up for RFC purposes and to remind myself that there's a possible feature, but overall I don't see a strong use-case and I agree with @slorber that this may hinder us from building features that assume chronological ordering of posts and that other use-cases of the blog can be realized with another plugin |
Also, these days I'm not really a fan of having heavyweight callbacks as API just for more freedom of customization🤷♂️ This applies to |
I don't think it is quite as easy to add as another plugin, you have the contextual "next" and "previous" generation for the blog posts, which would be really awkward if they were sorted differently to the plugin sorting. I don't have strong feelings about this feature, and I would personally add something looking more like enum:
My feeling is that the only strong use case here is reversing the order from oldest to newest |
Agree, we should rather just provide a way to reverse the order for now, but think about keeping the API extensible just in case.
What about That would match the name of the widely used Lodash orderBy (https://lodash.com/docs/#orderBy) and we could later eventually provide other presets and multi-criteria ordering. Note we have a |
I can add my vote here. I've been trying to find a way to do this because I'm using the blog part of the site as a personal portfolio. The sidebar list is especially useful for that purpose (though I wish it were more fully featured / adjustable like the docs one) except that I can't sort by anything. I'd like to be able to do alphabetical, and I'd love love to let people filter by tags. I've tried swizzling the and similar components to do something like this but honestly it's too hacky. |
@certainlyNotHeisenberg about displaying the tags in sidebar, check this issue: #5461 It's not clear to me what you want to use the blog with an alphabetical order. Why not use docs or regular pages for your portfolio? |
Thanks @slorber. Alphabetical order was just an example — really I just mean, like the others said, that it'd be nice to have more natural control over the ordering. I considered using docs or pages, and I think those could work fine. There are just slight feature differences between them, so I tried to pick the best fit that wouldn't require lots of swizzling (which the documentation pretty strongly warns against doing) and the blog option seemed the best |
If you could put a |
@factoidforrest can you explain the use-case for this? What concrete problem are you trying to solve? |
Also if you could explain how it would work with combination with sorting? Would that override the sorting and shuffle something in always at position 3? Would you need to specify order of all items in that case? Do you want to just make sure that some items are first in the order? @factoidforrest |
@slorber Well, we sometimes produce multiple blog posts per day, and it would be nice to individually control their position. Or sometimes we have something REALLY important and we want to stick it to the top. We recently did the blog post about log4shell which is why this is coming up. https://www.lunasec.io/docs/blog/log4j-zero-day/ @cerkiewny I think that's all open to debate, but if you want to see a project with inspiring document sorting (that works with docusaurus), you can check out typedoc https://typedoc.org/guides/options/#sort For the manual position override, the way I would write the code is:
That way people can manually move things around when they need to, but still keep the default behavior most of the time. |
In this case, you can use the date frontmatter to specify a time:
Would you use IMHO what we are looking for here is rather a way to "pin" a blog post at the top (similar to GitHub issues somehow). It's also a common pattern among bloggers to have featured posts, and drive more attention to specific articles: We could allow a plugin option to feature a list of posts, put them at the top, and maybe also add them to the blog sidebar to make them accessible from all blog pages. Using Using something like If this position is only applied inside a single day, it would be a quite unintuitive option, and using an hour in frontmatter can be enough. |
So I've hit a need for this where we have multiple posts on the same day which aren't ordering correctly. There are a few options that would help - allow the date sorting to support date/time. Or allow weight. I'm aware position has been discussed - weight in my eyes is different. Position is "absolute" whereas weight nudges within the existing sort criteria - lighter items float, heavier ones sink. So two posts with the same dates - their final order would be determined by their weight. I can also see real benefit in |
@homotechsual ---
date: 2019-06-07T20:00
--- |
This is beautiful information, I'll raise a PR for the API docs to make it clearer that this handles datetime :-) thanks! As for featured - I'll get an FR in for that! |
Is anyone using custom sorting logic (ie "ascending"?) Do you expect the RSS feed to be in ascending order too? 🤔 Asking for #9827 (comment) We are looking to implement a sort function config (#9840) but it's not clear how this should impact the order of the RSS feed. I feel that the order of the feed should rather be chronological (descending) by default in any case, but that's not how the I never met anyone using this feature in practice so I'm not sure what users expect. Is anyone even using this feature? 😅 |
Not using custom ordering at present but agree that the RSS feed should maintain chronological ordering but perhaps be configurable separately from the display ordering. |
Such custom logic is proposed for sites with historical posts, tagged with past event dates: One example of such site is:
Fully agree. The feed order should be decoupled from the post order. And if the blog posts will be enhanced to support lastUpdateTime (#9826), my preference is to order the feeds by lastUpdateTime too. |
I don't think this one is a reasonable default. Many blogs have last update time and keep their feed in chronological order. As a curator myself and heavy RSS user through my newsletter (https://thisweekinreact.com), I really dislike when authors order their feed by last update date, because it notifies me of changes I'm not interested to know about. By chance, it doesn't happen often. |
We use a blog for our product updates/release notes, with a separate Markdown file for each product. We use the RSS feature, which involves changing the Is it possible to prevent files with the latest date from moving to the top of the list? |
@mhowes-veracode we have features to give you full control:
|
🚀 Feature
Let's be less opinionated and let users decide on the sorting logic.
Have you read the Contributing Guidelines on issues?
Yes
Has this been requested on Canny?
Requested on Discord
Motivation
Sorting by descending time works in almost all cases, but we shouldn't assume that all users use the blog for time-based information. E.g., sort by alphabetical order? Sort by tags?
API Design
A new
comparePosts
plugin option, which accepts a function that is passed to the sorting algorithm:docusaurus/packages/docusaurus-plugin-content-blog/src/blogUtils.ts
Lines 345 to 347 in b40e459
And yes, it will receive the entire blog post, with all of its metadata and content.
Have you tried building it?
No; should be trivial
The text was updated successfully, but these errors were encountered: