Skip to content

Extend sort function to support semantic version numbers #9402

@alexlafreniere

Description

@alexlafreniere

We use Hugo to manage our documentation site. On this site, we provide documentation for various versions of software packages that are released according to semantic versioning rules. We list versions of the packages in descending order according to their version number for easy navigation. Today, Hugo has no direct support for sorting by semver, so we settle for sorting by the date the version was released. This is less than desirable in the situation where we are actively maintaining more than one major or minor version at a time, resulting in seemingly unsorted lists of versions for our users.

On a stale PR attempting to implement sorting of semver numbers, @jmooring suggested extending the sort function to support this functionality. Implementing sorting in this way would avoid breaking existing sites and allow sorting any resource by any front matter field according to semver conventions:

{{ range (sort .Pages "Params.version" "semVerAsc" ) }}
{{ range (sort .Pages "Params.version" "semVerDesc" ) }}

I'm unfamiliar with the Hugo codebase, but would be more than happy to perform the implementation once the design proposal is finalized and accepted by the Hugo maintainers. My initial survey of the source suggests most changes would center around tpl/collections/sort.go, but a nudge in the right direction from more experienced contributors would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions