diff --git a/hugolib/embedded_templates_test.go b/hugolib/embedded_templates_test.go
index c62d59b1d..5d7d6dc23 100644
--- a/hugolib/embedded_templates_test.go
+++ b/hugolib/embedded_templates_test.go
@@ -116,3 +116,42 @@ Disqus:
// Disqus
b.AssertFileContent("public/index.html", "\"disqus_shortname\" + '.disqus.com/embed.js';")
}
+
+func TestEmbeddedPaginationTemplate(t *testing.T) {
+ t.Parallel()
+
+ test := func(variant string, expectedOutput string) {
+ b := newTestSitesBuilder(t)
+ b.WithConfigFile("toml", `paginate = 1`)
+ b.WithContent(
+ "s1/p01.md", "---\ntitle: p01\n---",
+ "s1/p02.md", "---\ntitle: p02\n---",
+ "s1/p03.md", "---\ntitle: p03\n---",
+ "s1/p04.md", "---\ntitle: p04\n---",
+ "s1/p05.md", "---\ntitle: p05\n---",
+ "s1/p06.md", "---\ntitle: p06\n---",
+ "s1/p07.md", "---\ntitle: p07\n---",
+ "s1/p08.md", "---\ntitle: p08\n---",
+ "s1/p09.md", "---\ntitle: p09\n---",
+ "s1/p10.md", "---\ntitle: p10\n---",
+ )
+ b.WithTemplates("index.html", `{{ .Paginate (where site.RegularPages "Section" "s1") }}`+variant)
+ b.Build(BuildCfg{})
+ b.AssertFileContent("public/index.html", expectedOutput)
+ }
+
+ expectedOutputDefaultFormat := "Pager 1\n
"
+ expectedOutputTerseFormat := "Pager 1\n "
+
+ variant := `{{ template "_internal/pagination.html" . }}`
+ test(variant, expectedOutputDefaultFormat)
+
+ variant = `{{ template "_internal/pagination.html" (dict "page" .) }}`
+ test(variant, expectedOutputDefaultFormat)
+
+ variant = `{{ template "_internal/pagination.html" (dict "page" . "format" "default") }}`
+ test(variant, expectedOutputDefaultFormat)
+
+ variant = `{{ template "_internal/pagination.html" (dict "page" . "format" "terse") }}`
+ test(variant, expectedOutputTerseFormat)
+}
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 }}{{ end }}
`},
- {`pagination.html`, `{{ $pag := $.Paginator }}
-{{ if gt $pag.TotalPages 1 -}}
-
-{{ end }}
+{{- end }}
+
+{{- if in $validFormats $format }}
+ {{- if gt $page.Paginator.TotalPages 1 }}
+
+ {{- end }}
+{{- else }}
+ {{- errorf $msg2 (delimit $validFormats ", ") }}
+{{- end -}}
+
+{{/* Format: default
+{{/* --------------------------------------------------------------------- */}}
+{{- define "partials/inline/pagination/default" }}
+ {{- with .Paginator }}
+ {{- $currentPageNumber := .PageNumber }}
+
+ {{- with .First }}
+ {{- if ne $currentPageNumber .PageNumber }}
+
+ ««
+
+ {{- else }}
+
+ ««
+
+ {{- end }}
+ {{- end }}
+
+ {{- with .Prev }}
+
+ «
+
+ {{- else }}
+
+ «
+
+ {{- 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 }}
+
+ {{ $k }}
+
+ {{- else }}
+
+ {{ $k }}
+
+ {{- end }}
+ {{- end }}
+
+ {{- with .Next }}
+
+ »
+
+ {{- else }}
+
+ »
+
+ {{- end }}
+
+ {{- with .Last }}
+ {{- if ne $currentPageNumber .PageNumber }}
+
+ »»
+
+ {{- else }}
+
+ »»
+
+ {{- end }}
+ {{- end }}
+ {{- end }}
+{{- end -}}
+
+{{/* Format: terse
+{{/* --------------------------------------------------------------------- */}}
+{{- define "partials/inline/pagination/terse" }}
+ {{- with .Paginator }}
+ {{- $currentPageNumber := .PageNumber }}
+
+ {{- with .First }}
+ {{- if ne $currentPageNumber .PageNumber }}
+
+ ««
+
+ {{- end }}
+ {{- end }}
+
+ {{- with .Prev }}
+
+ «
+
+ {{- 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 }}
+
+ {{ $k }}
+
+ {{- else }}
+
+ {{ $k }}
+
+ {{- end }}
+ {{- end }}
+
+ {{- with .Next }}
+
+ »
+
+ {{- end }}
+
+ {{- with .Last }}
+ {{- if ne $currentPageNumber .PageNumber }}
+
+ »»
+
+ {{- end }}
+ {{- end }}
+ {{- end }}
+{{- end -}}
`},
{`schema.html`, `
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 -}}
-
-{{ end }}
+{{- end }}
+
+{{- if in $validFormats $format }}
+ {{- if gt $page.Paginator.TotalPages 1 }}
+
+ {{- end }}
+{{- else }}
+ {{- errorf $msg2 (delimit $validFormats ", ") }}
+{{- end -}}
+
+{{/* Format: default
+{{/* --------------------------------------------------------------------- */}}
+{{- define "partials/inline/pagination/default" }}
+ {{- with .Paginator }}
+ {{- $currentPageNumber := .PageNumber }}
+
+ {{- with .First }}
+ {{- if ne $currentPageNumber .PageNumber }}
+
+ ««
+
+ {{- else }}
+
+ ««
+
+ {{- end }}
+ {{- end }}
+
+ {{- with .Prev }}
+
+ «
+
+ {{- else }}
+
+ «
+
+ {{- 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 }}
+
+ {{ $k }}
+
+ {{- else }}
+
+ {{ $k }}
+
+ {{- end }}
+ {{- end }}
+
+ {{- with .Next }}
+
+ »
+
+ {{- else }}
+
+ »
+
+ {{- end }}
+
+ {{- with .Last }}
+ {{- if ne $currentPageNumber .PageNumber }}
+
+ »»
+
+ {{- else }}
+
+ »»
+
+ {{- end }}
+ {{- end }}
+ {{- end }}
+{{- end -}}
+
+{{/* Format: terse
+{{/* --------------------------------------------------------------------- */}}
+{{- define "partials/inline/pagination/terse" }}
+ {{- with .Paginator }}
+ {{- $currentPageNumber := .PageNumber }}
+
+ {{- with .First }}
+ {{- if ne $currentPageNumber .PageNumber }}
+
+ ««
+
+ {{- end }}
+ {{- end }}
+
+ {{- with .Prev }}
+
+ «
+
+ {{- 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 }}
+
+ {{ $k }}
+
+ {{- else }}
+
+ {{ $k }}
+
+ {{- end }}
+ {{- end }}
+
+ {{- with .Next }}
+
+ »
+
+ {{- end }}
+
+ {{- with .Last }}
+ {{- if ne $currentPageNumber .PageNumber }}
+
+ »»
+
+ {{- end }}
+ {{- end }}
+ {{- end }}
+{{- end -}}