2023-10-31 16:53:15 +00:00
|
|
|
{{ $img := .img }}
|
|
|
|
{{ $alt := .alt }}
|
|
|
|
{{ $class := .class }}
|
2023-11-26 13:47:26 +00:00
|
|
|
{{ $lazy := .lazy | default $.Page.Site.Params.enableImageLazyLoading | default true }}
|
|
|
|
{{ $webp := .webp | default $.Page.Site.Params.enableImageWebp | default true }}
|
|
|
|
{{ $lqip := .lqip | default false }}
|
|
|
|
{{ $x2 := .x2 | default false }}
|
2023-10-31 16:53:15 +00:00
|
|
|
|
|
|
|
{{ with $img }}
|
|
|
|
{{ if (eq .MediaType.SubType "svg") }}
|
2023-12-26 00:22:55 +00:00
|
|
|
{{ $width := "" }}
|
|
|
|
{{ $height := "" }}
|
2023-10-31 16:53:15 +00:00
|
|
|
{{ $svgContent := .Content }}
|
|
|
|
{{ range (findRESubmatch `<svg[^>]*width=["']([.0-9]*)["'a-zA-Z]` $svgContent 1) }}
|
|
|
|
{{ $width = index . 1 }}
|
|
|
|
{{ end }}
|
|
|
|
{{ range (findRESubmatch `<svg[^>]*height=["']([.0-9]*)["'a-zA-Z]` $svgContent 1) }}
|
|
|
|
{{ $height = index . 1 }}
|
|
|
|
{{ end }}
|
|
|
|
{{ if (eq "" $width $height) }}
|
|
|
|
{{ range (findRESubmatch `<svg[^>]*viewBox=["']?([.0-9]*) ([.0-9]*) ([.0-9]*) ([.0-9]*)` $svgContent 1) }}
|
|
|
|
{{ $width = index . 3 }}
|
|
|
|
{{ $height = index . 4 }}
|
|
|
|
{{ end }}
|
|
|
|
{{ end }}
|
|
|
|
{{ if (eq "" $width $height) }}
|
|
|
|
{{ warnf "Can't detect width and height for SVG %s" .RelPermalink }}
|
|
|
|
{{/* do not use lazy without dimensions */}}
|
|
|
|
{{ $lazy = false }}
|
|
|
|
{{ end }}
|
2023-12-26 00:22:55 +00:00
|
|
|
<!-- prettier-ignore -->
|
2023-10-31 16:53:15 +00:00
|
|
|
<picture {{ with $class }} class="{{ . }}" {{ end }}>
|
|
|
|
<img
|
|
|
|
src="{{ .RelPermalink }}"
|
2023-12-26 00:22:55 +00:00
|
|
|
{{ with $width }}width="{{ . }}"{{ end }}
|
|
|
|
{{ with $height }}height="{{ . }}"{{ end }}
|
|
|
|
{{ with $class }}class="{{ . }}"{{ end }}
|
|
|
|
{{ with $alt }}alt="{{ . }}"{{ end }}
|
|
|
|
{{ with $lazy }}loading="lazy" decoding="async"{{ end }}
|
|
|
|
/>
|
2023-10-31 16:53:15 +00:00
|
|
|
</picture>
|
|
|
|
{{ else }}
|
2023-12-26 00:22:55 +00:00
|
|
|
<picture
|
|
|
|
{{ with $class }}class="{{ . }}"{{ end }}
|
2023-10-31 16:53:15 +00:00
|
|
|
{{ if $lqip }}
|
|
|
|
{{ $bg := (.Resize "20x webp q20").Content | base64Encode }}
|
|
|
|
style="background-image:url(data:image/webp;base64,{{ $bg }});background-size:cover"
|
|
|
|
{{ end }}
|
|
|
|
>
|
2023-12-26 00:22:55 +00:00
|
|
|
{{ $width := .Width }}
|
|
|
|
{{ $height := .Height }}
|
|
|
|
{{ if $x2 }}
|
|
|
|
{{ $width = div .Width 2 }}
|
|
|
|
{{ $height = div .Height 2 }}
|
|
|
|
{{ end }}
|
|
|
|
{{ if $webp }}
|
|
|
|
<source
|
|
|
|
{{ if lt .Width 660 }}
|
|
|
|
{{ with .Resize (printf "%dx%d webp" .Width .Height) }}
|
2024-01-19 15:17:28 +00:00
|
|
|
srcset="{{ .RelPermalink }}"
|
2023-12-26 00:22:55 +00:00
|
|
|
{{ end }}
|
|
|
|
{{ else }}
|
|
|
|
srcset=" {{- (.Resize "330x webp").RelPermalink }} 330w,
|
2023-11-26 00:21:36 +00:00
|
|
|
{{- (.Resize "660x webp").RelPermalink }} 660w
|
|
|
|
{{ if gt .Width 1024 }}
|
|
|
|
,{{ (.Resize "1024x webp").RelPermalink }} 1024w
|
2023-11-26 01:02:09 +00:00
|
|
|
{{ else }}
|
|
|
|
{{ with .Resize (printf "%dx%d webp" .Width .Height) }}
|
|
|
|
,{{ .RelPermalink }} {{ .Width }}w
|
|
|
|
{{ end }}
|
2023-11-26 00:21:36 +00:00
|
|
|
{{ end }}
|
|
|
|
{{ if gt .Width 1320 }}
|
2024-01-19 15:17:28 +00:00
|
|
|
,{{ (.Resize "1320x webp").RelPermalink }} 1320w
|
2023-11-26 01:02:09 +00:00
|
|
|
{{ else }}
|
|
|
|
{{ with .Resize (printf "%dx%d webp" .Width .Height) }}
|
|
|
|
,{{ .RelPermalink }} {{ .Width }}w
|
|
|
|
{{ end }}
|
2023-11-26 00:21:36 +00:00
|
|
|
{{ end }}"
|
2023-12-26 00:22:55 +00:00
|
|
|
{{ end }}
|
2024-01-19 15:17:28 +00:00
|
|
|
sizes="100vw"
|
2023-12-26 00:22:55 +00:00
|
|
|
type="image/webp"
|
|
|
|
/>
|
|
|
|
{{ end }}
|
2023-10-31 16:53:15 +00:00
|
|
|
<img
|
2023-11-26 01:23:34 +00:00
|
|
|
width="{{ $width }}"
|
|
|
|
height="{{ $height }}"
|
2023-12-26 00:22:55 +00:00
|
|
|
{{ with $class }}class="{{ . }}"{{ end }}
|
|
|
|
{{ with $alt }}alt="{{ . }}"{{ end }}
|
|
|
|
{{ with $lazy }}loading="lazy" decoding="async"{{ end }}
|
2023-10-31 16:53:15 +00:00
|
|
|
{{ if lt .Width 660 }}
|
|
|
|
src="{{ .RelPermalink }}"
|
|
|
|
{{ else }}
|
2024-01-19 15:17:28 +00:00
|
|
|
src="{{ (.Resize "660x").RelPermalink }}"
|
2023-12-26 00:22:55 +00:00
|
|
|
srcset=" {{- (.Resize "330x").RelPermalink }} 330w,
|
2024-01-19 15:17:28 +00:00
|
|
|
{{- (.Resize "660x").RelPermalink }} 660w
|
2023-11-26 00:21:36 +00:00
|
|
|
{{ if gt .Width 1024 }}
|
|
|
|
,{{ (.Resize "1024x").RelPermalink }} 1024w
|
2023-11-26 01:02:09 +00:00
|
|
|
{{ else }}
|
|
|
|
,{{ .RelPermalink }} {{ .Width }}w
|
2023-11-26 00:21:36 +00:00
|
|
|
{{ end }}
|
|
|
|
{{ if gt .Width 1320 }}
|
2024-01-19 15:17:28 +00:00
|
|
|
,{{ (.Resize "1320x").RelPermalink }} 1320w
|
2023-11-26 01:02:09 +00:00
|
|
|
{{ else }}
|
|
|
|
,{{ .RelPermalink }} {{ .Width }}w
|
2023-11-26 00:21:36 +00:00
|
|
|
{{ end }}"
|
2024-01-19 15:17:28 +00:00
|
|
|
sizes="100vw"
|
2023-10-31 16:53:15 +00:00
|
|
|
{{ end }}
|
2023-12-26 00:22:55 +00:00
|
|
|
/>
|
2023-10-31 16:53:15 +00:00
|
|
|
</picture>
|
|
|
|
{{ end }}
|
2023-12-26 00:22:55 +00:00
|
|
|
{{ end }}
|