adds pagination for index page
This commit is contained in:
parent
367ac4126c
commit
700e10c62f
2 changed files with 50 additions and 12 deletions
|
@ -4,11 +4,12 @@
|
|||
|
||||
{{ define "content" }}
|
||||
<div class="post-list">
|
||||
{{ range (where .Data.Pages "Type" "not in" (slice "about" "portfolio")).GroupBy "Section" }}
|
||||
{{ range .Pages }}
|
||||
{{ $paginator := .Paginate (where .Data.Pages "Type" "posts") }}
|
||||
{{ range $paginator.Pages }}
|
||||
<div class="post-list__item">
|
||||
<span class="item__title--big">
|
||||
<a href="{{ .RelPermalink }}">{{ .Title }}</a>{{ if .Draft }}<sup> <i class="fas fa-pen-square fa-xs"></i></sup>{{ end }}
|
||||
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
|
||||
{{ if .Draft }}<sup><i class="fas fa-comment-dots fa-xs"></i></sup>{{ end }}
|
||||
</span>
|
||||
<span class="item__date">
|
||||
{{ .Date.Format (.Site.Params.dateformat | default "Jan 02, 2006") }}
|
||||
|
@ -19,20 +20,18 @@
|
|||
{{ .Summary }}
|
||||
{{ end }}
|
||||
{{ if .Truncated }}
|
||||
<div class="read-more-link">
|
||||
<a href="{{ .RelPermalink }}">Read More…</a>
|
||||
</div>
|
||||
... <a class="read-more-symbol" href="{{ .RelPermalink }}">➦</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ partial "pagination.html" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ define "footer" }}
|
||||
{{ if .Site.GoogleAnalytics }}
|
||||
{{ if .Site.GoogleAnalytics }}
|
||||
<!-- Google Analytics -->
|
||||
{{ template "_internal/google_analytics_async.html" . }}
|
||||
{{ end }}
|
||||
{{ partial "footer/font-awesome-js.html" . }}
|
||||
{{ end }}
|
||||
{{ partial "footer/font-awesome-js.html" . }}
|
||||
{{ end }}
|
||||
|
|
39
layouts/partials/pagination.html
Normal file
39
layouts/partials/pagination.html
Normal file
|
@ -0,0 +1,39 @@
|
|||
{{ $pag := $.Paginator }}
|
||||
{{ if gt $pag.TotalPages 1 }}
|
||||
<ul class="pagination">
|
||||
{{ with $pag.First }}
|
||||
<li class="page-item">
|
||||
<a href="{{ .URL }}" class="page-link" aria-label="First"><span aria-hidden="true">««</span></a>
|
||||
</li>
|
||||
{{ end }}
|
||||
<li class="page-item{{ if not $pag.HasPrev }} disabled{{ end }}">
|
||||
<a href="{{ if $pag.HasPrev }}{{ $pag.Prev.URL }}{{ end }}" class="page-link" aria-label="Previous"><span aria-hidden="true">«</span></a>
|
||||
</li>
|
||||
{{ $.Scratch.Set "__paginator.ellipsed" false }}
|
||||
{{ range $pag.Pagers }}
|
||||
{{ $right := sub .TotalPages .PageNumber }}
|
||||
{{ $showNumber := or (le .PageNumber 3) (eq $right 0) }}
|
||||
{{ $showNumber := or $showNumber (and (gt .PageNumber (sub $pag.PageNumber 2)) (lt .PageNumber (add $pag.PageNumber 2))) }}
|
||||
{{ if $showNumber }}
|
||||
{{ $.Scratch.Set "__paginator.ellipsed" false }}
|
||||
{{ $.Scratch.Set "__paginator.shouldEllipse" false }}
|
||||
{{ else }}
|
||||
{{ $.Scratch.Set "__paginator.shouldEllipse" (not ($.Scratch.Get "__paginator.ellipsed") ) }}
|
||||
{{ $.Scratch.Set "__paginator.ellipsed" true }}
|
||||
{{ end }}
|
||||
{{ if $showNumber }}
|
||||
<li class="page-item{{ if eq . $pag }} active{{ end }}"><a class="page-link" href="{{ .URL }}">{{ .PageNumber }}</a></li>
|
||||
{{ else if ($.Scratch.Get "__paginator.shouldEllipse") }}
|
||||
<li class="page-item disabled"><span aria-hidden="true"> … </span></li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
<li class="page-item{{ if not $pag.HasNext }} disabled{{ end }}">
|
||||
<a href="{{ if $pag.HasNext }}{{ $pag.Next.URL }}{{ end }}" class="page-link" aria-label="Next"><span aria-hidden="true">»</span></a>
|
||||
</li>
|
||||
{{ with $pag.Last }}
|
||||
<li class="page-item">
|
||||
<a href="{{ .URL }}" class="page-link" aria-label="Last"><span aria-hidden="true">»»</span></a>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
Loading…
Reference in a new issue