Make folder-index sort "really" ascending

I just realized, that in my icon overview list (don’t ask, won’t tell) there is this strange linux like sorting going on that sorts alphabetically ascending, but descending on the file name. A sample as image:

The code creating this layout is (unimportant stuff taken out):

{{ range resources.Match "libs/bootstrap-icons/*.svg" }}
    {{ .Content | safeHTML }}<!-- that's the icon -->
    {{ $name := substr (substr .Name 0 -4) 21 | lower }}
    {{ $name }}
{{ end }}

I think bar-chart-line should be before bar-chart-line-fill and so on in the subsequent sorting. There is no reason to sort “nothing” behind “-fill”.

I think this might be an issue of the underlying operating system (Ubuntu/Linux)

Is there any way to force a “proper” sorting on a resources.Match like this?

I think it’s sorting

line-fill.svg vs line.svg

not

line-fill vs line

Which would be consistent with:

{{ $foo := slice "aa" "a." ".a" "a.a" }}
<ol>
  {{ range sort $foo }}
  <li>{{.}}</li>
  {{ end }}
</ol>

generating

.a
a.
a.a
aa

Aaaah. right. that makes sense. I’ll guess I will have to do a scratch-substring-loop before ranging over them then first. And that’s probably why the file sorting in Linux is weird too.

Final code with “proper” sorting:

<dl class="row">
    {{ $scratch := newScratch }}
    {{ range resources.Match "libs/bootstrap-icons/*.svg" }}
        {{ $name := substr (substr .Name 0 -4) 21 | lower }}
        {{ $scratch.SetInMap "icons" $name . }}
    {{ end }}
    {{ $icons := $scratch.Get "icons" }}
    {{ range sort $icons }}
        <dt class="col-md-1 col-sm-2">{{ .Content | safeHTML }}</dt>
        {{ $name := substr (substr .Name 0 -4) 21 | lower }}
        <dd class="col-md-3 col-sm-4 text-truncate" title="{{ $name }}">{{ $name }}</dd>
    {{ end }}
</dl>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.