-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Add sortSidebarByLastUpdate
to blogs to change the order in the sidebar
#9827
Comments
What about enabling users to provide a sort function instead? That would be more flexible and enable to sort on any attribute or frontMatter. Also, doesn't it make sense to have the sidebar and the blog pagination be in the same order anyway? |
I experimented with various conflicting solutions, and did not like any of them. My conclusion was that a single order is not enough, and I currently use two, one using the event dates and one using the last update time. |
You'll have to convince me and explain this in greater detail so that we can reach the same conclusion. Please create a docusaurus.new repro with 3 blog posts including representative metadata and front matter, and the desired order (or mockups) for each component/page rendering them |
Before me taking the time to learn how to use this new tool, can we first decide if my understanding of ordering is realistic? Assuming blog posts have the lastUpdateTime (if they don't, fallback to using the creation time):
Assuming articles have a chronological order (by event date for blogs with historical content, with fallback to creation date for usual blogs):
Please note that without event dates and without lastUpdateTime, these two cases collapse into one single case, using the creation date order. |
One small advice, if you allow me: when you suggest someone to use docusaurus.new, could you add a link to that site? You constantly asked me to use it, but I had no idea what it is. Only recently, while working on my fork, I bumped onto the documentation page referring to it; I totally missed it while reading the project web documentation. :-( |
Thanks to function sortBlogPostsForFeed(blogPost){ {
// Order the blog post items the way you want here
}
const feedOptions = {
createFeedItems: async (params) => {
const {blogPosts, defaultCreateFeedItems, ...rest} = params;
return defaultCreateFeedItems({blogPosts: sortBlogPostsForFeed(blogPosts),...rest);
},
};
We already have a If we extended it to allow a custom sort function instead of just 2 static sorting presets, you'd be able to sort by That would also impact the default order of your feed, which shouldn't be a problem considering you can change the order with the solution above if you need something different. That would also impact the sidebar post order, which you can override through swizzle if you want to use another order.
I don't know, what else could we do anyway? It doesn't make sense to group them by last update date for example 🤷♂️ In any case you can swizzle this component. We group things, but you don't even have to group if you want and can keep a flat list of posts in the order you want.
The posts are linked in the order we define thanks to the We don't care about the "chronology" technically, and can focus on having a consistent UX: if a paginated view has
Sorry it's GitHub refusing to autolink It leads to a browser sandbox with a newly initialized site that you can customize, save and then share with me a runnable url easily. This is much better for me because I'm able to run your code/attempt in isolation, on something minimal, by simply clicking a link. Running a GitHub repo is usually more time consuming. It's also important for my own security because it's not super safe to run sites of others without double-checking there's no malicious intent to hack me in it. When someone provides a GitHub repro, I usually first try to run in StackBlitz by adding |
I understand that now the feed order is the same as the paginated list order, but the question was different. I rephrase: assuming we add lastUpdateTime to the blog, and the user enables it, shouldn't the default feeds order be based on the lastUpdateTime? (without the user having to redefine the In my opinion the feeds order should always be chronological, regardless of a possible custom order for the paginated posts (like the event dates). Otherwise, if I understand you right, your solution is to add a custom sort function via |
I don't think it should be the case.
Yes, that seems a reaonable thing to do, and people can override that order anyway. But changing that default order is a breaking change, that we can only do for Docusaurus v4. People using |
Have you read the Contributing Guidelines on issues?
Description
When
showLastUpdateTime
is enabled, it also makes sense to show the updated posts in the top of the sidebar list.Has this been requested on Canny?
No response
Motivation
When editing older posts, it is useful to give users an indication that posts have been modified recently.
API design
To control this new feature add an
sortSidebarByLastUpdate
option when set to true, the sidebar list is sorted by the last update time, when available.Have you tried building it?
The functionality is implemented in cronica-it@1f21464.
Self-service
The text was updated successfully, but these errors were encountered: