diff options
author | serg <contact@sergfurtak.com> | 2021-06-13 23:35:46 +0300 |
---|---|---|
committer | serg <contact@sergfurtak.com> | 2021-06-13 23:35:46 +0300 |
commit | bf276a6c39934da7c22b5e4fb8afbf6c04b605ff (patch) | |
tree | 41ebd75ed39e6d6c160ef46d7f51d19295ac90b6 | |
parent | 87043249861096f1a2a1b9d5a4fa6973bdd5a6ee (diff) |
add opportunity to set width and height for responsive imageimprove-image-crop
Signed-off-by: serg <contact@sergfurtak.com>
-rw-r--r-- | layouts/partials/modules/image.html | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/layouts/partials/modules/image.html b/layouts/partials/modules/image.html index d71c300..48f3c35 100644 --- a/layouts/partials/modules/image.html +++ b/layouts/partials/modules/image.html @@ -4,6 +4,8 @@ image: alt: Description srcset: src/img-1.jpg 500w, src/img-2.jpg 900w sizes: "(min-width: 600px) 50vw, 100vw" + width: crop # get width of image automatically after crop; or define manually a number value for this variable; depends on first (or only one) item in cropSet param + height: crop # get height of image automatically after crop; or define manually a number value for this variable; depends on first (or only one) item in cropSet param cropSet: # order matter; override sibling srcset if defined - options: 1170x500 # first (or only one) item is default cropped image and used as src in <img> tag - options: 900x400 @@ -50,10 +52,14 @@ image: {{$image = partial "funcs/GetImage" (dict "bundle" $imageBundle "path" $src "cmd" .cmd "options" .options)}} {{end}} {{end}} + {{$width := cond (eq .width "crop") $image.Width .width}} + {{$height := cond (eq .height "crop") $image.Height .height}} <img src="{{$image.RelPermalink | default ($src | relURL)}}" {{with .alt}} alt="{{.}}"{{end}} {{with $srcset}} {{printf "srcset=%q" . | safeHTMLAttr}}{{end}} {{with .sizes}} sizes="{{.}}"{{end}} + {{with $width}} width="{{.}}"{{end}} + {{with $height}} height="{{.}}"{{end}} /> {{if .sources}}</picture>{{end}} {{end}} |