feat: add pagination

gh-pages
nodejh 4 years ago
parent 180c9c61d6
commit 4389d68302

@ -2,40 +2,43 @@
{{ partial "profile.html" . }} {{ partial "profile.html" . }}
<div id="list-page"> <div id="list-page">
{{ $pages := where .Site.RegularPages "Params.hidden" "ne" "true" }} {{ $pages := .Site.RegularPages }}
{{ $paginator := .Paginate ($pages) }} {{ $paginator := .Paginate ($pages) }}
{{ range $paginator.Pages }} {{ range $paginator.Pages }}
{{ $title := .Title }} {{ $title := .Title }}
{{ $summary := .Summary }} {{ $summary := .Summary }}
{{ $date := dateFormat "Jan 2, 2006" .Date }}
<section class="item"> <section class="item">
<div> <div>
<h1 class="title"><a href='{{ .RelPermalink }}'>{{ $title }}</a></h1> <h1 class="title"><a href='{{ .RelPermalink }}'>{{ $title }}</a></h1>
<div class="date">{{ .Date.Format "Jan 2" }}</div> <div class="date">{{ $date }}</div>
</div> </div>
<div class="summary">{{ $summary | plainify | htmlUnescape }}</div> <div class="summary">{{ $summary | plainify | htmlUnescape }}</div>
</section>
{{ end }}
{{ if or ($paginator.HasPrev) ($paginator.HasNext) }}
{{ with .Resources.ByType "image" }} <div class="pagination">
{{ $image := index . 1 }} {{ if $paginator.HasPrev }}
{{ range . }} <span class="prev">
{{ if eq .Name "images/cover.png" }} <a href="{{.Paginator.Prev.URL}}">
{{ $image = . }} <span class="arrow"></span> {{ with .Site.Params.newerPosts }}{{ . }}{{ else }}Newer Posts{{ end }}
{{ else if eq .Name "images/cover.jpg" }} </a>
{{ $image = . }} </span>
{{ else if eq .Name "images/cover.jpeg" }}
{{ $image = . }}
{{ end }}
{{ end }}
<div class="cover">
<img src="{{ $image.RelPermalink }}" alt="{{ $title }}">
</div>
{{ end }} {{ end }}
</section> {{ if $paginator.HasNext }}
<span class="next">
<a href="{{.Paginator.Next.URL}}">
{{ with .Site.Params.olderPosts }}{{ . }}{{ else }}Older Posts{{ end }} <span class="arrow"></span>
</a>
</span>
{{ end }}
</div>
{{ end }} {{ end }}
</div> </div>
{{ end }} {{ end }}

@ -252,7 +252,7 @@ nav.navigation a.button {
} }
#list-page .summary { #list-page .summary {
color: #6a737d; color: #8c8c8c;
margin-top: 12px; margin-top: 12px;
} }
@ -266,3 +266,17 @@ nav.navigation a.button {
width: 100%; width: 100%;
text-align: center; text-align: center;
} }
#list-page .pagination {
margin: 48px 0;
width: 100%;
height: 32px;
margin-top: 48px;
}
#list-page .pagination .pre {
float: left;
}
#list-page .pagination .next {
float: right;
}
Loading…
Cancel
Save