-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.html
70 lines (63 loc) · 2.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
{{ define "main" }}
<!-- Have the paginator list posts, sorted by last modified date, most recent first -->
{{ $paginator := .Paginate (.Pages.ByLastmod.Reverse) 10 }}
<div class="posts">
<!-- http://justindunham.net/blog-bells-and-whistles-in-hugo/ -->
{{ range $paginator.Pages }}
{{ .Render "summary"}}
{{ end }}
</div>
<p>
<div class="pagination">
<!-- https://discourse.gohugo.io/t/solved-big-pagination-need-add/6576/8?u=kaushalmodi -->
{{ $window := .Site.Params.paginateWindow | default 1 }}
{{ if gt $paginator.TotalPages 1 }}
{{ $total := $paginator.TotalPages }}
{{ $size := add 7 (add $window $window) }}
{{ $cur := $paginator.PageNumber }}
{{ if gt $total $size }}
{{ if lt $cur (sub $size (add $window 1)) }}
{{ $.Scratch.Set "show" (seq 1 (sub $size 2)) }}
{{ else if lt (sub $total $cur) (sub $size (add $window 2)) }}
{{ $.Scratch.Set "show" (seq (add (sub $total $size) 3) $total) }}
{{ else }}
{{ $.Scratch.Set "show" (seq (sub $cur $window) (add $cur $window)) }}
{{ end }}
{{ $.Scratch.Add "show" 1 }}
{{ $.Scratch.Add "show" $total }}
{{ else }}
{{ $.Scratch.Set "show" (seq 1 $total) }}
{{ end }}
<!-- https://gohugo.io/templates/pagination/#build-the-navigation -->
{{ range $paginator.Pagers }}
{{ $cur := .PageNumber }}
{{ if in ($.Scratch.Get "show") $cur }}
<a href="{{ .URL }}">
{{- if eq . $paginator -}}<b>{{- end -}}
{{ .PageNumber }}
{{- if eq . $paginator -}}</b>{{- end -}}
</a>
{{ else if in (slice 2 (sub $total 1)) $cur }}
<a name="">…</a>
{{ end }}
{{ end }}
{{ end }}
[
{{ if .Paginator.HasPrev }}
<a href="{{ .Paginator.Prev.URL }}">Newer</a>
{{ end }}
{{ if .Paginator.HasNext }}
<a href="{{ .Paginator.Next.URL }}">Older</a>
{{ end }}
]
</div>
</p>
{{ if (eq 1 $paginator.PageNumber) }}
<hr>
<h3 id="debug">SiteInfo (Debug)</h3>
{{ partial "debugprint.html" .Site }}
<hr>
<h3 id="debug-menu">Menu (Debug)</h3>
{{ partial "debugprint.html" .Site.Menus }}
{{ end }}
{{ end }}