Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Implementation of page/post sorting via optional weight meta-data. #134

Open
wants to merge 1 commit into
base: jb-development
Choose a base branch
from
Open

Implementation of page/post sorting via optional weight meta-data. #134

wants to merge 1 commit into from

Conversation

TheCodeKing
Copy link

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.

@hupili
Copy link

hupili commented Mar 22, 2013

Looks like a useful feature!

Is there any way to sort the navigation bar?

e.g.

http://hupili.github.com

I'd like the order to be Blog, Pages, blabla

Thanks!

@TheCodeKing
Copy link
Author

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

@hupili
Copy link

hupili commented Mar 22, 2013

Hi Mike,

I merge your commits into my repo. Works well. Nice job!

Your current implementation loops over 100 to 0:

  • Not extensible if one has more than 100 pages to prioritise.
  • For every weight, Jekyll checks every pages. Although it works well for my small number of pages. I don't know how scalable it is.

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.

@TheCodeKing
Copy link
Author

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.

@hupili
Copy link

hupili commented May 2, 2013

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 href and name in _config.yml. commits

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.

@TheCodeKing
Copy link
Author

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.

@groundh0g groundh0g added this to the v 0.5.0 milestone Apr 4, 2015
@groundh0g groundh0g self-assigned this Apr 4, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants