eleventy-navigation icon indicating copy to clipboard operation
eleventy-navigation copied to clipboard

change sorting

Open mstenz opened this issue 3 years ago • 9 comments

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

mstenz avatar Aug 18 '21 23:08 mstenz

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 avatar Aug 19 '21 13:08 mstenz

@zachleat Can you please merge?

mstenz avatar Feb 01 '22 09:02 mstenz

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

hesselamann avatar May 24 '22 06:05 hesselamann

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

dtucker50 avatar Jun 28 '22 14:06 dtucker50

It'd be great to see this merged!

mrtnmgs avatar Apr 25 '23 15:04 mrtnmgs

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 avatar Apr 25 '23 17:04 mrtnmgs

@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?

antgel avatar Aug 01 '23 15:08 antgel

@zachleat @binyamin Please!

Dexus avatar Sep 12 '23 13:09 Dexus

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

binyamin avatar Sep 12 '23 17:09 binyamin