blowfish/layouts/_default/_markup/render-image.html

48 lines
1.6 KiB
HTML
Raw Normal View History

2022-12-21 17:46:19 -06:00
{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }}
2022-09-10 14:05:37 -05:00
{{ $url := urls.Parse .Destination }}
{{ $altText := .Text }}
{{ $caption := .Title }}
{{ if findRE "^https?" $url.Scheme }}
<figure>
2024-03-09 09:24:00 -06:00
<img class="my-0 rounded-md" loading="lazy" src="{{ $url.String }}" alt="{{ $altText }}" />
2022-09-10 14:05:37 -05:00
{{ 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>
2022-12-21 17:46:19 -06:00
{{ if $disableImageOptimization }}
<img
class="my-0 rounded-md"
2024-03-09 09:24:00 -06:00
loading="lazy"
2022-12-21 17:46:19 -06:00
src="{{ .RelPermalink }}"
alt="{{ $altText }}"
/>
{{ else }}
2022-09-10 14:05:37 -05:00
<img
class="my-0 rounded-md"
2024-03-09 09:24:00 -06:00
loading="lazy"
2022-09-10 14:05:37 -05:00
srcset="
2022-12-21 17:46:19 -06:00
{{ (.Resize "330x").RelPermalink }} 330w,
{{ (.Resize "660x").RelPermalink }} 660w,
{{ (.Resize "1024x").RelPermalink }} 1024w,
{{ (.Resize "1320x").RelPermalink }} 2x"
2022-09-10 14:05:37 -05:00
src="{{ (.Resize "660x").RelPermalink }}"
alt="{{ $altText }}"
/>
2022-12-21 17:46:19 -06:00
{{ end }}
2022-09-10 14:05:37 -05:00
{{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }}
</figure>
{{ else }}
<figure>
2024-03-09 09:24:00 -06:00
<img class="my-0 rounded-md" loading="lazy" src="{{ $url.String }}" alt="{{ $altText }}" />
2022-09-10 14:05:37 -05:00
{{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }}
</figure>
{{ end }}
{{ end }}