diff --git a/layouts/shortcodes/image.html b/layouts/shortcodes/image.html index 9c53c9f..8408a19 100644 --- a/layouts/shortcodes/image.html +++ b/layouts/shortcodes/image.html @@ -1,7 +1,14 @@ - {{ if (fileExists (printf "%s/%s" "content" (replace (index .Params "src") (path.Ext (index .Params "src")) ".webp"))) -}} - + {{ if (fileExists (printf "%s/%s" "content" (replace (.Get "src") (path.Ext (.Get "src")) ".webp"))) -}} + {{- end }} - - {{ index .Params + {{ $image := $.Page.Resources.GetMatch (.Get "src") }} + {{ if gt $image.Width 800 -}} + {{ $resized := $image.Resize "800x Lanczos" }} + + {{ .Get + {{ else }} + + {{ .Get + {{- end}} \ No newline at end of file diff --git a/layouts/shortcodes/smallimg.html b/layouts/shortcodes/smallimg.html index 209c56f..4279adc 100644 --- a/layouts/shortcodes/smallimg.html +++ b/layouts/shortcodes/smallimg.html @@ -1,17 +1,38 @@ - {{ if (fileExists (printf "%s/%s" "content" (replace (index .Params "src") (path.Ext (index .Params "src")) ".webp"))) -}} - + {{ if (fileExists (printf "%s/%s" "content" (replace (.Get "src") (path.Ext (.Get "src")) ".webp"))) -}} + + {{- end }} + {{ $image := $.Page.Resources.GetMatch (.Get "src") }} + {{ if or (gt $image.Width 800) (and (isset .Params "width") (gt $image.Width (.Get "width"))) -}} + {{ $.Scratch.Set "imgwidth" 800 }} + {{ if lt (.Get "width") 800 -}} + {{ $.Scratch.Set "imgwidth" (trim (.Get "width") "px") }} + {{- end }} + {{ $resized := $image.Resize (printf "%sx Lanczos" ($.Scratch.Get "imgwidth")) }} + + {{ .Get + {{ else }} + + {{ .Get {{- end }} - - {{ index .Params \ No newline at end of file