gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.88k stars 7.54k forks source link

Bring "case insensitive" sorting to Hugo #5661

Closed regisphilibert closed 5 years ago

regisphilibert commented 5 years ago

It is currently not possible in Hugo to sort things in a "CMS" sensible way due to sorting being case sensitive.

For ex:

{{ range sort (slice "Apple" "aSomething" "Zoo" "Gravy") }}
{{ . }}<br>
{{ end }}

will output:

Apple
Gravy
Zoo
aSomething

Same with .ByTitle etc...

I personally can't think of a sorting use case where case sensitivity has value, but this does not matter much if we're facing a Go limitation as the following threads imply.

https://discourse.gohugo.io/t/sort-posts-by-title-case-insensitive/6076 https://discourse.gohugo.io/t/sorting-posts-by-title-case-insensitive/2413

Though maybe some has changed since then and this behaviour could now be aligned with the majority of content sorting use cases' need.

bep commented 5 years ago

"CMS" sensible way

What do you mean by this? Does it take language into account?

regisphilibert commented 5 years ago

What do you mean by this? Does it take language into account?

I mean the way we often sort content. It takes into account languages using cases I guess, which excludes a lot non-european languages.

But if the point is we should have both ways of sorting, then by all means yes!

But I think many users need "case-insensitive sorting" in Hugo, and that's why I started this issue. I would also push for this being default but only by instinct and experience.

bep commented 5 years ago

But if the point is we should have both ways of sorting, then by all means yes!

I think we need to take this in (baby) steps. We need to properly integrate timezone/locale and with that string collation, but that is a bigger task. Implementing string sorting using unicode case folding would definitively be an improvement. So we start there.

bep commented 5 years ago

I assigned this to myself. I have a sketchy implementation somewhere -- but I need to wait until I get my refactoring branch merged (I have moved the page sorting to a different package).

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open. If this is a feature request, and you feel that it is still relevant and valuable, please tell us why. This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.