eleventy-navigation
eleventy-navigation copied to clipboard
change sorting
allow better sorting. pages that have an order command are now always first, not last. this will fix #1
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.
@zachleat Can you please merge?
@zachleat, can you please merge? I heavily depend on this PR and the upcoming release :)
@zachleat Please merge this ASAP as I need this in my project. Thanks
It'd be great to see this merged!
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.
@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?
@zachleat @binyamin Please!
I don't have write access to this repository. Sorry.