Skip to content

Please make Taxonomy.ByCount produce a stable ordering #14095

@mikenakis

Description

@mikenakis

From discourse.gohugo.io

The TL;DR:

Please make Taxonomy.ByCount sort first by count, then by name, so as to produce a stable ordering.

The long form:

I have placed hugo’s destination directory in a github repository so that each time I make changes to the source files I can see their effect on the destination files.

For this to work well, it is important that there be no spurious changes in the destination files. By “no spurious changes” I mean that two successive hugo builds on an identical set of source files should produce identical sets of destination files.

As things stand right now, there are some sources of spurious changes that I am struggling with, for example some unnecessary updates to some modification dates, and the Pager 2 weirdness. But these are another story.

One source of spurious changes that I suppose could easily be fixed is the way the Taxonomy.ByCount method works.

As it stands, this method works as intended, but here is the problem:

If I remove a tag, and then add that tag back, then within a group of tags with the same count, some tags may be re-ordered. In other words, the method does not produce a stable ordering.

I suppose that this is happening because the method just sorts on count, but count is not unique, so sorting on count alone gives an unstable ordering.

To fix this, the method should perform sorting using a complete set of keys.

A complete set of keys would be, I suppose, the count followed by the name. This way, items that have the same count would be sorted alphabetically within that count, thus producing a stable ordering. (I suppose two items better not have the same name, or if they do, then it is their fault, not hugo’s fault.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions