From 18409c84e0828a7469301d62bfc39b98bd64858b Mon Sep 17 00:00:00 2001 From: Daniel-I-Am Date: Sun, 12 Jun 2022 18:34:18 +0200 Subject: [PATCH] Add pagination --- assets/sass/_pagination.scss | 56 ++++++++++++++++++++++++++++++ assets/sass/app.scss | 1 + layouts/partials/generic-list.html | 24 +++++++++++-- layouts/partials/snippet-list.html | 4 ++- layouts/snippets/list.html | 2 +- 5 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 assets/sass/_pagination.scss diff --git a/assets/sass/_pagination.scss b/assets/sass/_pagination.scss new file mode 100644 index 0000000..0a21c33 --- /dev/null +++ b/assets/sass/_pagination.scss @@ -0,0 +1,56 @@ +.pagination { + display: flex; + margin: 2rem auto 0; + max-width: 150px; + justify-content: space-evenly; + + list-style: none; + user-select: none; + + .page-item { + a { + transition: background-color 100ms ease-in; + background-color: rgba(white, 0.05); + padding: 1rem; + + text-decoration: none; + + &:hover { + background-color: rgba(white, 0.1); + } + } + + &.disabled, + &.active { + a { + cursor: not-allowed; + } + } + + &.disabled { + a { + background-color: rgba(white, 0.025); + } + } + + &.active { + a { + background-color: rgba(white, 0.1); + } + } + + &:first-child { + a { + border-top-left-radius: 1rem; + border-bottom-left-radius: 1rem; + } + } + + &:last-child { + a { + border-top-right-radius: 1rem; + border-bottom-right-radius: 1rem; + } + } + } +} diff --git a/assets/sass/app.scss b/assets/sass/app.scss index 414cc63..64d5e0f 100644 --- a/assets/sass/app.scss +++ b/assets/sass/app.scss @@ -16,4 +16,5 @@ // Component-specific styling @import "compact-list"; +@import "pagination"; @import "list"; diff --git a/layouts/partials/generic-list.html b/layouts/partials/generic-list.html index d5847fa..2d248b1 100644 --- a/layouts/partials/generic-list.html +++ b/layouts/partials/generic-list.html @@ -1,7 +1,11 @@ +{{ $page := index $ "page" }} + {{ $labelSingular := index $ "labelSingular" }} +{{ $pageType := index $ "pageType"}} + +{{ $pagination := index $ "pagination" }} {{ $labelPlural := or (index $ "labelPlural") (print $labelSingular "s") }} {{ $maximumListSize := or (index $ "maximumListSize") 3 }} -{{ $pageType := index $ "pageType"}} {{ $viewAllHref := or (index $ "viewAllHref") (print "/" $labelPlural) }}
@@ -16,7 +20,22 @@
    - {{ range ( first $maximumListSize (where site.RegularPages "Type" $pageType).ByDate.Reverse ) }} + {{ $entries := (where site.RegularPages "Type" $pageType).ByDate.Reverse }} + + {{ if $pagination }} + {{ $paginator := $page.Paginate $entries }} + {{ range $paginator.Pages }} +
  • + {{ index $ +
    +

    {{ .Title }}

    + {{ .Date.Format "January 2, 2006" }} +
    +
  • + {{ end }} + {{ template "_internal/pagination.html" $page }} + {{ else }} + {{ range ( first $maximumListSize $entries ) }}
  • {{ index $
    @@ -25,6 +44,7 @@
  • {{ end }} + {{ end }}
diff --git a/layouts/partials/snippet-list.html b/layouts/partials/snippet-list.html index e950664..87dc7b5 100644 --- a/layouts/partials/snippet-list.html +++ b/layouts/partials/snippet-list.html @@ -1,3 +1,5 @@ {{ $showViewAllButton := or (index $ "showViewAllButton") false }} +{{ $pagination := or (index $ "pagination") false }} +{{ $page := index $ "page" }} -{{ partial "generic-list" (dict "labelSingular" "snippet" "pageType" "snippets" "showViewAllButton" $showViewAllButton) }} +{{ partial "generic-list" (dict "labelSingular" "snippet" "pageType" "snippets" "showViewAllButton" $showViewAllButton "page" $page "pagination" $pagination) }} diff --git a/layouts/snippets/list.html b/layouts/snippets/list.html index bcb51de..81e035e 100644 --- a/layouts/snippets/list.html +++ b/layouts/snippets/list.html @@ -1,3 +1,3 @@ {{ define "main" }} -{{ partial "snippet-list" (dict) }} +{{ partial "snippet-list" (dict "page" . "pagination" true) }} {{ end }}