diff --git a/_comments/comment1.md b/_comments/comment1.md index 30674f8..896dfd5 100644 --- a/_comments/comment1.md +++ b/_comments/comment1.md @@ -1,7 +1,7 @@ --- +slug: comment1 post: 2023-10-02-ask-the-saga-of-the-disappearing-ergonomic-chair-continues author: commenter1 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! diff --git a/_comments/comment1_reply1.md b/_comments/comment1_reply1.md index abc6f14..1ca72d3 100644 --- a/_comments/comment1_reply1.md +++ b/_comments/comment1_reply1.md @@ -1,8 +1,8 @@ --- +slug: comment1_reply1 +parent: comment1 post: 2023-10-02-ask-the-saga-of-the-disappearing-ergonomic-chair-continues author: nestedcommenter1 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. diff --git a/_comments/comment2.md b/_comments/comment2.md index 7a42c75..5b84ffb 100644 --- a/_comments/comment2.md +++ b/_comments/comment2.md @@ -1,7 +1,7 @@ --- +slug: comment2 post: 2023-10-02-ask-the-saga-of-the-disappearing-ergonomic-chair-continues author: commenter2 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! diff --git a/_includes/comment.liquid b/_includes/comment.liquid index 40cc33a..fb52757 100644 --- a/_includes/comment.liquid +++ b/_includes/comment.liquid @@ -1,26 +1,42 @@ {% comment %} - Comment template - displays a single comment and its nested replies + Flat iterative version - no recursion, just nested loops up to N levels {% endcomment %} -
-
- â–² - @{{ comment.author }} - {{ comment.date | date: "%b %d, %Y" }} | parent | next -
-
+{% assign top_comments = site.comments | where: "parent", nil | sort: "date" %} + +{% for comment in top_comments %} +
+
+ â–² + @{{ 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 %} +
+
+ @{{ reply.author }} – + {{ reply.date | date: "%b %d, %Y" }} +
+

{{ reply.content }}

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

{{ reply2.content }}

+ reply + {# Extend further levels here if needed #} +
+ {% endfor %} +
+ {% endfor %}
- - {% assign replies = site.comments | where: "parent", comment.slug | sort: "date" %} -
comment_slug: {{ comment.slug }}
- - {% for reply in replies %} -
parent: {{ reply.parent }}
-
slug: {{ reply.slug }}
-
- {% include comment.liquid comment=reply %} -
- {% endfor %} -
+{% endfor %} diff --git a/_layouts/post.liquid b/_layouts/post.liquid index caf2c4d..a978e4d 100644 --- a/_layouts/post.liquid +++ b/_layouts/post.liquid @@ -47,14 +47,7 @@ layout: default

Comments

- {% assign filename = page.path | split: "/" | last | replace: ".markdown", "" | replace: ".md", "" %} - {% 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" %} - + {% assign top_level_comments = site.comments | where: "post", page.slug | where_exp: "item", "item.parent == nil" | sort: "date" %} {% if top_level_comments.size > 0 %} {% for comment in top_level_comments %} {% include comment.liquid comment=comment %} @@ -64,3 +57,4 @@ layout: default {% endif %}
+