Implementation of page/post sorting via optional weight meta-data.#134
Implementation of page/post sorting via optional weight meta-data.#134TheCodeKing wants to merge 1 commit intoplusjade:jb-developmentfrom TheCodeKing:jb-development
Conversation
|
Looks like a useful feature! Is there any way to sort the navigation bar? e.g. I'd like the order to be Blog, Pages, blabla Thanks! |
|
Hi, Yes that's what the patch does. If you add a weight property to your posts/pages then they will be sorted whenever using the JB/pages_list include. I'm actually using this to control the order on my navigation items. It's not the most elegant solution, but I couldn't find an obvious way to achieve this with liquid. Mike |
|
Hi Mike, I merge your commits into my repo. Works well. Nice job! Your current implementation loops over 100 to 0:
I've not studied the directives but I'd like to know, is there equivalent functions like sorting? If so, the prioritisation logic can be upgraded. I noticed that the blog posts in archive page is sorted in reverse chronological order. They must have similar mechanism. |
|
Yes it's not ideal. I'm not very familiar with Liquid or Jekyll, but this seemed the only option based on the limited time I spent on it. There doesn't seem to be a working sort function. Perhaps I need to dig into posts implementation and see how that's done. I don't use them on my site and just wanted a way to order my nav items. I'm not too worried about the 100 for loop as it's a static site generator and it all happens offline. It's also pretty quick, but yes doesn't scale and offers limited functionality. Probably better for pages than posts. |
|
I used this patch to manage my navigation bar for some days. It's working but the page generation speed is low. I finally disabled the feature. The generation time falls down from about 10s to less than 1s. In order to manage the order of navigation bar, I manually write the I don't have other sorting demand besides navigation bar management. How about you? @TheCodeKing If only for navigation bar management, I would suggest the new way I just demoed. I have a kind of OCD to re-generate while writing. That's why re-generation speed is also crucial for me.. :).. BTW, this pull request also served as my studying material for Liquid! Nice commit. |
|
I only use it for top level navigation and speed is not a concern. You could always reduce the loop from 100 to 10 depending on the size of your menu to increase speed, but sounds like you have a solution. |
Implementation of optional 'weight' meta-data to influence ordering when listing pages/posts. Weight is set on pages/posts to a value of between 0 and 100, where 100 is the highest priority and will appear first in the list. Items without weight value default to same priority as items with 0 weight, and appear last in the list.