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 -}}
|
||||
{{- $pages := .Pages | complement $subsections -}}
|
||||
{{- $pages = where $pages "Params.hidden" "!=" true -}}
|
||||
|
||||
{{- if eq (len $pages) 0 -}}
|
||||
{{/* If there are no normal pages, display subsections in list style, with pagination */}}
|
||||
@@ -68,12 +69,14 @@
|
||||
{{- end -}}
|
||||
|
||||
{{/* List only pages that are not a subsection */}}
|
||||
{{ $paginator := .Paginate $pages }}
|
||||
{{ $paginator := partial "helper/paginator.html" . }}
|
||||
{{ with $paginator }}
|
||||
<section class="article-list--compact">
|
||||
{{ range $paginator.Pages }}
|
||||
{{ range .Pages }}
|
||||
{{ partial "article-list/compact" . }}
|
||||
{{ end }}
|
||||
</section>
|
||||
{{ end }}
|
||||
|
||||
{{- partial "pagination.html" . -}}
|
||||
|
||||
|
||||
+2
-4
@@ -1,10 +1,8 @@
|
||||
{{ define "main" }}
|
||||
{{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }}
|
||||
{{ $filtered := where $pages "Params.hidden" "!=" true }}
|
||||
{{ $pag := .Paginate ($filtered) }}
|
||||
{{- $paginator := partial "helper/paginator.html" . -}}
|
||||
|
||||
<section class="article-list">
|
||||
{{ range $index, $element := $pag.Pages }}
|
||||
{{ range $index, $element := $paginator.Pages }}
|
||||
{{ partial "article-list/default" . }}
|
||||
{{ end }}
|
||||
</section>
|
||||
|
||||
@@ -1,37 +1,20 @@
|
||||
{{- $title := .Title -}}
|
||||
{{- $pageTitle := .Title -}}
|
||||
{{- $siteTitle := .Site.Title -}}
|
||||
{{- $paginator := partial "helper/paginator.html" . -}}
|
||||
|
||||
{{- if .IsHome -}}
|
||||
<!-- Homepage, and it's pagination -->
|
||||
{{- $title := slice -}}
|
||||
|
||||
<!-- Build paginator -->
|
||||
{{ $pages := where .Site.RegularPages "Section" "in" .Site.Params.mainSections }}
|
||||
{{ $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 "" }}
|
||||
{{- if $pageTitle }}
|
||||
{{- $title = slice $pageTitle -}}
|
||||
{{- 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