From 02356ab5fb5cf7ce9ff4cdf43ec8d478729cafe9 Mon Sep 17 00:00:00 2001 From: Alexander Apalikov Date: Fri, 15 Mar 2019 17:11:43 +0300 Subject: [PATCH] Fix feature shortcode for Hugo Algorithm for splitting string by dots and comparing major, minor version one by one separately. There is no break statement for range loop, that's why added special handling for that case. --- site/layouts/shortcodes/feature.html | 32 +++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/site/layouts/shortcodes/feature.html b/site/layouts/shortcodes/feature.html index 3616ec9609..32859b8ae2 100644 --- a/site/layouts/shortcodes/feature.html +++ b/site/layouts/shortcodes/feature.html @@ -1,6 +1,36 @@ {{- $version := getenv "RELEASE_VERSION" | default $.Page.Site.Params.release_version }} {{- $publishVersion := (.Get "publishVersion" ) | default "0.0.0" }} {{- $expiryVersion := (.Get "expiryVersion") | default "9999.0.0"}} -{{- if and (ge $version $publishVersion) (lt $version $expiryVersion) }} +{{- $publDigits := split $publishVersion "." }} +{{- $curDigits := split $version "." }} +{{- $expDigits := split $expiryVersion "." }} +{{- $multiplier := 10000 }} +{{- $current := 0}} +{{- $publish := 0}} +{{- $expire := 0}} +{{- $index := 0}} + +{{/*Generate initial shift for most significant number*/}} +{{- $shift := 1 }} +{{- range $curDigits}} + {{- $shift = mul $shift $multiplier }} +{{- end}} +{{- $shift = div $shift $multiplier }} + +{{/* loop three times */}} +{{- range $curDigits}} + {{/* Get integer from dot separated string at index */}} + {{- $c := int (index $curDigits $index)}} + {{- $p := int (index $publDigits $index)}} + {{- $e := int (index $expDigits $index)}} + {{/* current += digit * shift */}} + {{- $current = (add $current (mul $c $shift ))}} + {{- $publish = (add $publish (mul $p $shift ))}} + {{- $expire = (add $expire (mul $e $shift ))}} + {{- $shift = (div $shift $multiplier)}} + + {{- $index = (add $index 1) }} +{{- end}} +{{- if and (ge $current $publish) (lt $current $expire) }} {{.Inner}} {{- end}} \ No newline at end of file