Halo, I want to render an optional image template in the render-image.html
hook.
Here my render-image.html
:
{{ $file_ext := substr (path.Ext .Destination) 1 }}
{{ $file_name := replaceRE `\.+.+` "" (path.Base .Destination) }}
{{ $dir := path.Dir .Destination }}
<picture>
<source srcset="{{ $dir }}/{{ $file_name }}.avif" type="image/avif" />
<img src="{{ .Destination }}" alt="{{ .Text }}" />
</picture>
The .avif
file is not been generated yet. It will be generated using sharp in the CI build.
So, If I run the local server, the image will be not found.
I want to render it optionally with this:
<picture>
{{ if not .Site.IsServer }}
<source srcset="{{ $dir }}/{{ $file_name }}.avif" type="image/avif" />
{{ end }}
<img src="{{ .Destination }}" alt="{{ .Text }}" />
</picture>
But it does not work and I got an error:
render-image.html:17:15: executing "_default/_markup/render-image.html" at <.Site.IsServer>: can't evaluate field Site in type goldmark.linkContext
I was use:
{{ if not $.Site.IsServer }}
...
{{ end }}
But still doesn’t work.
How can I make the avif image used optionally in local server?
Any ideas?