diff options
author | thingsym <thingsym@gmail.com> | 2018-11-21 15:39:03 +0300 |
---|---|---|
committer | thingsym <thingsym@gmail.com> | 2018-11-21 15:39:03 +0300 |
commit | 40348514cdd426b7c724e4461b0392f364336856 (patch) | |
tree | 4966f370944824e2b9bac14886ca5c41166e75c5 /layouts | |
parent | f15170e8a690bdf0552a6aa47ba2360e49358971 (diff) |
perf: improve pagination
Diffstat (limited to 'layouts')
-rw-r--r-- | layouts/partials/pagination.html | 70 |
1 files changed, 33 insertions, 37 deletions
diff --git a/layouts/partials/pagination.html b/layouts/partials/pagination.html index fc9d3e7..9d9f82b 100644 --- a/layouts/partials/pagination.html +++ b/layouts/partials/pagination.html @@ -1,46 +1,42 @@ -<div class="navigation"> -<!-- Next prev page --> {{- $currentNode := . -}} +<nav class="pagination"> +{{- template "pagination" dict "menu" .Site.Home "currentnode" $currentNode "menu_exclusion" .Site.Params.menu_exclusion -}} +{{- with ($.Scratch.Get "prevPage") -}} +<a class="nav nav-prev" href="{{ .URL | absURL }}" title="{{ .Title }}"><i class="fas fa-arrow-left" aria-hidden="true"></i> Prev - {{ .Title }}</a> +{{ end -}} +{{- with ($.Scratch.Get "nextPage") -}} +<a class="nav nav-next" href="{{ .URL | absURL }}" title="{{ .Title }}">Next - {{ .Title }} <i class="fas fa-arrow-right" aria-hidden="true"></i></a> +{{- end }} +</nav> -{{- template "menu-nextprev" dict "menu" .Site.Home "currentnode" $currentNode -}} +{{- define "pagination" -}} +{{- $currentNode := .currentnode -}} +{{- $menu_exclusion := .menu_exclusion -}} -{{- define "menu-nextprev" -}} - {{- $currentNode := .currentnode -}} - {{- if hasPrefix $currentNode.URL .menu.URL -}} - {{- $currentNode.Scratch.Set "NextPageOK" "OK" -}} - {{- $currentNode.Scratch.Set "prevPage" ($currentNode.Scratch.Get "prevPageTmp") -}} +{{- if hasPrefix $currentNode.URL .menu.URL -}} + {{- $currentNode.Scratch.Set "NextPageOK" "OK" -}} + {{- $currentNode.Scratch.Set "prevPage" ($currentNode.Scratch.Get "prevPageTmp") -}} +{{- else -}} + {{- if eq ($currentNode.Scratch.Get "NextPageOK") "OK" -}} + {{- $currentNode.Scratch.Set "NextPageOK" nil -}} + {{ if in $menu_exclusion .menu.Section }} {{- else -}} - {{- if eq .menu.Section "blog" -}} - {{- else if eq .menu.Section "archives" -}} - {{- else if eq .menu.Section "entry" -}} - {{- else if eq .menu.Section "posts" -}} - {{- else -}} - {{- if eq ($currentNode.Scratch.Get "NextPageOK") "OK" -}} - {{- $currentNode.Scratch.Set "NextPageOK" nil -}} - {{- $currentNode.Scratch.Set "nextPage" .menu -}} - {{- end -}} - {{- end -}} - {{- end -}} - {{- $currentNode.Scratch.Set "prevPageTmp" .menu -}} - {{- $currentNode.Scratch.Set "pages" .menu.Pages -}} - {{- if .menu.IsHome -}} - {{- $currentNode.Scratch.Set "pages" .menu.Sections -}} - {{- else if .menu.Sections -}} - {{- $currentNode.Scratch.Set "pages" (.menu.Pages | union .menu.Sections) -}} - {{- end -}} - {{- $pages := ($currentNode.Scratch.Get "pages") -}} - {{- range $pages.ByWeight -}} - {{- template "menu-nextprev" dict "menu" . "currentnode" $currentNode -}} + {{- $currentNode.Scratch.Set "nextPage" .menu -}} {{- end -}} + {{- end -}} {{- end -}} -{{- if not $.Site.Params.disableNavChevron -}} - {{- with ($.Scratch.Get "prevPage") -}} -<a class="nav nav-prev" href="{{ .URL | absURL }}" title="{{ .Title }}"><i class="fas fa-arrow-left" aria-hidden="true"></i> Prev - {{ .Title }}</a> - {{ end -}} - {{- with ($.Scratch.Get "nextPage") -}} -<a class="nav nav-next" href="{{ .URL | absURL }}" title="{{ .Title }}">Next - {{ .Title }} <i class="fas fa-arrow-right" aria-hidden="true"></i></a> - {{- end }} + +{{- $currentNode.Scratch.Set "prevPageTmp" .menu -}} +{{- $currentNode.Scratch.Set "pages" .menu.Pages -}} +{{- if .menu.IsHome -}} + {{- $currentNode.Scratch.Set "pages" .menu.Sections -}} +{{- else if .menu.Sections -}} + {{- $currentNode.Scratch.Set "pages" (.menu.Pages | union .menu.Sections) -}} +{{- end -}} +{{- $pages := ($currentNode.Scratch.Get "pages") -}} +{{- range $pages.ByWeight -}} + {{- template "pagination" dict "menu" . "currentnode" $currentNode "menu_exclusion" $menu_exclusion -}} +{{- end -}} {{- end -}} -</div> |