2021-05-21 23:50:10 +02:00
|
|
|
<div class="block">
|
2021-05-18 17:07:00 +02:00
|
|
|
<a href="{{.Permalink}}">
|
2021-05-19 18:08:47 +02:00
|
|
|
<!--
|
|
|
|
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 }}]
|
2021-05-19 18:08:47 +02:00
|
|
|
{{ end }}
|
|
|
|
{{ .Title }}
|
|
|
|
</a>
|
2021-05-21 23:50:10 +02:00
|
|
|
</div>
|