feat: responsive image shortcode

This commit is contained in:
nevfy 2024-11-12 02:55:52 +03:00
parent 96680d67e4
commit 3881f8f8ae

View file

@ -0,0 +1,30 @@
{{ $src := ( resources.Get ( .Get 0 ) ) }}
{{ $tinyw := default "500" }}
{{ $smallw := default "800" }}
{{ $mediumw := default "1200" }}
{{ $largew := default "2400" }}
{{ $tiny := $src.Resize (printf "%sx" $tinyw) }}
{{ $small := $src.Resize (printf "%sx" $smallw) }}
{{ $medium:= $src.Resize (printf "%sx" $mediumw) }}
{{ $large := $src.Resize (printf "%sx" $largew) }}
<img
{{ with ( .Get 1 ) }}
class = "{{ . }}"
{{ end }}
srcset='
{{ with $tiny.RelPermalink }} {{.}} {{(printf "%sw" $tinyw)}} {{ end }},
{{ with $small.RelPermalink }} {{.}} {{(printf "%sw" $smallw)}} {{ end }},
{{ with $medium.RelPermalink }} {{.}} {{(printf "%sw" $mediumw)}} {{ end }},
{{ with $large.RelPermalink }} {{.}} {{(printf "%sw" $largew)}} {{ end }}
'
sizes='
(max-width: {{(printf "%spx" $tinyw)}}) {{(printf "%spx" $tinyw)}},
(max-width: {{(printf "%spx" $smallw)}}) {{(printf "%spx" $smallw)}},
(max-width: {{(printf "%spx" $mediumw)}}) {{(printf "%spx" $mediumw)}},
(max-width: {{(printf "%spx" $largew)}}) {{(printf "%spx" $largew)}},
100%
'
>