fix: Render comments in "Favorites" tab with correct post links
This commit is contained in:
1 parent
3a188f33c9
commit
ac0b093c26
1 file changed
+16
-8
@@ -165,32 +165,40 @@
|
|||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<!-- Render as Comment -->
|
<!-- Render as Comment -->
|
||||||
|
{% comment %} Try to find the parent post using post_slug from comment front matter {% endcomment %}
|
||||||
|
{% assign parent_post = site.posts | where: "slug", item.post_slug | first %}
|
||||||
|
|
||||||
|
{% if parent_post %}
|
||||||
|
{% comment %} Construct URL to the comment on the parent post's page {% endcomment %}
|
||||||
|
{% assign comment_anchor = '#comment-' | append: item.slug %}
|
||||||
|
{% assign comment_url = parent_post.url | append: comment_anchor %}
|
||||||
<div class="border-b border-gray-200 pb-3 mb-3">
|
<div class="border-b border-gray-200 pb-3 mb-3">
|
||||||
<p class="text-sm mb-2">{{ item.content | markdownify | strip_html }}</p> <!-- Assuming content might be markdown -->
|
<p class="text-sm mb-2">{{ item.content | markdownify | strip_html }}</p>
|
||||||
<div class="mt-2 mb-1 text-sm flex flex-col md:flex-row items-start md:items-center md:space-x-2">
|
<div class="mt-2 mb-1 text-sm flex flex-col md:flex-row items-start md:items-center md:space-x-2">
|
||||||
<div class="flex items-start space-x-2 mb-2 md:mb-0">
|
<div class="flex items-start space-x-2 mb-2 md:mb-0">
|
||||||
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
|
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
|
||||||
<i class="fa-solid fa-arrow-up mr-1"></i> {{ item.upvotes | default: 0 }}
|
<i class="fa-solid fa-arrow-up mr-1"></i> {{ item.upvotes | default: 0 }}
|
||||||
</span>
|
</span>
|
||||||
<!-- Link to the comment's reply page or context -->
|
<!-- Link to the comment itself on the post page -->
|
||||||
<a href="{{ item.url }}" class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
|
<a href="{{ comment_url }}" class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
|
||||||
<i class="fas fa-reply mr-1"></i> REPLY
|
<i class="fas fa-reply mr-1"></i> REPLY
|
||||||
</a>
|
</a>
|
||||||
<!-- Link to the comment itself or context -->
|
<!-- Link to the comment itself on the post page -->
|
||||||
<a href="{{ item.url }}" class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
|
<a href="{{ comment_url }}" class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
|
||||||
<i class="fas fa-link mr-1"></i> VIEW
|
<i class="fas fa-link mr-1"></i> VIEW
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<small class="text-sm font-action">
|
<small class="text-sm font-action">
|
||||||
<a href="/user/{{ item.author }}/" class="text-sm hover:underline">{{ item.author }}</a>
|
<a href="/user/{{ item.author }}/" class="text-sm hover:underline">{{ item.author }}</a>
|
||||||
<span class="text-text-muted text-sm opacity-75">{{ item.date | date: "%d %b %Y" }}</span>
|
<span class="text-text-muted text-sm opacity-75">{{ item.date | date: "%d %b %Y" }}</span>
|
||||||
{% assign parent_post = site.posts | where_exp: "post", "post.comments contains item" | first %}
|
|
||||||
{% if parent_post %}
|
|
||||||
<span class="text-text-muted text-sm opacity-75">on: <a href="{{ parent_post.url }}" class="hover:underline">{{ parent_post.title }}</a></span>
|
<span class="text-text-muted text-sm opacity-75">on: <a href="{{ parent_post.url }}" class="hover:underline">{{ parent_post.title }}</a></span>
|
||||||
{% endif %}
|
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% else %}
|
||||||
|
{% comment %} Optional: Render a fallback or error if parent post not found {% endcomment %}
|
||||||
|
<!-- <div class="border-b border-gray-200 pb-3 mb-3 text-red-500 text-xs">Comment by {{item.author}} on {{item.date | date: "%d %b %Y"}} - Parent post '{{ item.post_slug }}' not found.</div> -->
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user