Files
hugo-profile/layouts/partials/sections/footer/recentBlogPosts.html
T
Adrià LópezandGitHub 95ba6334d4 Only creating the div if showing recent posts
Hi,

I thought that it's better to avoid adding the recent-posts div to the DOM if that section is not enabled.
Also, I've modified the logic so that if there are no posts, it will be considered disabled instead of showing the title with no further content.

Hope this is Ok.
2023-03-24 19:16:57 +01:00

39 lines
2.1 KiB
HTML

{{ $currentNumOfrecentPosts := len (where .Site.RegularPages "Type" "posts") }}
{{ if and (gt $currentNumOfrecentPosts 0) (.Site.Params.footer.recentPosts.enable | default false) }}
<div class="container py-3" id="recent-posts">
{{ $recentPostsPath := .Site.Params.footer.recentPosts.path | default "blogs" }}
{{ $recentPostsCount := .Site.Params.footer.recentPosts.count | default 3 }}
{{ $recentPosts := where .Site.RegularPages "Section" $recentPostsPath | first $recentPostsCount }}
<div class="h3 text-center text-secondary py-3">
{{ .Site.Params.footer.recentPosts.title | default "Recent Posts" }}
</div>
<div class="row justify-content-center">
{{ range $recentPosts }}
<div class="col-lg-4 col-md-6 pt-2">
<div class="card h-100">
{{ if and (not (.Site.Params.footer.recentPosts.disableFeaturedImage | default false)) (.Params.image) }}
<div class="card-header">
<a href="{{ .RelPermalink }}">
<img src="{{ .Params.image }}" class="card-img-top" alt="{{ .Title }}">
</a>
</div>
{{ end }}
<div class="card-body bg-transparent p-3 shadow-sm">
<a href="{{ .RelPermalink }}" class="primary-font card-title">
<h5 class="card-title bg-transparent" title="{{ .Title }}">{{ .Title | truncate 25 }}</h5>
</a>
<div class="card-text secondary-font">
<p>{{ .Summary | truncate 300}}</p>
</div>
</div>
<div class="mt-auto card-footer">
<span class="float-start">{{ .Date.Format (.Site.Params.datesFormat.articleRecent | default "January 2, 2006") }}</span>
<a href="{{ .RelPermalink }}" class="float-end btn btn-outline-info btn-sm">{{ .Site.Params.terms.read | default "Read" }}</a>
</div>
</div>
</div>
{{ end }}
</div>
</div>
{{ end }}