From 77ace237246584661f4ff78282c943c5d7f00e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Wed, 1 Jun 2022 21:01:15 +0800 Subject: [PATCH] :art: Add pagination in home page. --- layouts/index.html | 1 + layouts/partials/pagination.html | 42 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 layouts/partials/pagination.html diff --git a/layouts/index.html b/layouts/index.html index bece7f1..b8baedb 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -60,4 +60,5 @@ {{- end }} +{{- partial "partials/pagination.html" . }} {{- end }} \ No newline at end of file diff --git a/layouts/partials/pagination.html b/layouts/partials/pagination.html new file mode 100644 index 0000000..bd12821 --- /dev/null +++ b/layouts/partials/pagination.html @@ -0,0 +1,42 @@ +{{- $pag := .Paginator }} +{{- $tps := $pag.TotalPages }} + +{{- $begin := sub $pag.PageNumber 4}} +{{- $.Scratch.Set "begin" $begin }} +{{- $end := add $pag.PageNumber 4}} +{{- $.Scratch.Set "end" $end }} + +{{- if lt $begin 0}} + {{- $end := sub $end $begin }} + {{- $.Scratch.Set "end" $end }} +{{- end}} +{{- $end := $.Scratch.Get "end"}} + +{{- $over := sub $tps $end }} + +{{- if lt $over 0}} + {{- $begin := add $begin $over}} + {{- $.Scratch.Set "begin" $begin }} +{{- end }} +{{- $begin := $.Scratch.Get "begin"}} + \ No newline at end of file