From 89db3ed9d53bae1eeedd821fcd7fdb620922aa34 Mon Sep 17 00:00:00 2001 From: Jieiku Date: Fri, 5 Jul 2024 00:33:36 -0700 Subject: Github Style Numbers only Pagination --- templates/index.html | 4 +++ templates/macros/macros.html | 77 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) (limited to 'templates') diff --git a/templates/index.html b/templates/index.html index c2ced13..0b1e83f 100644 --- a/templates/index.html +++ b/templates/index.html @@ -59,7 +59,11 @@ This Template can also be used directly for the index eg: example.com/ or as the {%- endif %} {%- endfor %} + {%- if config.extra.arrow_pagination %} {{- macros::pagination(paginator=paginator, config=config) }} + {%- else %} + {{- macros::numpagination(paginator=paginator, config=config) }} + {%- endif %} {%- if config.extra.recent | default(value=true) %} {#- The following line is checking if the template is being used for the root or a section #} 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 @@ {%- 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 %} + + {%- endif %} +{%- endmacro %} -- cgit v1.3.1