From d707ff2a36600e3d217a584d02dd1070b61bf9e0 Mon Sep 17 00:00:00 2001 From: iUnknwn Date: Fri, 19 Jun 2020 12:45:23 -0700 Subject: [PATCH] Add support for auto-detection of featured images. --- layouts/partials/featured.html | 10 ++++++++++ layouts/partials/page-header.html | 2 +- layouts/partials/summary-with-image.html | 6 +++--- layouts/post/summary-with-image.html | 7 ++++--- 4 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 layouts/partials/featured.html diff --git a/layouts/partials/featured.html b/layouts/partials/featured.html new file mode 100644 index 0000000..10de1d2 --- /dev/null +++ b/layouts/partials/featured.html @@ -0,0 +1,10 @@ +{{ $linkToCover := "" }} +{{ if .Params.featured_image }} + {{ $linkToCover = .Params.featured_image }} +{{ else }} + {{ $img := .Resources.GetMatch "**cover*.jpg" }} + {{ with $img }} + {{ $linkToCover = .Permalink }} + {{ end }} +{{ end }} +{{ return $linkToCover }} \ No newline at end of file diff --git a/layouts/partials/page-header.html b/layouts/partials/page-header.html index 8cd6d4f..22b7822 100644 --- a/layouts/partials/page-header.html +++ b/layouts/partials/page-header.html @@ -1,4 +1,4 @@ -{{ $featured_image := .Params.featured_image }} +{{ $featured_image := partial "featured.html" . }} {{ if $featured_image }} {{/* Trimming the slash and adding absURL make sure the image works no matter where our site lives */}} {{ $featured_image := (trim $featured_image "/") | absURL }} diff --git a/layouts/partials/summary-with-image.html b/layouts/partials/summary-with-image.html index 962981f..8fcf1ae 100644 --- a/layouts/partials/summary-with-image.html +++ b/layouts/partials/summary-with-image.html @@ -1,8 +1,8 @@ -{{ $featured_image := .Params.featured_image }} +{{ $featured_image := partial "featured.html" . }}