Fixing post comment rendering

This commit is contained in:
Kerby Martino committed 2025-04-29 10:04:59 +08:00
1 parent 838f410b4d
commit 67edb553c7
4 files changed
+47 -12

No files matched your search

+1 -1
View File
@@ -53,4 +53,4 @@ collections:
permalink: /:collection/:title/
comments:
output: false
permalink: /:collection/:title/
sort_by: date
+28
View File
@@ -0,0 +1,28 @@
{% comment %}
Comment template - displays a single comment and its nested replies
{% endcomment %}
<div class="px-0 text-sm">
<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" }} | <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>
</div>
<div>
<p>{{ comment.content }}</p>
<small class="text-right underline text-xs cursor-pointer mt-1 inline-block">reply</small>
</div>
{% 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 %}
<div class="ml-2 mt-4 border-l-2 border-gray-200 pl-2 text-sm md:pl-4">
{% include comment.liquid comment=reply %}
</div>
{% endfor %}
</div>
+16 -11
View File
@@ -14,11 +14,13 @@ layout: default
<!-- Post title header -->
<div class="mt-0.5 mb-2 text-sm flex items-center">
<small class="text-text-muted ml-2 text-sm hover:underline">@{{ page.author }}</small>
{% 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 %}
<small class="text-text-muted ml-2 text-sm">{{ page.date | date: "%B %d, %Y" }} | <a href="#" class="ml-2 text-xs text-primary hover:underline">report</a> | <a href="#" class="ml-2 text-xs text-primary hover:underline">next</a> | <a href="#" class="ml-2 text-xs text-primary hover:underline">{{ comment_count }} comments</a></small>
</div>
@@ -45,14 +47,17 @@ layout: default
<h3 class="mt-4 text-lg font-medium">Comments</h3>
<div class="mt-4">
{% 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 %}
<p>No comments yet.</p>
@@ -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.