Skip to content

Instantly share code, notes, and snippets.

View jmooring's full-sized avatar

Joe Mooring jmooring

View GitHub Profile
@jmooring
jmooring / template.html
Last active August 3, 2023 22:13
Hugo - Code defensively when getting a remote resource
{{ $u := "https://example.org/images/a.jpg" }}
{{ with resources.GetRemote $u }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $u }}
{{ end }}