blog/themes/chosto/layouts/partials/listitem.html

31 lines
1.5 KiB
HTML
Raw Normal View History

2021-05-21 23:50:10 +02:00
<div class="block">
<a href="{{.Permalink}}">
<time class="post-date" datetime="{{ .Date.Format `2006-01-02T15:04:05Z07:00` | safeHTML }}">
{{ .Date.Day }} {{ index $.Site.Data.months_fr (printf "%d" .Date.Month) }} {{ .Date.Year }}
</time>
|
<!--
Well, I am a beginner with Hugo so this is probably like crushing a banana with a rocket.
When a post belongs to a "case" (i.e. a section with a code, I'd like to have [INDEX/TOTAL] printed in title.
An when a post is on its own, don't print anything.
A little bit like : https://www.hacking-social.com/
But I don't wan't to write it manually because it could break when adding a blog post in between two existing blog posts.
So, iterate over the blog posts with same section as current blog post, order them by date and save the index of current blog post.
Maybe there is an easier way to get the same result...
-->
{{ $currentPost := . }}
{{ $currentPostIndex := 1 }}
{{ $posts := (where $.Site.RegularPages "CurrentSection.Params.Code" "==" $.CurrentSection.Params.Code )}}
{{ $postsSorted := (sort $posts "Date" )}}
{{ range $index, $element := $postsSorted }}
{{ if eq $element.Title $currentPost.Title }}
{{ $currentPostIndex = (add $index 1) }}
{{ end }}
{{ end }}
{{ with .CurrentSection.Params.Code }}
2021-05-22 00:16:10 +02:00
[{{ . }}{{ print $currentPostIndex }}]
{{ end }}
{{ .Title }}
</a>
2021-05-21 23:50:10 +02:00
</div>