This is an automated email from the ASF dual-hosted git repository. zregvart pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-website.git
commit 3e69a8b0a30368f83d8a619ac411082a9b7a783d Author: Zoran Regvart <[email protected]> AuthorDate: Fri May 21 10:05:59 2021 +0200 fix: semantic version sorting Previously we used the provided sorting functionality that sorted by `version` parameter as a string. This wrongly sorts 3.10 after 3.9. This implements semantic version sort in `releases/version_sort.html` partial. --- layouts/partials/releases/downloads.html | 6 +++--- layouts/partials/releases/version_sort.html | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/layouts/partials/releases/downloads.html b/layouts/partials/releases/downloads.html index 6722f31..fe98912 100644 --- a/layouts/partials/releases/downloads.html +++ b/layouts/partials/releases/downloads.html @@ -16,13 +16,13 @@ {{ range $kind := $.Category.kinds }} {{ if eq $kind.filter "latest" }} - {{/* there can be only single latest version, and we sort by version (as strings!) to find it, there could be newer by date versions that are not the latest, e.g. patching a legacy or lts release */}} - {{ $released_versions := ($category_releases.ByParam "version").Reverse }} + {{/* there can be only single latest version, and we sort by version to find it, there could be newer by date versions that are not the latest, e.g. patching a legacy or lts release */}} + {{ $released_versions := partial "releases/version_sort.html" ($category_releases.ByParam "version") }} {{ $version := (index $released_versions 0).Param "version" }} {{ $versions = $versions | append (dict $kind.name $version) }} {{ else }} {{/* non-latest versions we need to sort by date of release */}} - {{ $released_versions := ($category_releases.ByParam "date").Reverse }} + {{ $released_versions := partial "releases/version_sort.html" ($category_releases.ByParam "date") }} {{ if $kind.last }} {{/* we need to feature more than one of this kind: 0..last - 1*/}} diff --git a/layouts/partials/releases/version_sort.html b/layouts/partials/releases/version_sort.html new file mode 100644 index 0000000..cb7692e --- /dev/null +++ b/layouts/partials/releases/version_sort.html @@ -0,0 +1,20 @@ +{{/* sorts given pages according to the semantic version */}} +{{/* array containing map with 'version_num' - the numbered version, and 'page' - the page */}} +{{ $versions := slice }} +{{ range . }} + {{/* version from the page front matter, a string */}} + {{ $version := .Params.version }} + {{/* version as number, e.g. 1.2.3 -> 100020003 */}} + {{ $version_num := 0 }} + {{ range $version_part := split $version "." }} + {{ $version_num = add (mul $version_num 1000) (int $version_part) }} + {{ end }} + {{ $versions = $versions | append (dict "version_num" $version_num "page" .) }} +{{ end }} +{{/* array of sorted pages */}} +{{ $sorted := slice }} +{{/* sort by version_num and collect only pages */}} +{{ range $val := (sort $versions "version_num" "desc") }} + {{ $sorted = $sorted | append (index $val "page") }} +{{ end }} +{{ return $sorted }}
