mirror of
https://github.com/theNewDynamic/gohugo-theme-ananke.git
synced 2025-06-08 09:12:47 +00:00
36 lines
1.2 KiB
Plaintext
36 lines
1.2 KiB
Plaintext
{{/*
|
|
GetImageResource
|
|
|
|
This partial gets an image resource for a given string.
|
|
|
|
A matching resource is returned if found in the following search order:
|
|
|
|
* A page resource.
|
|
* If the string begins with "http", a remote global resource.
|
|
* Otherwise, a local global resource.
|
|
|
|
If no matching resource is found, this partial returns false.
|
|
|
|
@return an image resource, or false if not found.
|
|
|
|
*/}}
|
|
{{ $imageResource := false }}
|
|
{{/* If we find a remote global Resource matching the exact value, we use it. */}}
|
|
{{ if (hasPrefix $.src "http") }}
|
|
{{ with resources.GetRemote $.src }}
|
|
{{ $imageResource = . }}
|
|
{{ end }}
|
|
{{ else }}
|
|
{{/* If we find a local global Resource matching the exact value, we use it. */}}
|
|
{{/* Matching uses relative paths so strip a leading / character if present. */}}
|
|
{{ with resources.GetMatch (trim $.src "/") }}
|
|
{{ $imageResource = . }}
|
|
{{ end }}
|
|
{{ end }}
|
|
{{/* If we find a Page Resource matching the exact value, we use it instead. */}}
|
|
{{/* Matching uses relative paths so strip a leading / character if present. */}}
|
|
{{ with $.pageResources.GetMatch (trim $.src "/") }}
|
|
{{ $imageResource = . }}
|
|
{{ end }}
|
|
{{ return $imageResource }}
|