This was a tough nut to crack. I’m totally new to Go Html Templates and Go itself, and I’ve never really used anything outside of Jekyll. It took me a minute, but I wound up coming up with this:
{{ $image := (resources.Get .Destination) }}
{{ with $image }}
{{ if eq $image.MediaType.SubType "svg" }}
<a data-fancybox="image" href="{{ $image.RelPermalink }}" data-caption="{{ with $.Title }}{{ . }}{{ end }}">
<img src="{{ $image.RelPermalink }}" {{ with $.Text }} alt="{{ . }}" {{ end }} {{ with $.Title}} title="{{ . }}"{{ end }} />
</a>
{{ else }}
{{ $resize := .Fill "200x165 webp q80" }}
<a data-fancybox="image" href="{{ $image.RelPermalink }}" data-caption="{{ with $.Title }}{{ . }}{{ end }}">
<img src="{{ $resize.RelPermalink }}" {{ with $.Text }} alt="{{ . }}" {{ end }} {{ with $.Title}} title="{{ . }}"{{ end }} />
</a>
{{ end }}
{{ end }}
Apparently I have a *.svg
file on my blog somewhere, because that was a thing I had to catch right away for this to work. So I had to move all my images out of static
and into assets
for it to work, first of all. Then I had to figure out how to query a parent context, so I could fill in Text
and Title
with the images. That’s what the $
is in $.Text
. It’s the parent context outside of $image
.