Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Mooring <joe.mooring@veriphor.com>2021-06-08 11:41:21 +0300
committerGitHub <noreply@github.com>2021-06-08 11:41:21 +0300
commit73483d0f9eb46838d41640f88cc05c1d16811dc5 (patch)
tree0c0bd410f7c4ea98f264076fe5cd3d0e50b3f750 /tpl/tplimpl
parent9b5debe4b820132759cfdf7bff7fe9c1ad0a6bb1 (diff)
tpl: Add a terse pagination template variant to improve performance
These calls are equivalent: {{ template "_internal/pagination.html" . }} {{ template "_internal/pagination.html" (dict "page" .) }} {{ template "_internal/pagination.html" (dict "page" . "format" "default") }} To use an alternate format: {{ template "_internal/pagination.html" (dict "page" . "format" "terse") }} Fixes #8599
Diffstat (limited to 'tpl/tplimpl')
-rw-r--r--tpl/tplimpl/embedded/templates.autogen.go195
-rw-r--r--tpl/tplimpl/embedded/templates/pagination.html195
2 files changed, 304 insertions, 86 deletions
diff --git a/tpl/tplimpl/embedded/templates.autogen.go b/tpl/tplimpl/embedded/templates.autogen.go
index c8732a914..9584077ef 100644
--- a/tpl/tplimpl/embedded/templates.autogen.go
+++ b/tpl/tplimpl/embedded/templates.autogen.go
@@ -248,51 +248,160 @@ if (!doNotTrack) {
{{- /* Facebook Page Admin ID for Domain Insights */}}
{{- with .Site.Social.facebook_admin }}<meta property="fb:admins" content="{{ . }}" />{{ end }}
`},
- {`pagination.html`, `{{ $pag := $.Paginator }}
-{{ if gt $pag.TotalPages 1 -}}
-<ul class="pagination">
- {{ with $pag.First -}}
- <li class="page-item">
- <a href="{{ .URL }}" class="page-link" aria-label="First"><span aria-hidden="true">&laquo;&laquo;</span></a>
- </li>
- {{ end -}}
- <li class="page-item{{ if not $pag.HasPrev }} disabled{{ end }}">
- <a {{ if $pag.HasPrev }}href="{{ $pag.Prev.URL }}"{{ end }} class="page-link" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a>
- </li>
- {{- $ellipsed := false -}}
- {{- $shouldEllipse := false -}}
- {{- range $pag.Pagers -}}
- {{- $right := sub .TotalPages .PageNumber -}}
- {{- $showNumber := or (le .PageNumber 3) (eq $right 0) -}}
- {{- $showNumber := or $showNumber (le .TotalPages 5) -}}{{/* Issue #7523 */}}
- {{- $showNumber := or $showNumber (and (gt .PageNumber (sub $pag.PageNumber 2)) (lt .PageNumber (add $pag.PageNumber 2))) -}}
- {{- if $showNumber -}}
- {{- $ellipsed = false -}}
- {{- $shouldEllipse = false -}}
- {{- else -}}
- {{- $shouldEllipse = not $ellipsed -}}
- {{- $ellipsed = true -}}
- {{- end -}}
- {{- if $showNumber }}
- <li class="page-item{{ if eq . $pag }} active{{ end }}">
- <a class="page-link" href="{{ .URL }}">{{ .PageNumber }}</a>
- </li>
- {{- else if $shouldEllipse }}
- <li class="page-item disabled">
- <span aria-hidden="true">&nbsp;&hellip;&nbsp;</span>
- </li>
- {{- end -}}
+ {`pagination.html`, `{{- $validFormats := slice "default" "terse" }}
+
+{{- $msg1 := "When passing a map to the internal pagination template, one of the elements must be named 'page', and it must be set to the context of the current page." }}
+{{- $msg2 := "The 'format' specified in the map passed to the internal pagination template is invalid. Valid choices are: %s." }}
+
+{{- $page := . }}
+{{- $format := "default" }}
+
+{{- if reflect.IsMap . }}
+ {{- with .page }}
+ {{- $page = . }}
+ {{- else }}
+ {{- errorf $msg1 }}
{{- end }}
- <li class="page-item{{ if not $pag.HasNext }} disabled{{ end }}">
- <a {{ if $pag.HasNext }}href="{{ $pag.Next.URL }}"{{ end }} class="page-link" aria-label="Next"><span aria-hidden="true">&raquo;</span></a>
- </li>
- {{- with $pag.Last }}
- <li class="page-item">
- <a href="{{ .URL }}" class="page-link" aria-label="Last"><span aria-hidden="true">&raquo;&raquo;</span></a>
- </li>
+ {{- with .format }}
+ {{- $format = lower . }}
{{- end }}
-</ul>
-{{ end }}
+{{- end }}
+
+{{- if in $validFormats $format }}
+ {{- if gt $page.Paginator.TotalPages 1 }}
+ <ul class="pagination pagination-{{ $format }}">
+ {{- partial (printf "partials/inline/pagination/%s" $format) $page }}
+ </ul>
+ {{- end }}
+{{- else }}
+ {{- errorf $msg2 (delimit $validFormats ", ") }}
+{{- end -}}
+
+{{/* Format: default
+{{/* --------------------------------------------------------------------- */}}
+{{- define "partials/inline/pagination/default" }}
+ {{- with .Paginator }}
+ {{- $currentPageNumber := .PageNumber }}
+
+ {{- with .First }}
+ {{- if ne $currentPageNumber .PageNumber }}
+ <li class="page-item">
+ <a href="{{ .URL }}" aria-label="First" class="page-link" role="button"><span aria-hidden="true">&laquo;&laquo;</span></a>
+ </li>
+ {{- else }}
+ <li class="page-item disabled">
+ <a href="#" aria-disabled="true" aria-label="First" class="page-link" role="button"><span aria-hidden="true">&laquo;&laquo;</span></a>
+ </li>
+ {{- end }}
+ {{- end }}
+
+ {{- with .Prev }}
+ <li class="page-item">
+ <a href="{{ .URL }}" aria-label="Previous" class="page-link" role="button"><span aria-hidden="true">&laquo;</span></a>
+ </li>
+ {{- else }}
+ <li class="page-item disabled">
+ <a href="#" aria-disabled="true" aria-label="Previous" class="page-link" role="button"><span aria-hidden="true">&laquo;</span></a>
+ </li>
+ {{- end }}
+
+ {{- $slots := 5 }}
+ {{- $start := math.Max 1 (sub .PageNumber (math.Floor (div $slots 2))) }}
+ {{- $end := math.Min .TotalPages (sub (add $start $slots) 1) }}
+ {{- if lt (add (sub $end $start) 1) $slots }}
+ {{- $start = math.Max 1 (add (sub $end $slots) 1) }}
+ {{- end }}
+
+ {{- range $k := seq $start $end }}
+ {{- if eq $.Paginator.PageNumber $k }}
+ <li class="page-item active">
+ <a href="#" aria-current="page" aria-label="Page {{ $k }}" class="page-link" role="button">{{ $k }}</a>
+ </li>
+ {{- else }}
+ <li class="page-item">
+ <a href="{{ (index $.Paginator.Pagers (sub $k 1)).URL }}" aria-label="Page {{ $k }}" class="page-link" role="button">{{ $k }}</a>
+ </li>
+ {{- end }}
+ {{- end }}
+
+ {{- with .Next }}
+ <li class="page-item">
+ <a href="{{ .URL }}" aria-label="Next" class="page-link" role="button"><span aria-hidden="true">&raquo;</span></a>
+ </li>
+ {{- else }}
+ <li class="page-item disabled">
+ <a href="#" aria-disabled="true" aria-label="Next" class="page-link" role="button"><span aria-hidden="true">&raquo;</span></a>
+ </li>
+ {{- end }}
+
+ {{- with .Last }}
+ {{- if ne $currentPageNumber .PageNumber }}
+ <li class="page-item">
+ <a href="{{ .URL }}" aria-label="Last" class="page-link" role="button"><span aria-hidden="true">&raquo;&raquo;</span></a>
+ </li>
+ {{- else }}
+ <li class="page-item disabled">
+ <a href="#" aria-disabled="true" aria-label="Last" class="page-link" role="button"><span aria-hidden="true">&raquo;&raquo;</span></a>
+ </li>
+ {{- end }}
+ {{- end }}
+ {{- end }}
+{{- end -}}
+
+{{/* Format: terse
+{{/* --------------------------------------------------------------------- */}}
+{{- define "partials/inline/pagination/terse" }}
+ {{- with .Paginator }}
+ {{- $currentPageNumber := .PageNumber }}
+
+ {{- with .First }}
+ {{- if ne $currentPageNumber .PageNumber }}
+ <li class="page-item">
+ <a href="{{ .URL }}" aria-label="First" class="page-link" role="button"><span aria-hidden="true">&laquo;&laquo;</span></a>
+ </li>
+ {{- end }}
+ {{- end }}
+
+ {{- with .Prev }}
+ <li class="page-item">
+ <a href="{{ .URL }}" aria-label="Previous" class="page-link" role="button"><span aria-hidden="true">&laquo;</span></a>
+ </li>
+ {{- end }}
+
+ {{- $slots := 3 }}
+ {{- $start := math.Max 1 (sub .PageNumber (math.Floor (div $slots 2))) }}
+ {{- $end := math.Min .TotalPages (sub (add $start $slots) 1) }}
+ {{- if lt (add (sub $end $start) 1) $slots }}
+ {{- $start = math.Max 1 (add (sub $end $slots) 1) }}
+ {{- end }}
+
+ {{- range $k := seq $start $end }}
+ {{- if eq $.Paginator.PageNumber $k }}
+ <li class="page-item active">
+ <a href="#" aria-current="page" aria-label="Page {{ $k }}" class="page-link" role="button">{{ $k }}</a>
+ </li>
+ {{- else }}
+ <li class="page-item">
+ <a href="{{ (index $.Paginator.Pagers (sub $k 1)).URL }}" aria-label="Page {{ $k }}" class="page-link" role="button">{{ $k }}</a>
+ </li>
+ {{- end }}
+ {{- end }}
+
+ {{- with .Next }}
+ <li class="page-item">
+ <a href="{{ .URL }}" aria-label="Next" class="page-link" role="button"><span aria-hidden="true">&raquo;</span></a>
+ </li>
+ {{- end }}
+
+ {{- with .Last }}
+ {{- if ne $currentPageNumber .PageNumber }}
+ <li class="page-item">
+ <a href="{{ .URL }}" aria-label="Last" class="page-link" role="button"><span aria-hidden="true">&raquo;&raquo;</span></a>
+ </li>
+ {{- end }}
+ {{- end }}
+ {{- end }}
+{{- end -}}
`},
{`schema.html`, `<meta itemprop="name" content="{{ .Title }}">
<meta itemprop="description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}">
diff --git a/tpl/tplimpl/embedded/templates/pagination.html b/tpl/tplimpl/embedded/templates/pagination.html
index 0984b6f9e..b3535ffca 100644
--- a/tpl/tplimpl/embedded/templates/pagination.html
+++ b/tpl/tplimpl/embedded/templates/pagination.html
@@ -1,45 +1,154 @@
-{{ $pag := $.Paginator }}
-{{ if gt $pag.TotalPages 1 -}}
-<ul class="pagination">
- {{ with $pag.First -}}
- <li class="page-item">
- <a href="{{ .URL }}" class="page-link" aria-label="First"><span aria-hidden="true">&laquo;&laquo;</span></a>
- </li>
- {{ end -}}
- <li class="page-item{{ if not $pag.HasPrev }} disabled{{ end }}">
- <a {{ if $pag.HasPrev }}href="{{ $pag.Prev.URL }}"{{ end }} class="page-link" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a>
- </li>
- {{- $ellipsed := false -}}
- {{- $shouldEllipse := false -}}
- {{- range $pag.Pagers -}}
- {{- $right := sub .TotalPages .PageNumber -}}
- {{- $showNumber := or (le .PageNumber 3) (eq $right 0) -}}
- {{- $showNumber := or $showNumber (le .TotalPages 5) -}}{{/* Issue #7523 */}}
- {{- $showNumber := or $showNumber (and (gt .PageNumber (sub $pag.PageNumber 2)) (lt .PageNumber (add $pag.PageNumber 2))) -}}
- {{- if $showNumber -}}
- {{- $ellipsed = false -}}
- {{- $shouldEllipse = false -}}
- {{- else -}}
- {{- $shouldEllipse = not $ellipsed -}}
- {{- $ellipsed = true -}}
- {{- end -}}
- {{- if $showNumber }}
- <li class="page-item{{ if eq . $pag }} active{{ end }}">
- <a class="page-link" href="{{ .URL }}">{{ .PageNumber }}</a>
- </li>
- {{- else if $shouldEllipse }}
- <li class="page-item disabled">
- <span aria-hidden="true">&nbsp;&hellip;&nbsp;</span>
- </li>
- {{- end -}}
+{{- $validFormats := slice "default" "terse" }}
+
+{{- $msg1 := "When passing a map to the internal pagination template, one of the elements must be named 'page', and it must be set to the context of the current page." }}
+{{- $msg2 := "The 'format' specified in the map passed to the internal pagination template is invalid. Valid choices are: %s." }}
+
+{{- $page := . }}
+{{- $format := "default" }}
+
+{{- if reflect.IsMap . }}
+ {{- with .page }}
+ {{- $page = . }}
+ {{- else }}
+ {{- errorf $msg1 }}
{{- end }}
- <li class="page-item{{ if not $pag.HasNext }} disabled{{ end }}">
- <a {{ if $pag.HasNext }}href="{{ $pag.Next.URL }}"{{ end }} class="page-link" aria-label="Next"><span aria-hidden="true">&raquo;</span></a>
- </li>
- {{- with $pag.Last }}
- <li class="page-item">
- <a href="{{ .URL }}" class="page-link" aria-label="Last"><span aria-hidden="true">&raquo;&raquo;</span></a>
- </li>
+ {{- with .format }}
+ {{- $format = lower . }}
{{- end }}
-</ul>
-{{ end }}
+{{- end }}
+
+{{- if in $validFormats $format }}
+ {{- if gt $page.Paginator.TotalPages 1 }}
+ <ul class="pagination pagination-{{ $format }}">
+ {{- partial (printf "partials/inline/pagination/%s" $format) $page }}
+ </ul>
+ {{- end }}
+{{- else }}
+ {{- errorf $msg2 (delimit $validFormats ", ") }}
+{{- end -}}
+
+{{/* Format: default
+{{/* --------------------------------------------------------------------- */}}
+{{- define "partials/inline/pagination/default" }}
+ {{- with .Paginator }}
+ {{- $currentPageNumber := .PageNumber }}
+
+ {{- with .First }}
+ {{- if ne $currentPageNumber .PageNumber }}
+ <li class="page-item">
+ <a href="{{ .URL }}" aria-label="First" class="page-link" role="button"><span aria-hidden="true">&laquo;&laquo;</span></a>
+ </li>
+ {{- else }}
+ <li class="page-item disabled">
+ <a href="#" aria-disabled="true" aria-label="First" class="page-link" role="button"><span aria-hidden="true">&laquo;&laquo;</span></a>
+ </li>
+ {{- end }}
+ {{- end }}
+
+ {{- with .Prev }}
+ <li class="page-item">
+ <a href="{{ .URL }}" aria-label="Previous" class="page-link" role="button"><span aria-hidden="true">&laquo;</span></a>
+ </li>
+ {{- else }}
+ <li class="page-item disabled">
+ <a href="#" aria-disabled="true" aria-label="Previous" class="page-link" role="button"><span aria-hidden="true">&laquo;</span></a>
+ </li>
+ {{- end }}
+
+ {{- $slots := 5 }}
+ {{- $start := math.Max 1 (sub .PageNumber (math.Floor (div $slots 2))) }}
+ {{- $end := math.Min .TotalPages (sub (add $start $slots) 1) }}
+ {{- if lt (add (sub $end $start) 1) $slots }}
+ {{- $start = math.Max 1 (add (sub $end $slots) 1) }}
+ {{- end }}
+
+ {{- range $k := seq $start $end }}
+ {{- if eq $.Paginator.PageNumber $k }}
+ <li class="page-item active">
+ <a href="#" aria-current="page" aria-label="Page {{ $k }}" class="page-link" role="button">{{ $k }}</a>
+ </li>
+ {{- else }}
+ <li class="page-item">
+ <a href="{{ (index $.Paginator.Pagers (sub $k 1)).URL }}" aria-label="Page {{ $k }}" class="page-link" role="button">{{ $k }}</a>
+ </li>
+ {{- end }}
+ {{- end }}
+
+ {{- with .Next }}
+ <li class="page-item">
+ <a href="{{ .URL }}" aria-label="Next" class="page-link" role="button"><span aria-hidden="true">&raquo;</span></a>
+ </li>
+ {{- else }}
+ <li class="page-item disabled">
+ <a href="#" aria-disabled="true" aria-label="Next" class="page-link" role="button"><span aria-hidden="true">&raquo;</span></a>
+ </li>
+ {{- end }}
+
+ {{- with .Last }}
+ {{- if ne $currentPageNumber .PageNumber }}
+ <li class="page-item">
+ <a href="{{ .URL }}" aria-label="Last" class="page-link" role="button"><span aria-hidden="true">&raquo;&raquo;</span></a>
+ </li>
+ {{- else }}
+ <li class="page-item disabled">
+ <a href="#" aria-disabled="true" aria-label="Last" class="page-link" role="button"><span aria-hidden="true">&raquo;&raquo;</span></a>
+ </li>
+ {{- end }}
+ {{- end }}
+ {{- end }}
+{{- end -}}
+
+{{/* Format: terse
+{{/* --------------------------------------------------------------------- */}}
+{{- define "partials/inline/pagination/terse" }}
+ {{- with .Paginator }}
+ {{- $currentPageNumber := .PageNumber }}
+
+ {{- with .First }}
+ {{- if ne $currentPageNumber .PageNumber }}
+ <li class="page-item">
+ <a href="{{ .URL }}" aria-label="First" class="page-link" role="button"><span aria-hidden="true">&laquo;&laquo;</span></a>
+ </li>
+ {{- end }}
+ {{- end }}
+
+ {{- with .Prev }}
+ <li class="page-item">
+ <a href="{{ .URL }}" aria-label="Previous" class="page-link" role="button"><span aria-hidden="true">&laquo;</span></a>
+ </li>
+ {{- end }}
+
+ {{- $slots := 3 }}
+ {{- $start := math.Max 1 (sub .PageNumber (math.Floor (div $slots 2))) }}
+ {{- $end := math.Min .TotalPages (sub (add $start $slots) 1) }}
+ {{- if lt (add (sub $end $start) 1) $slots }}
+ {{- $start = math.Max 1 (add (sub $end $slots) 1) }}
+ {{- end }}
+
+ {{- range $k := seq $start $end }}
+ {{- if eq $.Paginator.PageNumber $k }}
+ <li class="page-item active">
+ <a href="#" aria-current="page" aria-label="Page {{ $k }}" class="page-link" role="button">{{ $k }}</a>
+ </li>
+ {{- else }}
+ <li class="page-item">
+ <a href="{{ (index $.Paginator.Pagers (sub $k 1)).URL }}" aria-label="Page {{ $k }}" class="page-link" role="button">{{ $k }}</a>
+ </li>
+ {{- end }}
+ {{- end }}
+
+ {{- with .Next }}
+ <li class="page-item">
+ <a href="{{ .URL }}" aria-label="Next" class="page-link" role="button"><span aria-hidden="true">&raquo;</span></a>
+ </li>
+ {{- end }}
+
+ {{- with .Last }}
+ {{- if ne $currentPageNumber .PageNumber }}
+ <li class="page-item">
+ <a href="{{ .URL }}" aria-label="Last" class="page-link" role="button"><span aria-hidden="true">&raquo;&raquo;</span></a>
+ </li>
+ {{- end }}
+ {{- end }}
+ {{- end }}
+{{- end -}}