feat(theme): pagination navigation
refactored out of the list template into its own partial features: - hidden if there's only 1 page - shows up to 5 page numbers along with links to previous/next and first/last - hide first/last if within 1 page from end - ellipses denoting page numbers not shownpull/3/head
parent
0b977fa65d
commit
0cf3f0aaad
|
|
@ -25,19 +25,7 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ if gt $paginator.TotalPages 1 }}
|
{{- partial "pagination.html" . -}}
|
||||||
<div class="row" style="margin-top: 2em">
|
|
||||||
<nav aria-label="Page navigation">
|
|
||||||
<ul class="pagination">
|
|
||||||
{{ range $paginator.Pagers }}
|
|
||||||
<li class="page-item {{ if eq $paginator.PageNumber .PageNumber }}active{{ end }}">
|
|
||||||
<a class="page-link" href="{{ .URL }}">{{.PageNumber}}</a>
|
|
||||||
</li>
|
|
||||||
{{ end }}
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
</div>
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
<script src="/js/masonry.js"></script>
|
<script src="/js/masonry.js"></script>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
{{ $paginator := $.Paginator }}
|
||||||
|
{{ if ne .Kind "home" }}
|
||||||
|
{{ $paginator = .Data }}
|
||||||
|
{{ end }}
|
||||||
|
{{ if gt $paginator.TotalPages 1 }}
|
||||||
|
{{ $.Scratch.Set "dot_rendered" false }}
|
||||||
|
<nav aria-label="page navigation">
|
||||||
|
<ul class="pagination">
|
||||||
|
{{ if and (ne $paginator.PageNumber 1) (ne $paginator.PageNumber 2) }}
|
||||||
|
<li class="page-item"><a href="{{ $paginator.First.URL }}" rel="first" class="page-link">« First</a></li>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ if $paginator.HasPrev }}
|
||||||
|
<li class="page-item"><a href="{{ $paginator.Prev.URL }}" rel="prev" class="page-link">‹ Prev</a></li>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ range $paginator.Pagers }}
|
||||||
|
{{ if eq . $paginator }}
|
||||||
|
<li class="page-item active"><a href="{{ .URL }}" class="page-link">{{ .PageNumber }}</a></li>
|
||||||
|
{{ else if and (ge .PageNumber (sub $paginator.PageNumber 2)) (le .PageNumber (add $paginator.PageNumber 2)) }}
|
||||||
|
{{ $.Scratch.Set "dot_rendered" false }}
|
||||||
|
<li class="page-item"><a href="{{ .URL }}" class="page-link">{{ .PageNumber }}</a></li>
|
||||||
|
{{ else if eq ($.Scratch.Get "dot_rendered") false }}
|
||||||
|
{{ $.Scratch.Set "dot_rendered" true }}
|
||||||
|
<li class="page-item disabled"><a class="page-link">...</a></li>
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ if $paginator.HasNext }}
|
||||||
|
<li class="page-item"><a href="{{ $paginator.Next.URL }}" rel="next" class="page-link">Next ›</a></li>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ if and (ne $paginator.PageNumber $paginator.TotalPages) ((ne $paginator.PageNumber (sub $paginator.TotalPages 1))) }}
|
||||||
|
<li class="page-item"><a href="{{ $paginator.Last.URL }}" rel="last" class="page-link">Last »</a></li>
|
||||||
|
{{ end }}
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
{{ end }}
|
||||||
|
|
@ -1,3 +1,38 @@
|
||||||
|
/* post styles */
|
||||||
article p img {
|
article p img {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* pagination styles */
|
||||||
|
.pagination {
|
||||||
|
display: flex;
|
||||||
|
list-style: none;
|
||||||
|
border-radius: .25rem;
|
||||||
|
margin: 20px 0;
|
||||||
|
padding: 0;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-item {
|
||||||
|
position: relative;
|
||||||
|
display: block;
|
||||||
|
padding: 0.5em;
|
||||||
|
margin: 0.25em;
|
||||||
|
line-height: 1.25;
|
||||||
|
border: 1px dashed;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-item.active {
|
||||||
|
background: #1EAEDB;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-item.active .page-link {
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-item.disabled .page-link {
|
||||||
|
color: #6c757d;
|
||||||
|
pointer-events: none;
|
||||||
|
cursor: auto;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue