use regex on content make first image featured image
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
rra 2024-11-28 21:46:09 +01:00
parent 5fe7cacea3
commit 16194c23a1

View File

@ -5,26 +5,31 @@
{{ $postPermalink := .Permalink}}
<time class="dt-published" datetime="{{ .Date.Format `Jan 02 2006` }}">{{ .Date.Format "Jan 02, 2006" }}</time>
<h2 class="p-name"><a href="{{ .Permalink }}" class="u-url">{{ .Title }}</a></h2>
<h2 class="p-name"><a href="{{ .Permalink }}" class="u-url">{{ .Title }}</a></h2>
</header>
{{ with (index (.Resources.ByType "image") 0) }}
{{ $height := add .Height 0.0}}
{{ $ratio := div $height .Width}}
{{ $thumb := .Fit "540x540 q80 webp"}}
<div class="p-summary{{if gt $ratio 1 }} portrait {{else}} landscape {{end}}">
<div class="summary-image {{if gt $ratio 1 }} portrait {{else}} landscape {{end}}">
<a href="{{ $postPermalink }}"><img src="{{ $thumb.Permalink }}" alt="{{ .Title }}"> </a>
</div>
{{$first_image := ""}}
{{$matches := findRESubmatch `<img\s.*?src=(?:'|")([^'">]+)(?:'|")` .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"}}
<div class="p-summary{{if gt $ratio 1 }} portrait {{else}} landscape {{end}}">
<div class="summary-image {{if gt $ratio 1 }} portrait {{else}} landscape {{end}}">
<a href="{{ $postPermalink }}"><img src="{{ $thumb.Permalink }}" alt="{{ .Title }}"> </a>
</div>
{{ else }}
<div class="p-summary">
{{ end }}
{{ end }}
{{ else }}
<div class="p-summary">
{{end}}
<div class="summary-text">
{{ .Summary }}
</div>
</div>
<footer class='post-footer'>
<a href="{{ .RelPermalink }}">
<svg width="11" height="11" viewBox="0 0 11 11" xmlns="http://www.w3.org/2000/svg">
@ -32,5 +37,5 @@
</svg>
</a>
</footer>
</article>
</div>
</article>
</div>