From e9536ae101080c3ef20677659cab62cfa8dc56d5 Mon Sep 17 00:00:00 2001
From: alexisben <alex@noesya.coop>
Date: Mon, 26 Dec 2022 16:39:34 +0100
Subject: [PATCH] refacto toc conditions

---
 layouts/pages/list.html               | 46 ++++----------------------
 layouts/partials/GetBodyclass         |  2 +-
 layouts/partials/IsTocNeeded          | 14 +-------
 layouts/partials/programs/single.html | 11 ++++---
 layouts/partials/toc/default.html     | 47 ++++-----------------------
 layouts/posts/single.html             | 12 +++----
 6 files changed, 28 insertions(+), 104 deletions(-)

diff --git a/layouts/pages/list.html b/layouts/pages/list.html
index 3a0bf4f3..3e9183bf 100644
--- a/layouts/pages/list.html
+++ b/layouts/pages/list.html
@@ -2,46 +2,14 @@
   {{ partial "pages/hero.html" . }}
 
   <div class="document-content">
-
-    {{/*  TOC PART  */}}
     {{- $category := site.GetPage (printf "/categories%s" .Params.category) -}}
-    {{- $show_aside := false -}}
-
-    {{- $has_blocks := false -}}
-    {{- range .Params.blocks -}}
-      {{- $has_blocks = true -}}
-      {{- if .title -}}
-        {{- $show_aside = true -}}
-      {{- end -}}
-    {{- end -}}
-    
-    {{- if .Pages -}}
-      {{- if eq $has_blocks false -}}
-        {{- $show_aside = true -}}
-      {{- end -}}
-    {{- end -}}
-    
-    {{- if .Content -}}
-      {{- if eq $has_blocks false -}}
-        {{- $show_aside = true -}}
-      {{- end -}}
-    {{- end -}}
-    
-    {{- if $category -}}
-      {{- if eq $has_blocks false -}}
-        {{- $show_aside = true -}}
-      {{- end -}}
-    {{- end -}}
-    
-    {{- if $show_aside }}
-      {{ partial "toc/container.html"
-          (dict
-              "category" $category
-              "toc" "pages/toc.html"
-              "context" .
-          )
-      }}
-    {{ end }}
+    {{ partial "toc/container.html"
+        (dict
+            "category" $category
+            "toc" "pages/toc.html"
+            "context" .
+        )
+    }}
 
     {{ partial "hooks/after-page-hero.html" . }}
 
diff --git a/layouts/partials/GetBodyclass b/layouts/partials/GetBodyclass
index 96ab6faf..5349630b 100644
--- a/layouts/partials/GetBodyclass
+++ b/layouts/partials/GetBodyclass
@@ -8,7 +8,7 @@
   {{- $bodyclass = printf "full-width %s" $bodyclass -}}
 {{- end -}}
 
-{{- if .Params.layout.offcanvas  -}}
+{{- if .Params.layout.toc.offcanvas  -}}
   {{- $bodyclass = printf "offcanvas-toc %s" $bodyclass -}}
 {{- end -}}
 
diff --git a/layouts/partials/IsTocNeeded b/layouts/partials/IsTocNeeded
index c0ec4cc7..01901125 100644
--- a/layouts/partials/IsTocNeeded
+++ b/layouts/partials/IsTocNeeded
@@ -1,13 +1 @@
-{{ $isNeeded := false }}
-
-{{ if eq .context.Type "programs" }}
-  {{ $isNeeded = true }}
-{{ end }}
-
-{{ if .context.Params.blocks }}
-  {{ if gt (len .context.Params.blocks) 1 }}
-    {{ $isNeeded = true }}
-  {{ end }}
-{{ end }}
-
-{{ return $isNeeded }}
\ No newline at end of file
+{{ return .context.Params.layout.toc.present }}
\ No newline at end of file
diff --git a/layouts/partials/programs/single.html b/layouts/partials/programs/single.html
index 5248c782..44e430b0 100644
--- a/layouts/partials/programs/single.html
+++ b/layouts/partials/programs/single.html
@@ -1,12 +1,15 @@
 <div class="document-content" itemscope itemtype="https://schema.org/EducationalOccupationalCredential">
