fix: pagination in list.html

This commit is contained in:
kbe
2025-08-18 18:16:18 +02:00
parent 0089c93afa
commit 67d08d9865
3 changed files with 93 additions and 32 deletions

View File

@@ -1,21 +1,80 @@
{{ define "main" }} {{ define "main" }}
<div class="posts-list"> {{ $defaultCategory := "General" }}
<h1>{{ .Title }}</h1> {{ if .Site.Params.defaultCategory }}{{ $defaultCategory = .Site.Params.defaultCategory }}{{ end }}
{{ range .Pages }} <div class="section-sm bg-gray-lighter">
<article class="post-preview"> <div class="container text-center">
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2> <h3 class="font-family-playfair">{{ .Title }}</h3>
<div class="post-meta"> </div><!-- end container -->
<time>{{ .Date.Format "Jan 2, 2006" }}</time> </div>
{{ if .Params.author }}
<span>{{ .Params.author }}</span> <!-- Blog section -->
<div class="section">
<div class="container">
<div class="row g-4">
<div class="col-12 col-sm-10 offset-sm-1 col-md-8 offset-md-2">
{{ $paginationLimit := 10 }}
{{ if .Site.Params.paginationLimit }}{{ $paginationLimit = .Site.Params.paginationLimit }}{{ end }}
{{ $paginator := .Paginator $paginationLimit }}
{{ range $paginator.Pages }}
<!-- Blog Post box -->
<div class="mb-5">
<div class="img-link-box">
<a href="{{ .RelPermalink }}">
{{ if .Params.featured_image }}
<img src="{{ .Params.featured_image }}" alt="{{ .Title }}">
{{ else }}
<img src="/assets/images/col-1.jpg" alt="{{ .Title }}">
{{ end }}
</a>
</div>
<div class="mt-4">
<div class="d-flex justify-content-between mb-2">
<div class="d-inline-flex">
{{ if .Params.categories }}
{{ range $index, $category := .Params.categories }}
{{ if $index }}, {{ end }}
{{ if and (eq (printf "%T" $category) "string") }}
<a class="font-family-poppins font-small fw-medium uppercase" href="/categories/{{ $category | urlize }}">{{ $category }}</a>
{{ else if and (eq (printf "%T" $category) "map") }}
{{ if $category.name }}
<a class="font-family-poppins font-small fw-medium uppercase" href="/categories/{{ $category.name | urlize }}">{{ $category.name }}</a>
{{ else }}
<a class="font-family-poppins font-small fw-medium uppercase" href="#">{{ $defaultCategory }}</a>
{{ end }}
{{ else }}
<a class="font-family-poppins font-small fw-medium uppercase" href="#">{{ $defaultCategory }}</a>
{{ end }}
{{ end }}
{{ else }}
<a class="font-family-poppins font-small fw-medium uppercase" href="#">{{ $defaultCategory }}</a>
{{ end }} {{ end }}
</div> </div>
<div class="d-inline-flex">
<span class="font-small">{{ .Date.Format "02/07/2006" }}</span>
</div>
</div>
<h4><a class="text-link-1" href="{{ .RelPermalink }}">{{ .Title }}</a></h4>
{{ if .Params.excerpt }} {{ if .Params.excerpt }}
<p class="post-excerpt">{{ .Params.excerpt }}</p> <p>{{ .Params.excerpt }}</p>
{{ end }} {{ else if .Summary }}
<a href="{{ .RelPermalink }}" class="read-more">Read more →</a> <p>{{ .Summary }}</p>
</article> {{ else }}
<p>{{ truncate 200 .Content }}</p>
{{ end }} {{ end }}
<div class="mt-3">
<a class="button-text-1" href="{{ .RelPermalink }}">Lire la suite</a>
</div> </div>
</div>
</div>
<!-- End Blog Post box -->
{{ end }}
<!-- Pagination -->
{{ partial "pagination.html" (dict "Paginator" .Paginator "Page" .) }}
</div>
</div><!-- end row -->
</div><!-- end container -->
</div>
<!-- end Blog section -->
{{ end }} {{ end }}

View File

