uci-hugo-doc/layouts/shortcodes/img.html

45 lines
1.4 KiB
HTML
Raw Normal View History

2021-04-27 14:44:35 -07:00
{{ $source := ($.Page.Resources.ByType "image").GetMatch (printf "%s" (.Get "name")) }}
2021-02-20 12:39:31 -08:00
{{ $customAlt := .Get "alt" }}
{{ $customSize := .Get "size" }}
{{ $lazyLoad := default (default true $.Site.Params.GeekdocImageLazyLoading) (.Get "lazy") }}
{{ with $source }}
{{ $caption := default .Title $customAlt }}
2021-02-20 12:39:31 -08:00
{{ $tiny := (.Resize "320x").Permalink }}
{{ $small := (.Resize "600x").Permalink }}
{{ $medium := (.Resize "1200x").Permalink }}
{{ $large := (.Resize "1800x").Permalink }}
2021-02-20 12:39:31 -08:00
{{ $size := dict "tiny" $tiny "small" $small "medium" $medium "large" $large }}
2021-02-20 12:39:31 -08:00
<div class="flex justify-center">
<figure class="gdoc-markdown__figure">
<a class="gdoc-markdown__link--raw" href="{{ .Permalink }}">
2021-04-27 14:44:35 -07:00
<picture>
<source
{{ with $customSize }}
srcset="{{ index $size $customSize }}"
{{ else }}
srcset="{{ $size.small }} 600w, {{ $size.medium }} 1200w" sizes="100vw"
{{ end }}
/>
<img
{{ if $lazyLoad }}
loading="lazy"
{{ end }}
src="{{ $size.large }}"
alt="{{ $caption }}"
/>
2021-04-27 14:44:35 -07:00
</picture>
</a>
{{ with $caption -}}
<figcaption>
{{ . }}{{ with $source.Params.credits }}({{ . | $.Page.RenderString }}){{ end }}
</figcaption>
{{- end }}
</figure>
</div>
2021-02-20 12:39:31 -08:00
{{ end }}