[SHORTCODE] Add picture/source to img
This commit is contained in:
parent
7d9ad73c0b
commit
d35fec4c78
1 changed files with 19 additions and 8 deletions
|
@ -1,16 +1,27 @@
|
||||||
{{ $img := $.Page.Resources.GetMatch (.Get "src")}}
|
{{ $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 }}>
|
<figure {{ with .Get "class" }} class="{{ . }}"{{ end }}>
|
||||||
{{ with .Get "link" }}
|
{{ with .Get "link" }}
|
||||||
<a href="{{ . | absURL }}">
|
<a href="{{ . | absURL }}">
|
||||||
|
{{ else }}
|
||||||
|
<a href="{{ $img.RelPermalink }}">
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<img src="{{ $img.RelPermalink }}"
|
<picture>
|
||||||
{{ with .Get "alt"}} alt="{{ . }}"{{ end }}
|
{{ if ( in "svg ico gif" $ext_base ) }}
|
||||||
{{ with .Get "title"}} title="{{ . }}"{{ end }}
|
<img src="{{ $img.RelPermalink }}"
|
||||||
{{ with .Get "height"}} height="{{ . }}"{{ end }}
|
{{ with .Get "alt"}} alt="{{ . }}"{{ end }}
|
||||||
{{ with .Get "width"}} width="{{ . }}"{{ end }} />
|
{{ with .Get "title"}} title="{{ . }}"{{ end }}/>
|
||||||
{{ with .Get "link" }}
|
{{ else }}
|
||||||
</a>
|
<source srcset="{{ $name_base }}.thumb.avif" type="image/avif"/>
|
||||||
{{ end }}
|
<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" }}
|
{{ if .Get "caption" }}
|
||||||
<figcaption>
|
<figcaption>
|
||||||
<p>{{ .Get "caption" }}
|
<p>{{ .Get "caption" }}
|
||||||
|
|
Loading…
Reference in a new issue