hugo_frigg/layouts/shortcodes/img.html

43 lines
1.2 KiB
HTML

{{ $img := $.Page.Resources.GetMatch (.Get "src")}}
{{ $name_splitted := split $img.RelPermalink "." }}
{{ $name_base := index $name_splitted 0 }}
{{ $ext_base := index $name_splitted 1 }}
<figure {{ with .Get "class" }} class="{{ . }}"{{ end }}>
{{ with .Get "link" }}
<a href="{{ . | absURL }}">
{{ else }}
<a href="{{ $img.RelPermalink }}">
{{ end }}
<picture>
{{ if ( in "svg ico gif" $ext_base ) }}
<img src="{{ $img.RelPermalink }}"
{{ with .Get "alt"}} alt="{{ . }}"{{ end }}
{{ with .Get "title"}} title="{{ . }}"{{ end }}/>
{{ else }}
<source srcset="{{ $name_base }}.thumb.avif" type="image/avif"/>
<source srcset="{{ $name_base }}.thumb.webp" type="image/webp"/>
<img src="{{ $name_base }}.thumb.{{ $ext_base }}"
{{ with .Get "alt"}} alt="{{ . }}"{{ end }}
{{ with .Get "title"}} title="{{ . }}"{{ end }}/>
{{ end }}
</picture>
</a>
{{ if .Get "caption" }}
<figcaption>
<p>{{ .Get "caption" }}
{{ if .Get "attr" }}
<span class="attribution">
{{ with .Get "attrlink" }}
<a href="{{ . }}">
{{ end }}
{{ .Get "attr" }}
{{ with .Get "attrlink" }}
</a>
{{ end }}
</span>
{{ end }}
</p>
</figcaption>
{{ end }}
</figure>