From 70cc14fcbe9e229fef7dc2c6a861f1bd6d3c647e Mon Sep 17 00:00:00 2001 From: Jimmy Cai Date: Thu, 7 Jan 2021 11:28:16 +0100 Subject: [PATCH] feat(list): display subsections in list style when there are no normal pages (#121) closes https://github.com/CaiJimmy/hugo-theme-stack/issues/116 --- layouts/_default/list.html | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/layouts/_default/list.html b/layouts/_default/list.html index b4efb67..90e5b66 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -42,8 +42,17 @@ {{ end }} - {{ $subsections := .Sections }} - {{ with $subsections }} + {{- $subsections := .Sections -}} + {{- $pages := .Pages | complement $subsections -}} + + {{- if eq (len $pages) 0 -}} + {{/* If there are no normal pages, display subsections in list style, with pagination */}} + {{/* This happens with taxonomies like categories or tags */}} + {{- $pages = $subsections -}} + {{- $subsections = slice -}} + {{- end -}} + + {{- with $subsections -}}

{{ T "list.subsection" (len $subsections) }}

@@ -52,10 +61,10 @@ {{ end }}
- {{ end }} + {{- end -}} {{/* List only pages that are not a subsection */}} - {{ $paginator := .Paginate (.Pages | complement $subsections) }} + {{ $paginator := .Paginate $pages }}
{{ range $paginator.Pages }} {{ partial "article-list/compact" . }}