refactor: update comment replies logic to use slug instead of filename

This commit is contained in:
Kerby Martino authored and Kerby Martino (aider) committed 2025-04-29 11:05:21 +08:00
1 parent cc6bf9433f
commit c1821a8eb8
1 file changed
+5 -6
+5 -6
View File
@@ -13,15 +13,14 @@
<small class="text-right underline text-xs cursor-pointer mt-1 inline-block">reply</small> <small class="text-right underline text-xs cursor-pointer mt-1 inline-block">reply</small>
</div> </div>
{% comment %} {% assign replies = site.comments | where: "parent", comment.slug | sort: "date" %}
Find and render any replies to this comment <div>comment_slug: {{ comment.slug }}</div> <!-- output is "comment1" -->
We need to get the filename without extension to match the parent field
{% endcomment %}
{% assign comment_filename = comment.path | split: "/" | last | replace: ".md", "" %}
{% assign replies = site.comments | where: "parent", comment_filename | sort: "date" %}
{% for reply in replies %} {% for reply in replies %}
<div>parent: {{ reply.parent }}</div> <!-- OK, matches comment.slug -->
<div>slug: {{ reply.slug }}</div> <!-- OK -->
<div class="ml-2 mt-4 border-l-2 border-gray-200 pl-2 text-sm md:pl-4"> <div class="ml-2 mt-4 border-l-2 border-gray-200 pl-2 text-sm md:pl-4">
<!-- Error: Nesting too deep included in ../_layouts/post.liquid -->
{% include comment.liquid comment=reply %} {% include comment.liquid comment=reply %}
</div> </div>
{% endfor %} {% endfor %}