Support for 6 levels of nested comment

This commit is contained in:
Kerby Martino committed 2025-04-29 16:06:10 +08:00
1 parent c8540a111d
commit 5264e7eed3
1 file changed
+46 -11
+46 -11
View File
@@ -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 %}
<div class="px-0 text-sm border-l-2 border-gray-300 pl-2 mb-4">
<div class="mb-1">
<a href="#" class="text-text-muted no-underline text-sm leading-none inline-block pt-0.5 hover:text-link-hover">▲</a>
<small class="text-text-muted ml-2 text-sm">@{{ comment.author }}</small>
<small class="text-text-muted ml-2 text-sm">{{ comment.date | date: "%b %d, %Y" }}</small>
<a href="#" class="text-text-muted no-underline text-sm hover:text-link-hover">▲</a>
<small class="text-text-muted ml-2">@{{ comment.author }}</small>
<small class="text-text-muted ml-2">{{ comment.date | date: "%b %d, %Y" }}</small>
</div>
<p>{{ comment.content }}</p>
<small class="text-right underline text-xs cursor-pointer mt-1 inline-block">reply</small>
{% 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 %}
<div class="ml-4 mt-3 border-l-2 border-gray-200 pl-2">
<div class="mb-1">
<small class="text-text-muted">@{{ reply.author }}</small> –
<small class="text-text-muted">{{ reply.date | date: "%b %d, %Y" }}</small>
<small class="text-text-muted">@{{ reply1.author }}</small> –
<small class="text-text-muted">{{ reply1.date | date: "%b %d, %Y" }}</small>
</div>
<p>{{ reply.content }}</p>
<p>{{ reply1.content }}</p>
<small class="text-right underline text-xs cursor-pointer mt-1 inline-block">reply</small>
{% assign replies2 = site.comments | where: "parent", reply.slug | sort: "date" %}
{% assign replies2 = site.comments | where: "parent", reply1.slug | sort: "date" %}
{% for reply2 in replies2 %}
<div class="ml-4 mt-3 border-l-2 border-gray-200 pl-2">
<div class="mb-1">
@@ -33,7 +33,42 @@
</div>
<p>{{ reply2.content }}</p>
<small class="text-right underline text-xs cursor-pointer mt-1 inline-block">reply</small>
{# Extend further levels here if needed #}
{% assign replies3 = site.comments | where: "parent", reply2.slug | sort: "date" %}
{% for reply3 in replies3 %}
<div class="ml-4 mt-3 border-l-2 border-gray-200 pl-2">
<div class="mb-1">
<small class="text-text-muted">@{{ reply3.author }}</small> –
<small class="text-text-muted">{{ reply3.date | date: "%b %d, %Y" }}</small>
</div>
<p>{{ reply3.content }}</p>
<small class="text-right underline text-xs cursor-pointer mt-1 inline-block">reply</small>
{% assign replies4 = site.comments | where: "parent", reply3.slug | sort: "date" %}
{% for reply4 in replies4 %}
<div class="ml-4 mt-3 border-l-2 border-gray-200 pl-2">
<div class="mb-1">
<small class="text-text-muted">@{{ reply4.author }}</small> –
<small class="text-text-muted">{{ reply4.date | date: "%b %d, %Y" }}</small>
</div>
<p>{{ reply4.content }}</p>
<small class="text-right underline text-xs cursor-pointer mt-1 inline-block">reply</small>
{% assign replies5 = site.comments | where: "parent", reply4.slug | sort: "date" %}
{% for reply5 in replies5 %}
<div class="ml-4 mt-3 border-l-2 border-gray-200 pl-2">
<div class="mb-1">
<small class="text-text-muted">@{{ reply5.author }}</small> –
<small class="text-text-muted">{{ reply5.date | date: "%b %d, %Y" }}</small>
</div>
<p>{{ reply5.content }}</p>
<small class="text-right underline text-xs cursor-pointer mt-1 inline-block">reply</small>
</div>
{% endfor %}
</div>
{% endfor %}
</div>
{% endfor %}
</div>
{% endfor %}
</div>