+
+  <meta itemprop="name" content="{{ partial "PrepareHTML" .Title }}">
+  <meta itemprop="url" content="{{ .Permalink }}">
+
   {{ partial "toc/container.html"
-      (dict
+    (dict
           "toc" "programs/toc.html"
           "context" .
       )
-  }}
-  <meta itemprop="name" content="{{ partial "PrepareHTML" .Title }}">
-  <meta itemprop="url" content="{{ .Permalink }}">
+    }}
+
   {{- if .Params.image -}}
     {{- $id := .Params.image -}}
     {{- if isset .Params.image "id" -}}
diff --git a/layouts/partials/toc/default.html b/layouts/partials/toc/default.html
index ae57cd0f..2f071f86 100644
--- a/layouts/partials/toc/default.html
+++ b/layouts/partials/toc/default.html
@@ -1,40 +1,7 @@
-{{- $show_aside := false -}}
-
-{{- $has_blocks := false -}}
-{{- range .context.Params.blocks -}}
-  {{- $has_blocks = true -}}
-  {{- if .title -}}
-    {{- $show_aside = true -}}
-  {{- end -}}
-{{- end -}}
-
-{{- if .context.Pages -}}
-  {{- if eq $has_blocks false -}}
-    {{- $show_aside = true -}}
-  {{- end -}}
-{{- end -}}
-
-{{- if .context.Content -}}
-  {{- if eq $has_blocks false -}}
-    {{- $show_aside = true -}}
-  {{- end -}}
-{{- end -}}
-
-{{- if .category -}}
-  {{- if eq $has_blocks false -}}
-    {{- $show_aside = true -}}
-  {{- end -}}
-{{- end -}}
-
-{{- if $show_aside }}
-  <nav class="toc toc-pages" id="nav-toc" aria-labelledby="toc-title">
-    <ol>
-      {{- if .context.Params.blocks -}}
-        {{- partial "blocks/toc.html" .context.Params.blocks -}}
-      {{- end -}}
-    </ol>
-  </nav>
-
-{{ end -}}
-
-
+<nav class="toc toc-pages" id="nav-toc" aria-labelledby="toc-title">
+  <ol>
+    {{- if .context.Params.blocks -}}
+      {{- partial "blocks/toc.html" .context.Params.blocks -}}
+    {{- end -}}
+  </ol>
+</nav>
diff --git a/layouts/posts/single.html b/layouts/posts/single.html
index 562c3c3a..9a7f3026 100644
--- a/layouts/posts/single.html
+++ b/layouts/posts/single.html
@@ -2,6 +2,11 @@
   {{ partial "posts/hero-single.html" . }}
 
   <div class="document-content" itemscope itemtype="https://schema.org/NewsArticle">
+    <meta itemprop="headline" content="{{ partial "PrepareHTML" .Title }}">
+    <meta itemprop="url" content="{{ .Permalink }}">
+    {{ if .Date }}<meta itemprop="datePublished" content="{{ .Date.Format "2006-01-02T15:04" }}">{{ end }}
+    {{ if .Params.description_short }}<meta itemprop="abstract" content="{{ partial "PrepareHTML" .Params.description_short }}">{{ end }}
+    {{ if .Summary }}<meta itemprop="description" content="{{ partial "PrepareHTML" .Summary }}">{{ end }}
 
     {{ partial "toc/container.html"
         (dict
@@ -10,15 +15,8 @@
         )
     }}
 
-    <meta itemprop="headline" content="{{ partial "PrepareHTML" .Title }}">
-    <meta itemprop="url" content="{{ .Permalink }}">
-    {{ if .Date }}<meta itemprop="datePublished" content="{{ .Date.Format "2006-01-02T15:04" }}">{{ end }}
-    {{ if .Params.description_short }}<meta itemprop="abstract" content="{{ partial "PrepareHTML" .Params.description_short }}">{{ end }}
-    {{ if .Summary }}<meta itemprop="description" content="{{ partial "PrepareHTML" .Summary }}">{{ end }}
-
     {{ partial "posts/aside.html" . }}
 
-
     {{ partial "posts/chapo.html" (dict
         "context" .
         "block_wrapped" true
-- 
GitLab