88 lines
2.7 KiB
HTML
88 lines
2.7 KiB
HTML
<!-- This is potentially what I'd like to use -->
|
|
<picture>
|
|
{{ $isJPG := eq (path.Ext .Destination) ".jpg" }}
|
|
{{ $isPNG := eq (path.Ext .Destination) ".png" }}
|
|
|
|
{{ if ($isJPG) -}}
|
|
{{ $avifPath:= replace .Destination ".jpg" ".avif" }}
|
|
{{ $avifPathStatic:= printf "static/%s" $avifPath }}
|
|
|
|
{{ if (fileExists $avifPathStatic) -}}
|
|
<source srcset="{{ $avifPath | safeURL }}" type="image/avif" >
|
|
{{- end }}
|
|
|
|
{{ $webpPath:= replace .Destination ".jpg" ".webp" }}
|
|
{{ $webpPathStatic:= printf "static/%s" $webpPath }}
|
|
|
|
{{ if (fileExists $webpPathStatic) -}}
|
|
<source srcset="{{ $webpPath | safeURL }}" type="image/webp" >
|
|
{{- end }}
|
|
{{- end }}
|
|
|
|
{{ if ($isPNG) -}}
|
|
{{ $avifPath:= replace .Destination ".png" ".avif" }}
|
|
{{ $avifPathStatic:= printf "static/%s" $avifPath }}
|
|
|
|
{{ if (fileExists $avifPathStatic) -}}
|
|
<source srcset="{{ $avifPath | safeURL }}" type="image/avif" >
|
|
{{- end }}
|
|
|
|
{{ $webpPath:= replace .Destination ".png" ".webp" }}
|
|
{{ $webpPathStatic:= printf "static/%s" $webpPath }}
|
|
|
|
{{ if (fileExists $webpPathStatic) -}}
|
|
<source srcset="{{ $webpPath | safeURL }}" type="image/webp" >
|
|
{{- end }}
|
|
{{- end }}
|
|
|
|
{{ $img := imageConfig (add "/static" (.Destination | safeURL)) }}
|
|
|
|
<img
|
|
src="{{ .Destination | safeURL }}"
|
|
alt="{{ .Text }}"
|
|
loading="lazy"
|
|
decoding="async"
|
|
width="{{ $img.Width }}"
|
|
height="{{ $img.Height }}"
|
|
/>
|
|
</picture>
|
|
|
|
|
|
<!-- This is what is currently running -->
|
|
{{ $url := urls.Parse .Destination }}
|
|
{{ $altText := .Text }}
|
|
{{ $caption := .Title }}
|
|
{{ if findRE "^https?" $url.Scheme }}
|
|
<figure>
|
|
<img class="my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" />
|
|
{{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }}
|
|
</figure>
|
|
{{ else }}
|
|
{{ $resource := "" }}
|
|
{{ if $.Page.Resources.GetMatch ($url.String) }}
|
|
{{ $resource = $.Page.Resources.GetMatch ($url.String) }}
|
|
{{ else if resources.GetMatch ($url.String) }}
|
|
{{ $resource = resources.Get ($url.String) }}
|
|
{{ end }}
|
|
{{ with $resource }}
|
|
<figure>
|
|
<img
|
|
class="my-0 rounded-md"
|
|
srcset="
|
|
{{ (.Resize "330x").RelPermalink }} 330w,
|
|
{{ (.Resize "660x").RelPermalink }} 660w,
|
|
{{ (.Resize "1024x").RelPermalink }} 1024w,
|
|
{{ (.Resize "1320x").RelPermalink }} 2x"
|
|
src="{{ (.Resize "660x").RelPermalink }}"
|
|
alt="{{ $altText }}"
|
|
/>
|
|
{{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }}
|
|
</figure>
|
|
{{ else }}
|
|
<figure>
|
|
<img class="my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" />
|
|
{{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }}
|
|
</figure>
|
|
{{ end }}
|
|
{{ end }}
|