Skip to content
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

change sorting #32

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

change sorting #32

wants to merge 3 commits into from

Conversation

mstenz
Copy link

@mstenz mstenz commented Aug 18, 2021

allow better sorting. pages that have an order command are now always first, not last.
this will fix #1

allow better sorting. pages that have an order command are now always first, not last.
make sorting even better:
- not only numeric but also alphabetic sorting
- elements with an order are the first ones listed
- backwardscompatibilty with 'order: 0' (exluded from priorization)
@mstenz
Copy link
Author

mstenz commented Aug 19, 2021

I am no javascript specialist. hope the code change is fine. i am aware that maybe the syntax can be made easier, but I don't know how this can be done. I have tested everything on my local environment and it looks fine and do what it needs.

@mstenz
Copy link
Author

mstenz commented Feb 1, 2022

@zachleat Can you please merge?

@hesselamann
Copy link

@zachleat, can you please merge? I heavily depend on this PR and the upcoming release :)

@dtucker50
Copy link

@zachleat Please merge this ASAP as I need this in my project. Thanks

@mrtnmgs
Copy link

mrtnmgs commented Apr 25, 2023

It'd be great to see this merged!

@mrtnmgs
Copy link

mrtnmgs commented Apr 25, 2023

Here's a filter to sort by name if anyone needs it. It ignores order, if you need that look at @mstenz code in the MR.

  eleventyConfig.addFilter("sortByName", function (arr) {
        return arr.slice().sort((a, b) => a.title.toLowerCase().localeCompare(b.title.toLowerCase()));
  });

usage: {{ collections.all | eleventyNavigation | sortByName }}
note: the slice() here is to avoid mutating the output of eleventyNavigation as I don't know if it could have undesirable side effects. It ensures the sorting only affects the rendered list.

@antgel
Copy link

antgel commented Aug 1, 2023

@mrtnmgs That was a really useful snippet given that there is no response to this PR for a couple of years so thank you! May I ask, how did you work on it? Just dump the output of eleventyNavigation, or did you dive into the source code?

@Dexus
Copy link

Dexus commented Sep 12, 2023

@zachleat @binyamin Please!

@binyamin
Copy link
Member

I don't have write access to this repository. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change default order sort
7 participants