Skip to content

change sorting #32

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

Closed
wants to merge 3 commits into from
Closed

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

mstenz added 3 commits August 19, 2021 01:26
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

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

@zachleat
Copy link
Member

Went with a simpler approach here that only required modification of the sort method in one spot. The fix for #1 will ship with Navigation 1.0.0

@zachleat zachleat closed this Mar 19, 2025
@zachleat zachleat added this to the Eleventy Navigation 1.0.0 milestone Mar 19, 2025
zachleat added a commit that referenced this pull request Mar 19, 2025
@zachleat
Copy link
Member

Correction: the correct fix for this has shipped with Navigation v1.0.1

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
8 participants