From a617ad961ca71e0530d200ec8ddbaced7181e778 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 15 Sep 2017 08:44:12 +0100 Subject: [PATCH] Customize ordering on list pages --- content/posts/_index.md | 2 ++ layouts/_default/list.html | 3 ++- layouts/posts/list.html | 20 -------------------- 3 files changed, 4 insertions(+), 21 deletions(-) delete mode 100644 layouts/posts/list.html diff --git a/content/posts/_index.md b/content/posts/_index.md index 592491f..9887656 100644 --- a/content/posts/_index.md +++ b/content/posts/_index.md @@ -2,4 +2,6 @@ title: Blog linktitle: Posts show_images: true +sort_by: Date +sort_order: desc --- diff --git a/layouts/_default/list.html b/layouts/_default/list.html index b019fe6..e05cb3b 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -4,7 +4,8 @@ {{ if ne .Params.hide_pages "true" }}
{{ $parent := . }} - {{ $valid_pages := where .Site.Pages.ByTitle ".Parent" "!=" nil }} + {{ $sorted_pages := sort .Site.Pages (default "Title" .Params.sort_by) (default "asc" .Params.sort_order)}} + {{ $valid_pages := where $sorted_pages ".Parent" "!=" nil }} {{ $valid_pages := where $valid_pages ".Params.hide_in_list" "!=" "true" }} {{ range where $valid_pages ".Parent.UniqueID" $parent.UniqueID }} {{ if $parent.Params.show_images }} diff --git a/layouts/posts/list.html b/layouts/posts/list.html deleted file mode 100644 index c1b932f..0000000 --- a/layouts/posts/list.html +++ /dev/null @@ -1,20 +0,0 @@ -{{ partial "page_start.html" . }} -
- {{ partial "content.html" . }} - {{ if ne .Params.hide_pages "true" }} -
- {{ $parent := . }} - {{ $valid_pages := sort .Site.Pages "Date" "desc" }} - {{ $valid_pages := where $valid_pages ".Parent" "!=" nil }} - {{ $valid_pages := where $valid_pages ".Params.hide_in_list" "!=" "true" }} - {{ range where $valid_pages ".Parent.UniqueID" $parent.UniqueID }} - {{ if $parent.Params.show_images }} - {{ partial "box_image.html" . }} - {{ else }} - {{ partial "box.html" . }} - {{ end }} - {{ end }} -
- {{ end }} -
-{{ partial "page_end.html" . }}