update
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
{{/* Usage: {{< optimize-img src="cover.jpg" alt="Cover Image" size="800x"
|
||||
class="rounded shadow" >}} */}} {{ $src := .Get "src" }} {{ $alt := .Get "alt" |
|
||||
default "" }} {{ $class := .Get "class" | default "" }} {{ $size := .Get "size"
|
||||
| default "800x" }} {{ with .Page.Resources.GetMatch $src }} {{ $resized :=
|
||||
.Resize $size }} {{ $webp := $resized | images.Convert "webp" }}
|
||||
<img
|
||||
src="{{ $webp.RelPermalink }}"
|
||||
alt="{{ $alt }}"
|
||||
class="{{ $class }}"
|
||||
width="{{ $webp.Width }}"
|
||||
height="{{ $webp.Height }}"
|
||||
loading="lazy"
|
||||
/>
|
||||
{{ else }}
|
||||
<img src="{{ $src }}" alt="{{ $alt }}" class="{{ $class }}" loading="lazy" />
|
||||
{{ end }}
|
||||
{{ $src := .Get "src" }} {{ $alt := .Get "alt" | default "" }} {{ $class := .Get
|
||||
"class" | default "" }} {{ $size := .Get "size" | default "800x" }} {{ with
|
||||
.Page.Resources.GetMatch $src }} {{ $resized := .Resize $size }} {{ $webp :=
|
||||
$resized | images.Convert "webp" }}
|
||||
<img
|
||||
src="{{ $webp.RelPermalink }}"
|
||||
alt="{{ $alt }}"
|
||||
class="{{ $class }}"
|
||||
width="{{ $webp.Width }}"
|
||||
height="{{ $webp.Height }}"
|
||||
loading="lazy"
|
||||
/>
|
||||
{{ else }}
|
||||
<img src="{{ $src }}" alt="{{ $alt }}" class="{{ $class }}" loading="lazy" />
|
||||
{{ end }}
|
||||
|
||||
8
layouts/shortcodes/optimize-image.html
Normal file
8
layouts/shortcodes/optimize-image.html
Normal file
@@ -0,0 +1,8 @@
|
||||
{{$image := .Params.image}} {{$imgSrc := resources.Get $image}}
|
||||
<img
|
||||
src="{{$imgSrc.Permalink}}"
|
||||
alt="{{ .Title }}"
|
||||
data-pagefind-index-attrs="title,alt"
|
||||
class="story__coverImg"
|
||||
loading="lazy"
|
||||
/>
|
||||
Reference in New Issue
Block a user