From 16194c23a1558dc10d0c2411f0d160fc6bf9405a Mon Sep 17 00:00:00 2001 From: rra Date: Thu, 28 Nov 2024 21:46:09 +0100 Subject: [PATCH] use regex on content make first image featured image --- .../layouts/partials/pen_card.html | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/themes/lumbung-theme/layouts/partials/pen_card.html b/themes/lumbung-theme/layouts/partials/pen_card.html index cc4f808..1b09857 100644 --- a/themes/lumbung-theme/layouts/partials/pen_card.html +++ b/themes/lumbung-theme/layouts/partials/pen_card.html @@ -5,26 +5,31 @@ {{ $postPermalink := .Permalink}} -

{{ .Title }}

- +

{{ .Title }}

- - {{ with (index (.Resources.ByType "image") 0) }} - {{ $height := add .Height 0.0}} - {{ $ratio := div $height .Width}} - {{ $thumb := .Fit "540x540 q80 webp"}} -
-
- {{ .Title }} -
+ {{$first_image := ""}} + {{$matches := findRESubmatch `]+)(?:'|")` .Content 1 }} + {{range $matches}}{{$first_image = index . 1}}{{end}} + {{with .Resources.Get $first_image}} + {{/* Check for resource type since some TIFFS show up as image, but can not do image operations. Then we can ignore them. */}} + {{if .ResourceType}} + {{ $height := add .Height 0.0}} + {{ $ratio := div $height .Width}} + {{ $thumb := .Fit "540x540 q80 webp"}} +
+
+ {{ .Title }} +
{{ else }}
- {{ end }} + {{ end }} + {{ else }} +
+ {{end}}
{{ .Summary }}
- - -
+ +