From 3edb4ff8e774c21789404cc3ba44735a65cab27d Mon Sep 17 00:00:00 2001 From: George Cushen Date: Fri, 5 Mar 2021 17:23:43 +0000 Subject: [PATCH] feat: get page header image from page dir or assets media library --- wowchemy/layouts/partials/page_header.html | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/wowchemy/layouts/partials/page_header.html b/wowchemy/layouts/partials/page_header.html index af07f3f7..2652cfba 100644 --- a/wowchemy/layouts/partials/page_header.html +++ b/wowchemy/layouts/partials/page_header.html @@ -17,12 +17,20 @@ {{/* Header image */}} {{ if and .Params.header.image (not (and $featured (not .Params.image.preview_only))) }}
- {{ $img_src := urls.Parse .Params.header.image }} - {{ if $img_src.Scheme }} - + {{- $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 }} + {{$alt}} {{ else }} - {{ $media_dir := $.Scratch.Get "media_dir" }} - + {{$alt}} {{ end }} {{ with .Params.header.caption }}{{ . | markdownify | emojify }}{{ end }}