And here’s the final-final iteration… much lighter than the earlier version, and it will also be easy to replace it with the inbuilt ge
, le
comparisons in future.
Partial version_str2float.html
{{- $ver_major_minor := (float (replaceRE "([0-9]+\\.[0-9]+).*" "${1}" .)) -}}
{{- $ver_micro_str := (replaceRE "[0-9]+\\.[0-9]+(.*)" "${1}" . | replaceRE "-DEV" "-0.01") -}}
{{- $ver_micro := (div (float (or $ver_micro_str "0")) 100.00) -}}
{{- $ver_float := (add $ver_major_minor $ver_micro) -}}
<!-- "Return" value -->
{{- $ver_float -}}
Example Use
{{ if (ge (partial "version_str2float.html" .Hugo.Version) 0.36) }}
{{ printf "curr >= 0.36<br />" | safeHTML }}
{{ else }}
{{ printf "curr < 0.36<br />" | safeHTML }}
{{ end }}
Future
In future, once version 0.37 is old enough, simply remove the partial wrapper.
So (partial "version_str2float.html" .Hugo.Version)
becomes just .Hugo.Version
, and things will “just work”.