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

Support Sorting by Multiple Attributes #938

Open
stellarpower opened this issue Oct 11, 2024 · 2 comments
Open

Support Sorting by Multiple Attributes #938

stellarpower opened this issue Oct 11, 2024 · 2 comments

Comments

@stellarpower
Copy link

Hi,

I've got a list of posts. When I publish our site, we just use the day, I don't keep a full timestamp in the frontmatter, as we don't want to present it to the user.

This therefore means that when there is more than one post on a given day, the order of posts isn't fully defined, and so I get spurious changes in my commits for the HTML, which are a bit distracting when I'm making important changes to the templates etc. as I try to keep each one granular.

So far I am using a simple loop:
for page in allPages | sort(attribute="date") | reverse
What I'd like to propose is the possibility to sort a hashmap on multiple keys - so that it'll be sorted on the first, then any that have identical values for the first key, they'll be compared using the next key, etc.:
for page in allPages | sort(attribute=["date", "title"]) | reverse

This way I can use my date as the primary criterion and still have a means to stop them from jumping around in the list. Currently I can think of a few ways to work around, but if folks agree, feels like it'd be a nice feature to add. Thoughts?

Thanks

@Keats
Copy link
Owner

Keats commented Oct 11, 2024

It could be added, but I wouldn't add it to v1. This filter still needs to be rewritten for v2 so it could be good candidate for improvement

@stellarpower
Copy link
Author

Yep, for sure. Opened a specific FR as it felt more of a change to an existing feature than a hypothetical "wishlist" sort of thing, but of course add it to the next version, and I've got my workaround with group-by in the meantime.

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

No branches or pull requests

2 participants