refactor: centralize pagination logic (#1227)
* refactor: centralize pagination logic into a new helper partial used for page titles and index display * fix: list.html does not exclude hidden pages * refactor: Simplify title generation logic
This commit is contained in:
@@ -46,6 +46,7 @@
|
|||||||
|
|
||||||
{{- $subsections := .Sections -}}
|
{{- $subsections := .Sections -}}
|
||||||
{{- $pages := .Pages | complement $subsections -}}
|
{{- $pages := .Pages | complement $subsections -}}
|
||||||
|
{{- $pages = where $pages "Params.hidden" "!=" true -}}
|
||||||
|
|
||||||
{{- if eq (len $pages) 0 -}}
|
{{- if eq (len $pages) 0 -}}
|
||||||
{{/* If there are no normal pages, display subsections in list style, with pagination */}}
|
{{/* If there are no normal pages, display subsections in list style, with pagination */}}
|
||||||
@@ -68,12 +69,14 @@
|
|||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{/* List only pages that are not a subsection */}}
|
{{/* List only pages that are not a subsection */}}
|
||||||
{{ $paginator := .Paginate $pages }}
|
{{ $paginator := partial "helper/paginator.html" . }}
|
||||||
<section class="article-list--compact">
|
{{ with $paginator }}
|
||||||
{{ range $paginator.Pages }}
|
<section class="article-list--compact">
|
||||||
{{ partial "article-list/compact" . }}
|
{{ range .Pages }}
|
||||||
{{ end }}
|
{{ partial "article-list/compact" . }}
|
||||||
</section>
|
{{ end }}
|
||||||
|
</section>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
{{- partial "pagination.html" . -}}
|
{{- partial "pagination.html" . -}}
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -1,10 +1,8 @@
|
|||||||
{{ define "main" }}
|
{{ define "main" }}
|
||||||
{{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }}
|
{{- $paginator := partial "helper/paginator.html" . -}}
|
||||||
{{ $filtered := where $pages "Params.hidden" "!=" true }}
|
|
||||||
{{ $pag := .Paginate ($filtered) }}
|
|
||||||
|
|
||||||
<section class="article-list">
|
<section class="article-list">
|
||||||
{{ range $index, $element := $pag.Pages }}
|
{{ range $index, $element := $paginator.Pages }}
|
||||||
{{ partial "article-list/default" . }}
|
{{ partial "article-list/default" . }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -1,37 +1,20 @@
|
|||||||
{{- $title := .Title -}}
|
{{- $pageTitle := .Title -}}
|
||||||
{{- $siteTitle := .Site.Title -}}
|
{{- $siteTitle := .Site.Title -}}
|
||||||
|
{{- $paginator := partial "helper/paginator.html" . -}}
|
||||||
|
|
||||||
{{- if .IsHome -}}
|
{{- $title := slice -}}
|
||||||
<!-- Homepage, and it's pagination -->
|
|
||||||
|
|
||||||
<!-- Build paginator -->
|
{{- if $pageTitle }}
|
||||||
{{ $pages := where .Site.RegularPages "Section" "in" .Site.Params.mainSections }}
|
{{- $title = slice $pageTitle -}}
|
||||||
{{ $filtered := where $pages "Params.hidden" "!=" true }}
|
|
||||||
{{ $pag := .Paginate ($filtered) }}
|
|
||||||
|
|
||||||
{{ if .Paginator.HasPrev }}
|
|
||||||
<!-- Paginated. Append page number to title -->
|
|
||||||
{{ $title = printf "%s - %s" .Paginator $siteTitle }}
|
|
||||||
{{ else }}
|
|
||||||
{{ $title = $siteTitle}}
|
|
||||||
{{ end }}
|
|
||||||
{{- else if eq .Kind "term" -}}
|
|
||||||
<!-- Taxonomy page -->
|
|
||||||
|
|
||||||
<!-- Build paginator -->
|
|
||||||
{{ $notHidden := where .Pages "Params.hidden" "!=" true }}
|
|
||||||
{{ $pag := .Paginate ($notHidden) }}
|
|
||||||
|
|
||||||
<!-- {TAXONOMY_TYPE}: {TAXONOMY_TERM} -->
|
|
||||||
{{ $title = slice (title .Data.Singular) ": " $title }}
|
|
||||||
|
|
||||||
{{ if .Paginator.HasPrev }}
|
|
||||||
<!-- Add page number-->
|
|
||||||
{{ $title = $title | append " - " .Paginator }}
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
{{ $title = $title | append " - " $siteTitle }}
|
|
||||||
{{ $title = delimit $title "" }}
|
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{ return $title }}
|
{{- if and $paginator $paginator.HasPrev -}}
|
||||||
|
<!-- Add page number-->
|
||||||
|
{{ $title = $title | append (printf "Page %d" $paginator.PageNumber) }}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- if not .IsPage -}}
|
||||||
|
{{ $title = $title | append $siteTitle }}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{ return delimit $title " - " }}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
{{- $pages := "" -}}
|
||||||
|
|
||||||
|
{{- if .IsHome -}}
|
||||||
|
{{ $pages = where .Site.RegularPages "Section" "in" .Site.Params.mainSections }}
|
||||||
|
{{ $pages = where $pages "Params.hidden" "!=" true }}
|
||||||
|
{{- else if eq .Kind "term" -}}
|
||||||
|
{{ $pages = where .Pages "Params.hidden" "!=" true }}
|
||||||
|
{{- else if or (eq .Kind "section") (eq .Kind "taxonomy") -}}
|
||||||
|
{{ $subsections := .Sections }}
|
||||||
|
{{ $pages = .Pages | complement $subsections }}
|
||||||
|
{{ $pages = where $pages "Params.hidden" "!=" true }}
|
||||||
|
|
||||||
|
{{- if eq (len $pages) 0 -}}
|
||||||
|
{{/* See complete logic in list.html */}}
|
||||||
|
{{- $pages = $subsections -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- if $pages -}}
|
||||||
|
{{ $pages = .Paginate $pages }}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{ return $pages }}
|
||||||
Reference in New Issue
Block a user