hugo-geekdoc/layouts/shortcodes/img.html

52 lines
1.7 KiB
HTML
Raw Normal View History

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