From ada3edbff2b42de9fbe0b8497b9b3795c2d0a3a3 Mon Sep 17 00:00:00 2001
From: alexisben <alex@noesya.coop>
Date: Wed, 29 Nov 2023 12:59:55 +0100
Subject: [PATCH] handle categories in block post

---
 assets/sass/_theme/blocks/posts.sass         | 15 +++++++++++++++
 assets/sass/_theme/sections/categories.sass  | 17 +++++++++++------
 i18n/en.yml                                  |  4 ++++
 i18n/fr.yml                                  |  6 ++++++
 layouts/partials/blocks/templates/posts.html | 20 ++++++++++++++++----
 5 files changed, 52 insertions(+), 10 deletions(-)

diff --git a/assets/sass/_theme/blocks/posts.sass b/assets/sass/_theme/blocks/posts.sass
index 43c045a4..4949d3cc 100644
--- a/assets/sass/_theme/blocks/posts.sass
+++ b/assets/sass/_theme/blocks/posts.sass
@@ -206,3 +206,18 @@
             margin-right: auto
             .post
                 width: col(4, 10)
+
+// Move this part to blocks/categories when categories block is ready
+.block-posts
+    .categories--grid
+        li
+            background: $color-background-alt
+            padding: $spacing1
+            position: relative
+            a
+                @include h3
+                font-weight: bold
+                text-decoration: none
+                @include stretched-link
+            p
+                display: block
\ No newline at end of file
diff --git a/assets/sass/_theme/sections/categories.sass b/assets/sass/_theme/sections/categories.sass
index 2d3c05e6..cad38461 100644
--- a/assets/sass/_theme/sections/categories.sass
+++ b/assets/sass/_theme/sections/categories.sass
@@ -1,10 +1,15 @@
 ul.categories
-    @include list-section
-    li
-        a:first-child
-            & + p 
-                text-align: right
-                white-space: nowrap
+    &:not(.categories--grid)
+        @include list-section
+        li
+            a:first-child
+                & + p 
+                    text-align: right
+                    white-space: nowrap
+    &--grid
+        @include list-reset
+        @include grid(1)
+        @include grid(4, md)
 
 .categories__term
     main
diff --git a/i18n/en.yml b/i18n/en.yml
index 2e68d87b..c1db35e9 100644
--- a/i18n/en.yml
+++ b/i18n/en.yml
@@ -1,6 +1,10 @@
 blocks:
   call_to_action:
     title: Call to action
+  categories:
+    title: Catégories
+    items:
+      count: "{{ .Count }} articles"
   chapter:
     title: Chapter
   contact:
diff --git a/i18n/fr.yml b/i18n/fr.yml
index 5b434c91..45999977 100644
--- a/i18n/fr.yml
+++ b/i18n/fr.yml
@@ -1,6 +1,12 @@
 blocks:
   call_to_action:
     title: Appel à actions
+  categories:
+    title: Catégories
+    items:
+      count: 
+        one: "1 article"
+        other: "{{ .Count }} articles"
   chapter:
     title: Chapitre
   contact:
diff --git a/layouts/partials/blocks/templates/posts.html b/layouts/partials/blocks/templates/posts.html
index b3ea5891..81364943 100644
--- a/layouts/partials/blocks/templates/posts.html
+++ b/layouts/partials/blocks/templates/posts.html
@@ -26,10 +26,22 @@
           )}}
         {{- end }}
 
-        {{ partial (printf "blocks/templates/posts/%s.html" $layout) (dict
-          "posts" .posts
-          "heading_level" $block.ranks.children
-        )}}
+        {{ if eq .mode "categories" }}
+          <ul class="categories categories--grid">
+            {{ range site.Taxonomies.categories }}
+              <li data-title="{{ .Page.Title }}">
+                {{ partial "categories/category.html" .Page }}
+                <p>{{ i18n "blocks.categories.items.count" (dict "Count" (len .)) }}</p>
+              </li>
+            {{ end }}
+          </ul>
+        {{ else if .posts }}
+          {{ partial (printf "blocks/templates/posts/%s.html" $layout) (dict
+            "posts" .posts
+            "heading_level" $block.ranks.children
+          )}}
+        {{ end }}
+
       </div>
     </div>
   </div>
-- 
GitLab