Add [INDEX/COUNT] prefix for articles in cases (ie sections with Params.Code)

master
Quentin Duchemin 2021-05-19 18:08:47 +02:00
parent 9cf3825835
commit 0308ea1a5d
Signed by: Chosto
GPG Key ID: 0547178FEEDE7D6B
5 changed files with 38 additions and 19 deletions

View File

@ -1,7 +1,7 @@
---
title: Smartphone
subtitle: Que faire de notre addiction ?
code: ST
code: SP
---
Ce dossier réfléchit à...

File diff suppressed because one or more lines are too long

View File

@ -5,10 +5,10 @@
{{ .Content }}
</div>
<div>
{{ template "_internal/pagination.html" . }}
{{ range .Paginator.Pages }}
{{ .Render "summary" }}
{{ end }}
{{ template "_internal/pagination.html" . }}
</div>
</main>
{{ end }}

View File

@ -3,6 +3,29 @@
<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>
| {{.Title}}
</a>
|
<!--
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" )}}
{{ $postCounts := len $postsSorted }}
{{ range $index, $element := $postsSorted }}
{{ if eq $element.Title $currentPost.Title }}
{{ $currentPostIndex = (add $index 1) }}
{{ end }}
{{ end }}
{{ with .CurrentSection.Params.Code }}
[{{ . }} {{ print $currentPostIndex }}/{{ print $postCounts }}]
{{ end }}
{{ .Title }}
</a>
</li>

View File

@ -1,12 +1,4 @@
{{ define "main" }}
<section id="main">
<h1 id="title">{{ .Title }}</h1>
<div>
<article id="content">
{{ .Content }}
</article>
</div>
</section>
<aside id="meta">
<div>
<section>
@ -22,14 +14,17 @@
{{ end }}
</ul>
{{ end }}
{{ with .Params.tags }}
<ul id="tags">
{{ range . }}
<li> <a href="{{ "tags" | absURL }}/{{ . | urlize }}">{{ . }}</a> </li>
{{ end }}
</ul>
{{ end }}
</div>
</aside>
<section id="main">
<h1 id="title">{{ .Title }}</h1>
<div>
<article id="content">
{{ .Content }}
</article>
</div>
</section>
<aside id="prev_next">
<div>
{{ with .PrevInSection }}
<a class="previous" href="{{ .Permalink }}"> {{ .Title }}</a>