Closed tylersticka closed 6 years ago
@tylersticka I'm fine with using negative values, but I'd like to consider a few things:
Because we now have helpers that can sort by any property, we might want to focus on creating a common sorting function that possesses the logic to infer default values (e.g. 0
) and that isn't limited to just properties named "order".
Also, here's the library used by the helpers: https://github.com/bubkoo/natsort
I know, I know, I've already talked a ton about this in cloudfour/drizzle-builder#31. But it's still not working the way I'd like it to, and I thought I'd document that (even if it has to wait for a future version to be resolved).
The Problem
Here's a hypothetical collection of patterns:
By default, these will show up in the same order as above... whatever the file system determines "alphabetical" means for these files.
Let's say I want "Overview" to be the first pattern. Currently, that's really easy. I just add the property to my Frontmatter:
And the order changes:
Simple.
But what if I want a pattern to sort to the end?
For example, maybe the
group
pattern should go after all of the patterns pertaining to individual instances.Currently, that would require that I specify an order for every file:
Alternatively you could give everything after
overview
the sameorder
value. But you'd still have to specify for every single pattern, as any pattern lacking anorder
property will show up after everything else.My Recommendation
This use-case is why I recommended (and prototyped) that we mimic the CSS
order
property in structure. Specifically its initial value of0
.Having an initial value means negative numbers show up earlier than the default, positive numbers show up later.
This means you'd only need to specify the
order
property for the patterns you wanted to move, regardless of which direction they moved...It also seems intuitive given our target audience to make our
order
property behave in a manner similar to anorder
property they're familiar with.