aboutsummaryrefslogtreecommitdiff
path: root/templates/macros/macros.html
diff options
context:
space:
mode:
authorJieiku2024-07-05 00:33:36 -0700
committerJieiku2024-07-05 00:33:36 -0700
commit89db3ed9d53bae1eeedd821fcd7fdb620922aa34 (patch)
treec98b4cd5701985e9c5de0ec313721e83c066ced7 /templates/macros/macros.html
parentbdba5bea4f6495499908265af1a249b45892184d (diff)
downloadabridge-89db3ed9d53bae1eeedd821fcd7fdb620922aa34.tar.gz
abridge-89db3ed9d53bae1eeedd821fcd7fdb620922aa34.tar.bz2
abridge-89db3ed9d53bae1eeedd821fcd7fdb620922aa34.zip
Github Style Numbers only Pagination
Diffstat (limited to 'templates/macros/macros.html')
-rw-r--r--templates/macros/macros.html77
1 files changed, 77 insertions, 0 deletions
diff --git a/templates/macros/macros.html b/templates/macros/macros.html
index 9794e5d..dd3fcff 100644
--- a/templates/macros/macros.html
+++ b/templates/macros/macros.html
@@ -299,3 +299,80 @@
</nav>
{%- endif %}
{%- endmacro %}
+
+
+
+{%- macro numpagination(paginator, config)%}
+{%- set uglyurls = config.extra.uglyurls | default(value=false) -%}
+{%- if config.extra.offline %}{% set uglyurls = true %}{% endif %}
+ {%- if paginator.number_pagers > 1 %}
+ {%- if paginator.number_pagers <= 5 %} {# 5 or less pager is simple, just display all 5 #}
+ {%- set start = 1 %}
+ {%- set end = paginator.number_pagers %}
+ {%- endif %}
+
+ {%- if paginator.number_pagers > 5 %}
+
+ {%- if paginator.current_index >= 3 %} {# Check if the first number will be 1 or not #}
+ {%- set start = paginator.current_index - 2 %} {# Set the start number #}
+ {%- if paginator.number_pagers - paginator.current_index < 2 %} {# the last two pages your no longer centered with equal pages start and end #}
+ {%- set difference = paginator.number_pagers - paginator.current_index %}
+ {%- set compensation = 1 - difference %}
+ {%- set start = paginator.current_index - 3 - compensation %} {# however many pages are missing on the end, add offset to start #}
+ {%- endif %}
+ {%- else %}
+ {%- set start = 1 %}
+ {%- endif %}
+
+ {%- if paginator.number_pagers >= paginator.current_index + 2 %} {# Check if the last page is beyond our range #}
+ {%- set end = paginator.current_index + 2 %} {# End is beyond our range so we can safely set it to our range #}
+ {%- if paginator.current_index <= 3 %} {# check offset start, if on page 1 or 2 then set the end to page 5 #}
+ {%- set end = 5 %}
+ {%- endif %}
+ {%- else %}
+ {%- set end = paginator.number_pagers %}
+ {%- endif %}
+ {%- endif %}
+ <nav class="vpad">
+ {%- if paginator.current_index > 6 and paginator.number_pagers > 7 %}
+ <a class="inp on" href="{{ paginator.first | safe }}{%- if uglyurls %}index.html{%- endif %}" title="First Page">1</a>
+ <a class="inp on" href="{{ paginator.base_url | safe }}{{ 2 ~ '/' }}{%- if uglyurls %}index.html{%- endif %}" title="Page 2">2</a>
+ <span class="dis outp">...</span>
+ {%- elif paginator.current_index > 5 and paginator.number_pagers > 7 %}
+ <a class="inp on" href="{{ paginator.first | safe }}{%- if uglyurls %}index.html{%- endif %}" title="First Page">1</a>
+ <a class="inp on" href="{{ paginator.base_url | safe }}{{ 2 ~ '/' }}{%- if uglyurls %}index.html{%- endif %}" title="Page 2">2</a>
+ <a class="inp on" href="{{ paginator.base_url | safe }}{{ 3 ~ '/' }}{%- if uglyurls %}index.html{%- endif %}" title="Page 3">3</a>
+ {%- elif paginator.current_index > 4 and paginator.number_pagers > 6 %}
+ <a class="inp on" href="{{ paginator.first | safe }}{%- if uglyurls %}index.html{%- endif %}" title="First Page">1</a>
+ <a class="inp on" href="{{ paginator.base_url | safe }}{{ 2 ~ '/' }}{%- if uglyurls %}index.html{%- endif %}" title="Page 2">2</a>
+ {%- elif paginator.current_index > 3 and paginator.number_pagers > 5 -%}
+ <a class="inp on" href="{{ paginator.first | safe }}{%- if uglyurls %}index.html{%- endif %}" title="First Page">1</a>
+ {%- endif -%}
+
+ {%- for i in range(start=start, end=end+1) -%}
+ {%- if i == paginator.current_index -%}
+ <a class="inp on cnav" href="#">{{i}}</a>
+ {%- elif i > 1 -%}
+ <a class="inp on" href="{{ paginator.base_url | safe }}{{ i ~ '/' }}{%- if uglyurls %}index.html{%- endif %}">{{i}}</a>
+ {%- else -%}
+ <a class="inp on" href="{{ paginator.first | safe }}{%- if uglyurls %}index.html{%- endif %}">{{ i }}</a>
+ {%- endif -%}
+ {%- endfor -%}
+
+ {%- if paginator.number_pagers > paginator.current_index+5 and paginator.number_pagers > 7 %}
+ <span class="dis outp">...</span>
+ <a class="inp on" href="{{ paginator.last | safe }}{%- if uglyurls %}index.html{%- endif %}" title="Last Page">{{paginator.number_pagers-1}}</a>
+ <a class="inp on" href="{{ paginator.last | safe }}{%- if uglyurls %}index.html{%- endif %}" title="Last Page">{{paginator.number_pagers}}</a>
+ {%- elif paginator.number_pagers > paginator.current_index+4 and paginator.number_pagers > 7 %}
+ <a class="inp on" href="{{ paginator.last | safe }}{%- if uglyurls %}index.html{%- endif %}" title="Last Page">{{paginator.number_pagers-2}}</a>
+ <a class="inp on" href="{{ paginator.last | safe }}{%- if uglyurls %}index.html{%- endif %}" title="Last Page">{{paginator.number_pagers-1}}</a>
+ <a class="inp on" href="{{ paginator.last | safe }}{%- if uglyurls %}index.html{%- endif %}" title="Last Page">{{paginator.number_pagers}}</a>
+ {%- elif paginator.number_pagers > paginator.current_index+3 and paginator.number_pagers > 6 %}
+ <a class="inp on" href="{{ paginator.last | safe }}{%- if uglyurls %}index.html{%- endif %}" title="Last Page">{{paginator.number_pagers-1}}</a>
+ <a class="inp on" href="{{ paginator.last | safe }}{%- if uglyurls %}index.html{%- endif %}" title="Last Page">{{paginator.number_pagers}}</a>
+ {%- elif paginator.number_pagers > paginator.current_index+2 and paginator.number_pagers > 5 %}
+ <a class="inp on" href="{{ paginator.last | safe }}{%- if uglyurls %}index.html{%- endif %}" title="Last Page">{{paginator.number_pagers}}</a>
+ {%- endif -%}
+ </nav>
+ {%- endif %}
+{%- endmacro %}