Files
hugo_blog.awin.one/layouts/partials/utils/get-image.html
2022-05-10 01:13:38 +08:00

17 lines
582 B
HTML

{{- $img := "" }}
{{- $validKeyword := false }}
{{- if .keyword }}
{{- if (.context.Resources.ByType "image").GetMatch .keyword }}
{{- $validKeyword = true}}
{{- end }}
{{- end }}
{{- if $validKeyword }}
{{- $img = ((.context.Resources.ByType "image").GetMatch .keyword).Permalink }}
{{- else if or (hasPrefix .url "//") (or (hasPrefix .url "http://") (hasPrefix .url "https://")) }}
{{- $img = (.url | absURL) }}
{{- else if resources.GetMatch .url }}
{{- $img = (resources.GetMatch .url).Permalink }}
{{- else if .url }}
{{- $img = (.url | absURL) }}
{{- end }}
{{- return $img }}