use regex on content make first image featured image
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
5fe7cacea3
commit
16194c23a1
@ -5,26 +5,31 @@
|
|||||||
|
|
||||||
{{ $postPermalink := .Permalink}}
|
{{ $postPermalink := .Permalink}}
|
||||||
<time class="dt-published" datetime="{{ .Date.Format `Jan 02 2006` }}">{{ .Date.Format "Jan 02, 2006" }}</time>
|
<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>
|
</header>
|
||||||
|
{{$first_image := ""}}
|
||||||
{{ with (index (.Resources.ByType "image") 0) }}
|
{{$matches := findRESubmatch `<img\s.*?src=(?:'|")([^'">]+)(?:'|")` .Content 1 }}
|
||||||
{{ $height := add .Height 0.0}}
|
{{range $matches}}{{$first_image = index . 1}}{{end}}
|
||||||
{{ $ratio := div $height .Width}}
|
{{with .Resources.Get $first_image}}
|
||||||
{{ $thumb := .Fit "540x540 q80 webp"}}
|
{{/* Check for resource type since some TIFFS show up as image, but can not do image operations. Then we can ignore them. */}}
|
||||||
<div class="p-summary{{if gt $ratio 1 }} portrait {{else}} landscape {{end}}">
|
{{if .ResourceType}}
|
||||||
<div class="summary-image {{if gt $ratio 1 }} portrait {{else}} landscape {{end}}">
|
{{ $height := add .Height 0.0}}
|
||||||
<a href="{{ $postPermalink }}"><img src="{{ $thumb.Permalink }}" alt="{{ .Title }}"> </a>
|
{{ $ratio := div $height .Width}}
|
||||||
</div>
|
{{ $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 }}
|
{{ else }}
|
||||||
<div class="p-summary">
|
<div class="p-summary">
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
{{ else }}
|
||||||
|
<div class="p-summary">
|
||||||
|
{{end}}
|
||||||
<div class="summary-text">
|
<div class="summary-text">
|
||||||
{{ .Summary }}
|
{{ .Summary }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<footer class='post-footer'>
|
<footer class='post-footer'>
|
||||||
<a href="{{ .RelPermalink }}">
|
<a href="{{ .RelPermalink }}">
|
||||||
<svg width="11" height="11" viewBox="0 0 11 11" xmlns="http://www.w3.org/2000/svg">
|
<svg width="11" height="11" viewBox="0 0 11 11" xmlns="http://www.w3.org/2000/svg">
|
||||||
@ -32,5 +37,5 @@
|
|||||||
</svg>
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
</footer>
|
</footer>
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user