Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pagination.html « partials « layouts - github.com/fourtyone11/origin-hugo-theme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 12f7eb00412572b72b1fa479e3dc3ed0f3b0843e (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!--
//
//  OUTPUT POSTS
//––––––––––––––––––––––––––––––––––––––––––––––––––
-->
{{ $paginator := .Paginate (where .Data.Pages "Type" "posts") }}

<!--
//
//  PAGE NUMBERS
//––––––––––––––––––––––––––––––––––––––––––––––––––
-->
{{ $paginator := .Paginator }}

<!-- Number of links either side of the current page. -->
{{ $adjacent_links := 2 }}

<!-- $max_links = ($adjacent_links * 2) + 1 -->
{{ $max_links := (add (mul $adjacent_links 2) 1) }}

<!-- $lower_limit = $adjacent_links + 1 -->
{{ $lower_limit := (add $adjacent_links 1) }}

<!-- $upper_limit = $paginator.TotalPages - $adjacent_links -->
{{ $upper_limit := (sub $paginator.TotalPages $adjacent_links) }}

<!-- If there's more than one page. -->
{{ if gt $paginator.TotalPages 1 }}

  <div class="pagination">
    
    <!-- First page. -->
    {{ if ne $paginator.PageNumber 1 }}
    <div class="pagination__item pagination__item--first">
      <a aria-label="first page" class="pagination__link pagination__link--first" href="{{ $paginator.First.URL }}">
        <svg transform="rotate(180)" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24" viewBox="0 0 24 24" width="24"><g><rect fill="none" height="24" width="24"/></g><g><g><polygon points="15.5,5 11,5 16,12 11,19 15.5,19 20.5,12"/><polygon points="8.5,5 4,5 9,12 4,19 8.5,19 13.5,12"/></g></g></svg>
      </a>
    </div>
    {{ end }}

    <!-- Previous page. -->
    {{ if $paginator.HasPrev }}
    <div class="pagination__item pagination__item--previous">
      <a aria-label="previous page" href="{{ $paginator.Prev.URL }}" class="pagination__link pagination__link--previous">
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/><path d="M0 0h24v24H0z" fill="none"/></svg>
      </a>
    </div>
    {{ end }}
    <div class="pagination__pagenums"> 
    <!-- Page numbers. -->
    {{ range $paginator.Pagers }}
    
      {{ $.Scratch.Set "page_number_flag" false }}

      
      <!-- Advanced page numbers. -->
      {{ if gt $paginator.TotalPages $max_links }}


        <!-- Lower limit pages. -->
        <!-- If the user is on a page which is in the lower limit.  -->
        {{ if le $paginator.PageNumber $lower_limit }}

          <!-- If the current loop page is less than max_links. -->
          {{ if le .PageNumber $max_links }}
            {{ $.Scratch.Set "page_number_flag" true }}
          {{ end }}


        <!-- Upper limit pages. -->
        <!-- If the user is on a page which is in the upper limit. -->
        {{ else if ge $paginator.PageNumber $upper_limit }}

          <!-- If the current loop page is greater than total pages minus $max_links -->
          {{ if gt .PageNumber (sub $paginator.TotalPages $max_links) }}
            {{ $.Scratch.Set "page_number_flag" true }}
          {{ end }}


        <!-- Middle pages. -->
        {{ else }}
          
          {{ if and ( ge .PageNumber (sub $paginator.PageNumber $adjacent_links) ) ( le .PageNumber (add $paginator.PageNumber $adjacent_links) ) }}
            {{ $.Scratch.Set "page_number_flag" true }}
          {{ end }}

        {{ end }}

      
      <!-- Simple page numbers. -->
      {{ else }}

        {{ $.Scratch.Set "page_number_flag" true }}

      {{ end }}

      <!-- Output page numbers. -->
      {{ if eq ($.Scratch.Get "page_number_flag") true }}
        <div class="pagination__item{{ if eq . $paginator }} pagination__item--current{{ end }}">
          <a href="{{ .URL }}" class="pagination__link">
            {{ .PageNumber }}
          </a>
        </div>
      {{ end }}

    {{ end }}
    </div>

    <!-- Next page. -->
    {{ if $paginator.HasNext }}
    <div class="pagination__item pagination__item--next">
      <a aria-label="next page" href="{{ $paginator.Next.URL }}" class="pagination__link pagination__link--next">
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/><path d="M0 0h24v24H0z" fill="none"/></svg>
      </a>
    </div>
    {{ end }}

    <!-- Last page. -->
    {{ if ne $paginator.PageNumber $paginator.TotalPages }}
    <div class="pagination__item pagination__item--last">
      <a aria-label="last page" class="pagination__link pagination__link--last" href="{{ $paginator.Last.URL }}">
        <svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24" viewBox="0 0 24 24" width="24"><g><rect fill="none" height="24" width="24"/></g><g><g><polygon points="15.5,5 11,5 16,12 11,19 15.5,19 20.5,12"/><polygon points="8.5,5 4,5 9,12 4,19 8.5,19 13.5,12"/></g></g></svg>
      </a>
    </div>
    {{ end }}

  </div><!-- .pagination -->
{{ end }}