From 67edb553c76dcb105bb6ec8cdb613f935e938c68 Mon Sep 17 00:00:00 2001 From: Kerby Martino Date: Tue, 29 Apr 2025 10:04:59 +0800 Subject: [PATCH] Fixing post comment rendering --- _config.yml | 2 +- _includes/comment.liquid | 28 +++++++++++++++++++ _layouts/post.liquid | 27 ++++++++++-------- ...pearing-ergonomic-chair-continues.markdown | 2 ++ 4 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 _includes/comment.liquid diff --git a/_config.yml b/_config.yml index 6284203..20343e0 100644 --- a/_config.yml +++ b/_config.yml @@ -53,4 +53,4 @@ collections: permalink: /:collection/:title/ comments: output: false - permalink: /:collection/:title/ + sort_by: date diff --git a/_includes/comment.liquid b/_includes/comment.liquid new file mode 100644 index 0000000..2675d21 --- /dev/null +++ b/_includes/comment.liquid @@ -0,0 +1,28 @@ +{% comment %} + Comment template - displays a single comment and its nested replies +{% endcomment %} + +
+
+ ▲ + @{{ comment.author }} + {{ comment.date | date: "%b %d, %Y" }} | parent | next +
+
+

{{ comment.content }}

+ reply +
+ + {% comment %} + Find and render any replies to this comment + 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 %} +
+ {% include comment.liquid comment=reply %} +
+ {% endfor %} +
\ No newline at end of file diff --git a/_layouts/post.liquid b/_layouts/post.liquid index 7dd37e9..caf2c4d 100644 --- a/_layouts/post.liquid +++ b/_layouts/post.liquid @@ -14,11 +14,13 @@ layout: default
@{{ page.author }} - {% assign comment_count = site.comments | where: "post", page.slug | size %} - {% if comment_count == 0 %} - {% assign filename = page.path | split: "/" | last | replace: ".md", "" %} - {% assign comment_count = site.comments | where: "post", filename | size %} + {% 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 comment_count = site.comments | where: "post", post_id | size %} {{ page.date | date: "%B %d, %Y" }} | report | next | {{ comment_count }} comments
@@ -45,14 +47,17 @@ layout: default

Comments

- {% assign comments = site.comments | where: "post", page.slug | where_exp: "item", "item.parent == nil" %} - {% if comments.size == 0 %} - {% assign filename = page.path | split: "/" | last | replace: ".md", "" %} - {% assign comments = site.comments | where: "post", filename | where_exp: "item", "item.parent == nil" %} + {% assign filename = page.path | split: "/" | last | replace: ".markdown", "" | replace: ".md", "" %} + {% if page.slug %} + {% assign post_id = page.slug %} + {% else %} + {% assign post_id = filename %} {% endif %} - {% if comments.size > 0 %} - {% for comment in comments %} - {% include comment.liquid comment=comment level=0 %} + {% assign top_level_comments = site.comments | where: "post", post_id | 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 %} {% endfor %} {% else %}

No comments yet.

diff --git a/_posts/2023-10-02-ask-the-saga-of-the-disappearing-ergonomic-chair-continues.markdown b/_posts/2023-10-02-ask-the-saga-of-the-disappearing-ergonomic-chair-continues.markdown index 146d66a..0bd3852 100644 --- a/_posts/2023-10-02-ask-the-saga-of-the-disappearing-ergonomic-chair-continues.markdown +++ b/_posts/2023-10-02-ask-the-saga-of-the-disappearing-ergonomic-chair-continues.markdown @@ -3,5 +3,7 @@ layout: post title: "[Ask] The saga of the disappearing ergonomic chair continues." date: 2023-10-02 10:00:00 +0000 categories: ask +slug: 2023-10-02-ask-the-saga-of-the-disappearing-ergonomic-chair-continues +author: deskdetective --- The saga of the disappearing ergonomic chair continues.