From 25a1399fbe3a5a9ea8b881adbacf83a4cad203ae Mon Sep 17 00:00:00 2001
From: alexisben <alex@noesya.coop>
Date: Fri, 8 Mar 2024 10:43:48 +0100
Subject: [PATCH] add config for pages layout

---
 config.yaml                                       |  1 +
 layouts/partials/blocks/templates/pages/list.html | 10 +++++++++-
 layouts/partials/pages/children.html              |  7 ++++---
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/config.yaml b/config.yaml
index a5dc410c..5e5ad708 100644
--- a/config.yaml
+++ b/config.yaml
@@ -55,6 +55,7 @@ params:
     default_image: false
     index:
       truncate_description: 200 # Set to 0 to disable truncate
+      layout: grid # grid | list
   papers:
     default_image: false
     sidebar:
diff --git a/layouts/partials/blocks/templates/pages/list.html b/layouts/partials/blocks/templates/pages/list.html
index 0314906c..11b375e3 100644
--- a/layouts/partials/blocks/templates/pages/list.html
+++ b/layouts/partials/blocks/templates/pages/list.html
@@ -7,7 +7,15 @@
 )}}
 <ul class="list {{ if and (not $show_descriptions) (not $show_images) }} title-only {{ end }}">
   {{ range .pages }}
-    {{ $page := site.GetPage .file }}
+    {{- $file := false -}}
+    {{/*  Check if . is a map or page url, necessary when pages/grid is called outside block context */}}
+    {{ if reflect.IsMap . }}
+      {{ $file = .file }}
+    {{ else }}
+      {{ $file = . }}
+    {{ end }}
+
+    {{ $page := site.GetPage $file }}
     {{ with $page }}
       <li>
         {{ if or $show_descriptions $show_images }}
diff --git a/layouts/partials/pages/children.html b/layouts/partials/pages/children.html
index fb6dd823..84c53adf 100644
--- a/layouts/partials/pages/children.html
+++ b/layouts/partials/pages/children.html
@@ -2,13 +2,14 @@
 {{ if .Params.bodyclass }}
   {{- $page_class = printf "block-page-%s" .Params.bodyclass }}
 {{ end }}
+{{ $show_images := eq site.Params.pages.index.layout "grid" }}
 
-<div class="block block-pages block-pages--grid {{ $page_class }}">
+<div class="block block-pages block-pages--children block-pages--{{ site.Params.pages.index.layout }} {{ $page_class }}">
   <div class="container">
     <div class="block-content">
-      {{- partial "blocks/templates/pages/grid.html" (dict 
+      {{- partial (printf "blocks/templates/pages/%s.html" site.Params.pages.index.layout) (dict 
           "pages" .Params.children
-          "show_images" true
+          "show_images" $show_images
           "heading_level" 2
           "show_descriptions" true
           ) }}
-- 
GitLab