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>
{{ $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}}
{{if .Date}}
{{$curr := .Date.Format "2006"}}
@ -16,4 +21,4 @@
{{ $prev = $curr}}
{{end}}
{{end}}
</section>
</section>