Fix for comment rendering

This commit is contained in:
Kerby Martino committed 2025-04-29 16:04:18 +08:00
1 parent f5790642b2
commit c8540a111d
5 files changed
+34 -24

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
--- ---
slug: comment1
post: 2023-10-02-ask-the-saga-of-the-disappearing-ergonomic-chair-continues post: 2023-10-02-ask-the-saga-of-the-disappearing-ergonomic-chair-continues
author: commenter1 author: commenter1
date: 2023-10-02 12:00:00 +0000 date: 2023-10-02 12:00:00 +0000
slug: comment1
--- ---
Haha, this totally happened to me last year. We had a phantom chair thief at work and it became an ongoing office joke for months! Haha, this totally happened to me last year. We had a phantom chair thief at work and it became an ongoing office joke for months!
+2 -2
View File
@@ -1,8 +1,8 @@
--- ---
slug: comment1_reply1
parent: comment1
post: 2023-10-02-ask-the-saga-of-the-disappearing-ergonomic-chair-continues post: 2023-10-02-ask-the-saga-of-the-disappearing-ergonomic-chair-continues
author: nestedcommenter1 author: nestedcommenter1
date: 2023-10-02 13:00:00 +0000 date: 2023-10-02 13:00:00 +0000
parent: comment1
slug: comment1_reply1
--- ---
Did they ever catch who it was? 😂 I'd totally set up a hidden camera if it kept happening that much. Did they ever catch who it was? 😂 I'd totally set up a hidden camera if it kept happening that much.
+1 -1
View File
@@ -1,7 +1,7 @@
--- ---
slug: comment2
post: 2023-10-02-ask-the-saga-of-the-disappearing-ergonomic-chair-continues post: 2023-10-02-ask-the-saga-of-the-disappearing-ergonomic-chair-continues
author: commenter2 author: commenter2
date: 2023-10-02 14:00:00 +0000 date: 2023-10-02 14:00:00 +0000
slug: comment2
--- ---
At my old job, chairs were so bad people would "borrow" a good one whenever someone went on vacation. A real survival of the fittest situation! At my old job, chairs were so bad people would "borrow" a good one whenever someone went on vacation. A real survival of the fittest situation!
+28 -12
View File
@@ -1,26 +1,42 @@
{% comment %} {% comment %}
Comment template - displays a single comment and its nested replies Flat iterative version - no recursion, just nested loops up to N levels
{% endcomment %} {% endcomment %}
<div class="px-0 text-sm"> {% assign top_comments = site.comments | where: "parent", nil | sort: "date" %}
{% 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"> <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> <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.author }}</small>
<small class="text-text-muted ml-2 text-sm">{{ comment.date | date: "%b %d, %Y" }} | <a href="#" class="ml-2 text-xs text-primary hover:underline">parent</a> | <a href="#" class="ml-2 text-xs text-primary hover:underline">next</a></small> <small class="text-text-muted ml-2 text-sm">{{ comment.date | date: "%b %d, %Y" }}</small>
</div> </div>
<div>
<p>{{ comment.content }}</p> <p>{{ comment.content }}</p>
<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>
{% assign replies = site.comments | where: "parent", comment.slug | sort: "date" %} {% assign replies = site.comments | where: "parent", comment.slug | sort: "date" %}
<div>comment_slug: {{ comment.slug }}</div> <!-- output is "comment1" -->
{% for reply in replies %} {% for reply in replies %}
<div>parent: {{ reply.parent }}</div> <!-- OK, matches comment.slug --> <div class="ml-4 mt-3 border-l-2 border-gray-200 pl-2">
<div>slug: {{ reply.slug }}</div> <!-- OK --> <div class="mb-1">
<div class="ml-2 mt-4 border-l-2 border-gray-200 pl-2 text-sm md:pl-4"> <small class="text-text-muted">@{{ reply.author }}</small> –
{% include comment.liquid comment=reply %} <small class="text-text-muted">{{ reply.date | date: "%b %d, %Y" }}</small>
</div>
<p>{{ reply.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" %}
{% for reply2 in replies2 %}
<div class="ml-4 mt-3 border-l-2 border-gray-200 pl-2">
<div class="mb-1">
<small class="text-text-muted">@{{ reply2.author }}</small> –
<small class="text-text-muted">{{ reply2.date | date: "%b %d, %Y" }}</small>
</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 #}
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
{% endfor %}
</div>
{% endfor %}
+2 -8
View File
@@ -47,14 +47,7 @@ layout: default
<h3 class="mt-4 text-lg font-medium">Comments</h3> <h3 class="mt-4 text-lg font-medium">Comments</h3>
<div class="mt-4"> <div class="mt-4">
{% assign filename = page.path | split: "/" | last | replace: ".markdown", "" | replace: ".md", "" %} {% assign top_level_comments = site.comments | where: "post", page.slug | where_exp: "item", "item.parent == nil" | sort: "date" %}
{% if page.slug %}
{% assign post_id = page.slug %}
{% else %}
{% assign post_id = filename %}
{% endif %}
{% assign top_level_comments = site.comments | where: "post", post_id | where_exp: "item", "item.parent == nil" | sort: "date" %}
{% if top_level_comments.size > 0 %} {% if top_level_comments.size > 0 %}
{% for comment in top_level_comments %} {% for comment in top_level_comments %}
{% include comment.liquid comment=comment %} {% include comment.liquid comment=comment %}
@@ -64,3 +57,4 @@ layout: default
{% endif %} {% endif %}
</div> </div>
</div> </div>