initial setup of related content inside single articles. Needs working.
authordanix <danix@danix.xyz>
Tue, 7 Mar 2023 14:40:23 +0000 (15:40 +0100)
committerdanix <danix@danix.xyz>
Tue, 7 Mar 2023 14:40:23 +0000 (15:40 +0100)
layouts/partials/funcs/related.html [new file with mode: 0644]
layouts/post/single-baseof.html

diff --git a/layouts/partials/funcs/related.html b/layouts/partials/funcs/related.html
new file mode 100644 (file)
index 0000000..94d2fca
--- /dev/null
@@ -0,0 +1,36 @@
+{{ $related := .Site.RegularPages.Related . | first 5 }}
+{{ with $related }}
+<h3>You might also be interested in:</h3>
+<ul>
+    {{ range . }}
+    <li>
+        <a class="image" href="{{.Permalink}}">
+        {{ if isset .Params "featured_image" }}
+            <img src="{{ .Params.featured_image | absURL}}" alt="{{.Title}}" width="200">
+        {{ else }}
+            {{ $default_image := resources.Get "img/default_article.jpg" }} 
+            <img src="{{ $default_image.Permalink }}" alt="{{.Title}}" width="200">
+        {{ end }}
+            {{ .Title }}
+        </a>
+    </li>
+    {{ end }}
+</ul>
+{{ else }}
+<h3>Check out these awesome articles:</h3>
+<ul>
+    {{ range first 5 ( where site.RegularPages "Type" "in" site.Params.mainSections ) }}
+    <li>
+        <a class="image" href="{{.Permalink}}">
+        {{ if isset .Params "featured_image" }}
+            <img src="{{ .Params.featured_image | absURL}}" alt="{{.Title}}" width="200">
+        {{ else }}
+            {{ $default_image := resources.Get "img/default_article.jpg" }} 
+            <img src="{{ $default_image.Permalink }}" alt="{{.Title}}" width="200">
+        {{ end }}
+            {{ .Title }}
+        </a>
+    </li>
+    {{ end }}
+</ul>
+{{ end }}
\ No newline at end of file
index d75dd0f..c6f8bb9 100644 (file)
@@ -28,7 +28,7 @@
                                        {{- block "article-main" . }}{{- end }}
                                </section>
                                <section id="three">
-                                       <div class="inner">articoli correlati</div>
+                                       {{- partial "funcs/related.html" . -}}
                                </section>
                        </div>
                        {{- partial "footer.html" . -}}