@@ -60,7 +60,7 @@
<p>{{ truncate 200 .Content }}</p> <p>{{ truncate 200 .Content }}</p>
{{ end }} {{ end }}
<div class="mt-3"> <div class="mt-3">
<a class="button-text-1" href="{{ .Permalink }}">Read More</a> <a class="button-text-1" href="{{ .Permalink }}">Lire la suite</a>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,23 +1,25 @@
<!-- Pagination --> <!-- Pagination -->
{{ if gt (len .Site.RegularPages) 10 }} {{ $paginator := .Paginator }}
{{ $page := .Page }}
{{ if gt $paginator.TotalPages 1 }}
<nav> <nav>
<ul class="pagination justify-content-center mt-5"> <ul class="pagination justify-content-center mt-5">
<!-- Previous --> <!-- Previous -->
<li class="page-item {{ if not .Paginator.HasPrev }}disabled{{ end }}"> <li class="page-item {{ if not $paginator.HasPrev }}disabled{{ end }}">
{{ if .Paginator.HasPrev }} {{ if $paginator.HasPrev }}
<a class="page-link" href="{{ .Paginator.Prev.URL }}">&laquo; Previous</a> <a class="page-link" href="{{ $paginator.Prev.URL }}">&laquo; Précédent</a>
{{ else }} {{ else }}
<a class="page-link" href="#">&laquo; Previous</a> <a class="page-link" href="#">&laquo; Précédent</a>
{{ end }} {{ end }}
</li> </li>
<!-- Page numbers --> <!-- Page numbers -->
{{ $currentPage := .Paginator.PageNumber }} {{ $currentPage := $paginator.PageNumber }}
{{ $totalPages := .Paginator.TotalPages }} {{ $totalPages := $paginator.TotalPages }}
<!-- Always show first page --> <!-- Always show first page -->
<li class="page-item {{ if eq $currentPage 1 }}active{{ end }}"> <li class="page-item {{ if eq $currentPage 1 }}active{{ end }}">
<a class="page-link" href="{{ .Paginator.First.URL }}">1</a> <a class="page-link" href="{{ $paginator.First.URL }}">1</a>
</li> </li>
<!-- Show ellipsis if current page is > 4 --> <!-- Show ellipsis if current page is > 4 -->
@@ -28,7 +30,7 @@
{{ end }} {{ end }}
<!-- Show pages around current page --> <!-- Show pages around current page -->
{{ range .Paginator.Pagers }} {{ range $paginator.Pagers }}
{{ $pageNumber := .PageNumber }} {{ $pageNumber := .PageNumber }}
{{ if and (gt $pageNumber 1) (lt $pageNumber $totalPages) (ge $pageNumber (sub $currentPage 1)) (le $pageNumber (add $currentPage 1)) }} {{ if and (gt $pageNumber 1) (lt $pageNumber $totalPages) (ge $pageNumber (sub $currentPage 1)) (le $pageNumber (add $currentPage 1)) }}
{{ if ne $pageNumber 1 }} {{ if ne $pageNumber 1 }}
@@ -51,16 +53,16 @@
<!-- Always show last page --> <!-- Always show last page -->
{{ if gt $totalPages 1 }} {{ if gt $totalPages 1 }}
<li class="page-item {{ if eq $currentPage $totalPages }}active{{ end }}"> <li class="page-item {{ if eq $currentPage $totalPages }}active{{ end }}">
<a class="page-link" href="{{ .Paginator.Last.URL }}">{{ $totalPages }}</a> <a class="page-link" href="{{ $paginator.Last.URL }}">{{ $totalPages }}</a>
</li> </li>
{{ end }} {{ end }}
<!-- Next --> <!-- Next -->
<li class="page-item {{ if not .Paginator.HasNext }}disabled{{ end }}"> <li class="page-item {{ if not $paginator.HasNext }}disabled{{ end }}">
{{ if .Paginator.HasNext }} {{ if $paginator.HasNext }}
<a class="page-link" href="{{ .Paginator.Next.URL }}">Next &raquo;</a> <a class="page-link" href="{{ $paginator.Next.URL }}">Suivant &raquo;</a>
{{ else }} {{ else }}
<a class="page-link" href="#">Next &raquo;</a> <a class="page-link" href="#">Suivant &raquo;</a>
{{ end }} {{ end }}
</li> </li>
</ul> </ul>