add check on the latest post year before inserting the h2

This commit is contained in:
Angelo 2020-12-26 20:19:01 +13:00
parent 50d13c4e83
commit c7afd15e06

View file

@ -1,6 +1,11 @@
<section> <section>
{{ $prev := now.Format "2006"}} <!--start from the current year--> {{ $prev := now.Format "2006"}} <!--start from the current year-->
<h2 class="title is-2 top-pad">{{ $prev }}</h2> {{ range first 1 .Pages.ByPublishDate.Reverse }}
{{if .Date}} <!--also add the header if there are posts during the current year-->
{{if eq $prev (.Date.Format "2006")}} <h2 class="title is-2 top-pad"> {{ $prev }}</h2> {{end}}
{{end}}
{{end}}
{{range .Pages.ByPublishDate.Reverse}} {{range .Pages.ByPublishDate.Reverse}}
{{if .Date}} {{if .Date}}
{{$curr := .Date.Format "2006"}} {{$curr := .Date.Format "2006"}}