Hugo

Ordering tags chronologically & by postcount

Hello all,

I’ve been trying to built a navigation menu for my (photo)blog (repo here). I have the correct (working) tags, but I can’t seem to figure out how to order and limit them like I want.

Right now, I have a partial that reads as follows:

<nav class="nav">
    <ul class="series">
<!-- Range over series -->
        {{ range $name, $taxonomy := .Site.Taxonomies.series }}
        <li><a href="/series/{{ $name | urlize }}">{{ $name }}</a></li>
        {{ end }}
    </ul>

    <ul class="tags">
<!-- Range over top 5 tags -->
        {{ range $name, $taxonomy := .Site.Taxonomies.tags }}
        <li><a href="/tags/{{ $name | urlize }}">{{ $name }}</a></li>
        {{ end }}
    </ul>
</nav>

How would I go about ordering these? Sorting the series chronologically (the newest series first) and the tags by (the five) most used ones?

There is the sort function to start with:

You can also access Taxonomies already sorted by name or count (ASC/DESC)

No guarantees and untested, but I would start with these

{{ range $index, $var := (sort .Site.Taxonomies.series "Count") }}
{{ range $index, $var := (first 5 (sort .Site.Taxonomies.series "Count")) }}

Thanks for the tips!

They didn’t seem to work (or I didn’t get them to), but I found another solution.

To limit my list of tags by the most used ones, I used the following code:

{{ range (first 5 $.Site.Taxonomies.tags.ByCount) }}
<li><a href="/tags/{{ .Name | urlize }}">{{ .Name | humanize }}</a></li>
{{ end }}
2 Likes