feat: get page header image from page dir or assets media library

This commit is contained in:
George Cushen committed 2021-03-05 17:23:43 +00:00
1 parent ae7897c868
commit 3edb4ff8e7
1 file changed
+13 -5
+13 -5
View File
@@ -17,12 +17,20 @@
{{/* Header image */}}
{{ if and .Params.header.image (not (and $featured (not .Params.image.preview_only))) }}
<div class="article-header">
{{ $img_src := urls.Parse .Params.header.image }}
{{ if $img_src.Scheme }}
<img src="{{ .Params.header.image }}" class="article-banner" alt="">
{{- $img := "" -}}
{{ $alt := (.Params.header.caption | default "") | plainify }}
{{ $destination := .Params.header.image }}
{{ $is_remote := strings.HasPrefix $destination "http" }}
{{- if not $is_remote -}}
{{- $img = (.Page.Resources.ByType "image").GetMatch $destination -}}
{{- if not $img -}}
{{- $img = resources.Get (path.Join "media" $destination) -}}
{{- end -}}
{{- end -}}
{{ if $img }}
<img src="{{$img.RelPermalink}}" class="article-banner" alt="{{$alt}}">
{{ else }}
{{ $media_dir := $.Scratch.Get "media_dir" }}
<img src="{{ (printf "/%s/%s" $media_dir .Params.header.image) | relURL }}" class="article-banner" alt="">
<img src="{{ .Params.header.image }}" class="article-banner" alt="{{$alt}}">
{{ end }}
{{ with .Params.header.caption }}<span class="article-header-caption">{{ . | markdownify | emojify }}</span>{{ end }}