mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy.org.git
synced 2025-01-27 11:16:42 +00:00
feat: responsive image shortcode
This commit is contained in:
parent
96680d67e4
commit
3881f8f8ae
30
layouts/shortcodes/responsive-img.html
Normal file
30
layouts/shortcodes/responsive-img.html
Normal 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%
|
||||
'
|
||||
>
|
Loading…
Reference in a new issue