fix(lazyimg): normalize config dict in partial instead of shortcode

- move normalization of provided config dictionary keys to lower case
from shortcode to partial
- allows using any case when supplying config dict from other layouts
This commit is contained in:
kdevo
2021-10-30 11:21:31 +02:00
parent 0efce069c3
commit 45b704ebdb
2 changed files with 8 additions and 8 deletions
+7 -2
View File
@@ -17,7 +17,12 @@
"renderer" (default "lqip" site.Params.lazyimg.renderer)
)}}
{{ if reflect.IsMap . }}
{{ $params = merge $params . }}
{{ $userParams := . }}
{{/* Normalize by transforming all keys to lower-case: */}}
{{ range $k, $v := $userParams -}}
{{ $userParams = $userParams | merge (dict (lower $k) $v) }}
{{- end -}}
{{ $params = merge $params $userParams }}
{{ end }}
{{ $resType := (printf "%T" $params.img) }}
{{ if not (in $resType "resource") }}
@@ -31,7 +36,7 @@
{{/* Special handling for WebP renderers: */}}
{{ if in $params.renderer "webp" }}
{{/* Override user-supplied target format */}}
{{ $resizeOptionsWebP := printf "%s webp" ($params.resizeOptions | replaceRE "(jpg|png|tif|bmp|gif)" "") }}
{{ $resizeOptionsWebP := printf "%s webp" ($params.resizeoptions | replaceRE "(jpg|png|tif|bmp|gif)" "") }}
{{ $paramsWebP := merge $params (dict "resizeoptions" $resizeOptionsWebP) }}
{{ $imagesWebP := partial (printf "resizer/%s" $params.resizer) $paramsWebP }}
{{ $imagesRegular := partial (printf "resizer/%s" $params.resizer) $params }}
+1 -6
View File
@@ -1,10 +1,5 @@
{{ if .IsNamedParams -}}
{{ $params := dict }}
{{/* Normalize by transforming all keys to lower-case: */}}
{{ range $k, $v := .Params -}}
{{ $params = $params | merge (dict (lower $k) $v) }}
{{- end -}}
{{ partial "lazyimg" $params }}
{{ partial "lazyimg" .Params }}
{{- else -}}
{{ partial "lazyimg" (.Get 0) }}
{{- end }}