]> danix's work - danix.xyz-2.git/commitdiff
fix: enable related articles widget on article pages
authorDanilo M. <redacted>
Sat, 18 Apr 2026 15:05:55 +0000 (17:05 +0200)
committerDanilo M. <redacted>
Sat, 18 Apr 2026 15:05:55 +0000 (17:05 +0200)
The related widget was not displaying because the condition used .Type (the article's frontmatter type field like "life", "tech") instead of .Section (the content section like "articles"). Changed condition from eq .Type "articles" to eq .Section "articles".

Also added Hugo's [related] configuration block to enable content matching by categories (weight 100) and tags (weight 80) with an 80% threshold for finding related posts.

Co-Authored-By: Claude Haiku 4.5 <redacted>
hugo.toml
themes/danix-xyz-hacker/layouts/partials/sidebar.html

index 7e63a2b5508c52c08371f462c758f7e8b27cca6d..b7e0663be9b047b950e9c91744a0976a7713cd05 100644 (file)
--- a/hugo.toml
+++ b/hugo.toml
@@ -137,6 +137,20 @@ enableRobotsTXT = true
     color_dark = "#a855f7"
     color_light = "#7c3aed"
 
+# Related content configuration
+[related]
+  threshold = 80
+  includeNewer = true
+  toLower = true
+
+  [[related.indices]]
+    name = "categories"
+    weight = 100
+
+  [[related.indices]]
+    name = "tags"
+    weight = 80
+
 [[redirects]]
   from = '/it/**'
   to = '/it/404.html'
index f80c2cf2af6108102716380e71ffbd1571c87b79..dc263e6a18cfcc878325be46b0baedfbf9186f3f 100644 (file)
@@ -13,7 +13,7 @@
   {{ partial "social-share.html" (dict "page" . "mode" "sidebar") }}
 
   <!-- Related posts widget (articles only) -->
-  {{ if and .Site.Params.relatedPosts (eq .Type "articles") }}
+  {{ if and .Site.Params.relatedPosts (eq .Section "articles") }}
   {{ $related := first 5 (.Site.RegularPages.Related .) }}
   <hr class="sidebar-hr">
   <div class="sidebar-widget">