Skip to content

Commit

Permalink
fix: rename the images site parameter to hugomods.images
Browse files Browse the repository at this point in the history
Fixes #26
  • Loading branch information
razonyang committed Nov 8, 2023
1 parent 65f5c41 commit 92a8e32
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion hugo.toml
@@ -1,7 +1,7 @@
[module.hugoVersion]
min = "0.119.0"

[params.images]
[params.hugomods.images]
class_name = "img-fluid"
alignment_center_class_name = "d-block text-center"
alignment_start_class_name = "float-start me-2"
Expand Down
18 changes: 18 additions & 0 deletions layouts/partials/images/functions/params.html
@@ -0,0 +1,18 @@
{{- $default := dict
"class_name" "img-fluid"
"alignment_center_class_name" "d-block text-center"
"alignment_start_class_name" "float-start me-2"
"alignment_end_class_name" "float-end ms-2"
"figure_class_name" "figure"
"figure_caption_class_name" "figure-caption"
"figure_image_class_name" "figure-img"
"modern_format" "webp"
}}
{{- $params := default dict site.Params.hugomods.images }}
{{- with site.Params.images }}
{{- if reflect.IsMap . }}
{{- warnf "[images] please rename the images site parameter to hugomods.images, since it's conflict with some internal templates, see https://github.com/hugomods/images/issues/26." }}
{{- $params = . }}
{{- end }}
{{- end }}
{{- return merge $default $params }}
19 changes: 10 additions & 9 deletions layouts/partials/images/image.html
Expand Up @@ -9,8 +9,9 @@
{{/* - Style : additional inline style for <img> tag. */}}
{{- $formats := slice "bmp" "jpeg" "jpg" "png" "tif" "tiff" "webp" }}
{{- $modernFormat := "webp" }}
{{- if isset site.Params.images "modern_format" }}
{{- $modernFormat = site.Params.images.modern_format }}
{{- $siteParams := partialCached "images/functions/params" . }}
{{- if isset $siteParams "modern_format" }}
{{- $modernFormat = $siteParams.modern_format }}
{{- end }}
{{- $lazyLoading := default true .LazyLoading }}
{{/* Parse the image filename. */}}
Expand All @@ -25,7 +26,7 @@
{{- $originalSrc := "" }}
{{- $alt := default "" .Alt }}
{{- $caption := default "" .Caption }}
{{- $className := default (default "img-fluid" site.Params.images.class_name) .ClassName }}
{{- $className := default (default "img-fluid" $siteParams.class_name) .ClassName }}
{{- $height := default "" ($params.Get "height") }}
{{- $originalHeight := 0 }}
{{- $naturalHeight := $height }}
Expand All @@ -37,11 +38,11 @@
{{/* Image alignment. */}}
{{- $alignment := $url.Fragment }}
{{- if eq $alignment "center" }}
{{- $wrapperClass = default "d-block text-center" site.Params.images.alignment_center_class_name }}
{{- $wrapperClass = default "d-block text-center" $siteParams.alignment_center_class_name }}
{{- else if eq $alignment "float-start" }}
{{- $wrapperClass = default "float-start me-2" site.Params.images.alignment_start_class_name }}
{{- $wrapperClass = default "float-start me-2" $siteParams.alignment_start_class_name }}
{{- else if eq $alignment "float-end" }}
{{- $wrapperClass = default "float-end ms-2" site.Params.images.alignment_end_class_name }}
{{- $wrapperClass = default "float-end ms-2" $siteParams.alignment_end_class_name }}
{{- end }}
{{/* Check if the image is external. */}}
{{- if not $url.Scheme }}
Expand Down Expand Up @@ -210,9 +211,9 @@
"originalHeight" $originalHeight
}}
{{- if $caption }}
{{- $figureClass := default "figure" site.Params.images.figure_class_name }}
{{- $figureCaptionClass := default "figure-caption" site.Params.images.figure_caption_class_name }}
{{- $figureImgClass := default "figure-img" site.Params.images.figure_image_class_name }}
{{- $figureClass := default "figure" $siteParams.figure_class_name }}
{{- $figureCaptionClass := default "figure-caption" $siteParams.figure_caption_class_name }}
{{- $figureImgClass := default "figure-img" $siteParams.figure_image_class_name }}
<figure class="{{ $figureClass }} {{ $wrapperClass }}">
{{ partial "images/picture" (merge $ctx (dict "className" (printf "%s %s" $figureImgClass $className))) }}
<figcaption class="{{ $figureCaptionClass }}">{{ $caption }}</figcaption>
Expand Down

0 comments on commit 92a8e32

Please sign in to comment.