From 5264e7eed3193364b1c05e52358fe662261c7cac Mon Sep 17 00:00:00 2001 From: Kerby Martino Date: Tue, 29 Apr 2025 16:06:10 +0800 Subject: [PATCH] Support for 6 levels of nested comment --- _includes/comment.liquid | 57 ++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/_includes/comment.liquid b/_includes/comment.liquid index fb52757..560b9f4 100644 --- a/_includes/comment.liquid +++ b/_includes/comment.liquid @@ -1,5 +1,5 @@ {% comment %} - Flat iterative version - no recursion, just nested loops up to N levels + Supports up to 6 levels of nested comments (non-recursive) {% endcomment %} {% assign top_comments = site.comments | where: "parent", nil | sort: "date" %} @@ -7,24 +7,24 @@ {% for comment in top_comments %}
- ▲ - @{{ comment.author }} - {{ comment.date | date: "%b %d, %Y" }} + ▲ + @{{ comment.author }} + {{ comment.date | date: "%b %d, %Y" }}

{{ comment.content }}

reply - {% assign replies = site.comments | where: "parent", comment.slug | sort: "date" %} - {% for reply in replies %} + {% assign replies1 = site.comments | where: "parent", comment.slug | sort: "date" %} + {% for reply1 in replies1 %}
- @{{ reply.author }} – - {{ reply.date | date: "%b %d, %Y" }} + @{{ reply1.author }} – + {{ reply1.date | date: "%b %d, %Y" }}
-

{{ reply.content }}

+

{{ reply1.content }}

reply - {% assign replies2 = site.comments | where: "parent", reply.slug | sort: "date" %} + {% assign replies2 = site.comments | where: "parent", reply1.slug | sort: "date" %} {% for reply2 in replies2 %}
@@ -33,7 +33,42 @@

{{ reply2.content }}

reply - {# Extend further levels here if needed #} + + {% assign replies3 = site.comments | where: "parent", reply2.slug | sort: "date" %} + {% for reply3 in replies3 %} +
+
+ @{{ reply3.author }} – + {{ reply3.date | date: "%b %d, %Y" }} +
+

{{ reply3.content }}

+ reply + + {% assign replies4 = site.comments | where: "parent", reply3.slug | sort: "date" %} + {% for reply4 in replies4 %} +
+
+ @{{ reply4.author }} – + {{ reply4.date | date: "%b %d, %Y" }} +
+

{{ reply4.content }}

+ reply + + {% assign replies5 = site.comments | where: "parent", reply4.slug | sort: "date" %} + {% for reply5 in replies5 %} +
+
+ @{{ reply5.author }} – + {{ reply5.date | date: "%b %d, %Y" }} +
+

{{ reply5.content }}

+ reply +
+ {% endfor %} +
+ {% endfor %} +
+ {% endfor %}
{% endfor %}