From 6cf2997babcb488b14da04db0ba4a281dec6b942 Mon Sep 17 00:00:00 2001 From: Jieiku Date: Tue, 31 May 2022 01:19:49 -0700 Subject: Paginator Improvements --- .nojekyll | 1 + sass/include/_nav.scss | 14 ++++++++++++ templates/macros/macros.html | 53 ++++++++++++++++++++++++++++++++++---------- 3 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 .nojekyll diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.nojekyll @@ -0,0 +1 @@ + diff --git a/sass/include/_nav.scss b/sass/include/_nav.scss index dbde885..999d296 100644 --- a/sass/include/_nav.scss +++ b/sass/include/_nav.scss @@ -7,6 +7,20 @@ } main nav { margin-top: var(--s2);//pagination margin + ul li:nth-child(-n+2) { + margin-right: var(--s2); //pagination prev/first padding + } + ul li:nth-last-child(-n+2) { + margin-left: var(--s2); //pagination next/last padding + } +} +.off { + color: var(--c4); + font-weight: var(--fh); + border: .1rem solid var(--c4); + border-radius: var(--br); + padding: .1rem var(--s1); + margin: .1rem; } main nav a, main nav a:visited {//pagination link styling diff --git a/templates/macros/macros.html b/templates/macros/macros.html index 454854a..e4fcf73 100644 --- a/templates/macros/macros.html +++ b/templates/macros/macros.html @@ -23,21 +23,50 @@ {%- macro pagination(paginator)%} {%- 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 %} -- cgit v1.3.1