Skip to content

Instantly share code, notes, and snippets.

@jmooring
Last active August 3, 2023 22:13
Show Gist options
  • Save jmooring/e416433bc21f0aeb34744f31fc501782 to your computer and use it in GitHub Desktop.
Save jmooring/e416433bc21f0aeb34744f31fc501782 to your computer and use it in GitHub Desktop.
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 }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment