2026-01-25 23:29:41 +01:00
|
|
|
/// Params:
|
|
|
|
|
/// Resources: Where to search for images
|
|
|
|
|
/// Image: Image URL
|
2020-09-11 16:27:23 +02:00
|
|
|
|
2026-01-25 23:29:41 +01:00
|
|
|
/// Returns:
|
2026-03-04 13:05:17 +01:00
|
|
|
/// Resource: Hugo image resource object
|
2026-01-25 23:29:41 +01:00
|
|
|
/// Permalink: Image URL
|
|
|
|
|
/// Height: Image height
|
|
|
|
|
/// Width: Image width
|
2020-09-11 18:13:39 +02:00
|
|
|
|
2026-01-30 15:07:14 +01:00
|
|
|
{{ $result := "" }}
|
2026-01-25 23:29:41 +01:00
|
|
|
|
2026-01-30 15:07:14 +01:00
|
|
|
{{ if .Image }}
|
2026-01-25 23:29:41 +01:00
|
|
|
{{ $url := urls.Parse .Image }}
|
2026-03-04 13:05:17 +01:00
|
|
|
{{ $permalink := .Image }}
|
2026-01-30 15:07:14 +01:00
|
|
|
{{ $resource := "" }}
|
2026-03-04 13:05:17 +01:00
|
|
|
|
2026-01-25 23:29:41 +01:00
|
|
|
{{ if not (in (slice "https" "http") $url.Scheme) }}
|
2026-03-04 13:05:17 +01:00
|
|
|
{{/* Local image */}}
|
2026-01-30 15:07:14 +01:00
|
|
|
{{ $resource = .Resources.Get (printf "%s" (.Image | safeURL)) }}
|
2026-03-04 13:05:17 +01:00
|
|
|
{{ $permalink = $resource.RelPermalink }}
|
2026-01-30 15:07:14 +01:00
|
|
|
{{ else }}
|
2026-03-04 13:05:17 +01:00
|
|
|
{{/* Remote image */}}
|
2026-01-30 15:07:14 +01:00
|
|
|
{{ with try (resources.GetRemote $url) }}
|
|
|
|
|
{{ with .Err }}
|
|
|
|
|
{{ errorf "%s" . }}
|
|
|
|
|
{{ else with .Value }}
|
|
|
|
|
{{ $resource = . }}
|
|
|
|
|
{{ else }}
|
|
|
|
|
{{ errorf "Unable to get remote resource %q" $url }}
|
|
|
|
|
{{ end }}
|
|
|
|
|
{{ end }}
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
2026-03-04 13:05:17 +01:00
|
|
|
{{ with $resource }}
|
2026-03-05 09:23:47 +01:00
|
|
|
{{ if reflect.IsImageResourceWithMeta . }}
|
2026-01-25 23:29:41 +01:00
|
|
|
{{ $result = dict
|
2026-01-30 15:07:14 +01:00
|
|
|
"Resource" $resource
|
2026-03-04 13:05:17 +01:00
|
|
|
"Permalink" $permalink
|
2026-01-25 23:29:41 +01:00
|
|
|
"Height" $resource.Height
|
|
|
|
|
"Width" $resource.Width
|
|
|
|
|
}}
|
2026-03-04 13:05:17 +01:00
|
|
|
{{ else }}
|
|
|
|
|
{{ $result = dict
|
|
|
|
|
"Resource" $resource
|
|
|
|
|
"Permalink" $permalink
|
|
|
|
|
"Height" nil
|
|
|
|
|
"Width" nil
|
|
|
|
|
}}
|
|
|
|
|
{{ end }}
|
2020-09-11 16:27:23 +02:00
|
|
|
{{ end }}
|
2020-09-10 18:53:36 +02:00
|
|
|
{{ end }}
|
|
|
|
|
|
2026-01-25 23:29:41 +01:00
|
|
|
{{ return $result }}
|