feat: Populate user profile "Favorites" with submissions and comments

This commit is contained in:
Kerby Martino (aider) committed 2025-05-04 01:57:22 +08:00
1 parent 648c8a46cc
commit 3a188f33c9
1 file changed
+27 -22
+27 -22
View File
@@ -118,10 +118,14 @@
</div>
</div>
<div id="tab-favorites" class="hidden [&:target]:block">
{% if page.favorites and page.favorites.size > 0 %}
{% assign user_posts = site.posts | where_exp: "post", "post.author == page.username" %}
{% assign user_comments = site.comments | where_exp: "comment", "comment.author == page.username" %}
{% assign user_activity = user_posts | concat: user_comments | sort: "date" | reverse %}
{% if user_activity and user_activity.size > 0 %}
<div class="favorites-list space-y-4">
{% for favorite in page.favorites %}
{% if favorite.title %}
{% for item in user_activity %}
{% if item.title %}
<!-- Render as Post -->
<div class="mb-4">
<article class="flex flex-col md:flex-row items-start">
@@ -130,8 +134,8 @@
<!-- Post Title -->
<p class="mt-0 mb-0.5">
<strong>
<a href="{{ favorite.url }}" class="text-text-title font-bold text-md md:text-sm hover:underline">
{{ favorite.title }}
<a href="{{ item.url }}" class="text-text-title font-bold text-md md:text-sm hover:underline">
{{ item.title }}
</a>
</strong>
</p>
@@ -139,19 +143,19 @@
<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">
<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> {{ favorite.upvotes | default: 0 }}
<i class="fa-solid fa-arrow-up mr-1"></i> {{ item.upvotes | default: 0 }}
</span>
<!-- Assuming a generic 'reply' action or link -->
<a href="{{ favorite.url }}#comments" 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">
<!-- Link to the post's comment section -->
<a href="{{ item.url }}#comments" 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
</a>
<a href="{{ favorite.url }}#comments" 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-comment mr-1"></i> {{ favorite.comments_count | default: 0 }}
<a href="{{ item.url }}#comments" 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-comment mr-1"></i> {{ item.comments_count | default: 0 }}
</a>
</div>
<small class="text-sm font-action">
<a href="/user/{{ favorite.author }}/" class="text-sm hover:underline">{{ favorite.author }}</a>
<span class="text-text-muted text-sm opacity-75">{{ favorite.date | date: "%d %b %Y" }}</span>
<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>
</small>
</div>
</div>
@@ -162,26 +166,27 @@
{% else %}
<!-- Render as Comment -->
<div class="border-b border-gray-200 pb-3 mb-3">
<p class="text-sm mb-2">{{ favorite.content | markdownify | strip_html }}</p> <!-- Assuming content might be markdown -->
<p class="text-sm mb-2">{{ item.content | markdownify | strip_html }}</p> <!-- Assuming content might be markdown -->
<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">
<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> {{ favorite.upvotes | default: 0 }}
<i class="fa-solid fa-arrow-up mr-1"></i> {{ item.upvotes | default: 0 }}
</span>
<!-- Link to the comment or its parent post -->
<a href="{{ favorite.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">
<!-- Link to the comment's reply page or context -->
<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">
<i class="fas fa-reply mr-1"></i> REPLY
</a>
<!-- Link to the comment itself or context -->
<a href="{{ favorite.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="{{ 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">
<i class="fas fa-link mr-1"></i> VIEW
</a>
</div>
<small class="text-sm font-action">
<a href="/user/{{ favorite.author }}/" class="text-sm hover:underline">{{ favorite.author }}</a>
<span class="text-text-muted text-sm opacity-75">{{ favorite.date | date: "%d %b %Y" }}</span>
{% if favorite.post_title %}
<span class="text-text-muted text-sm opacity-75">on: <a href="{{ favorite.post_url }}" class="hover:underline">{{ favorite.post_title }}</a></span>
<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>
{% 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>
{% endif %}
</small>
</div>
@@ -190,7 +195,7 @@
{% endfor %}
</div>
{% else %}
<p class="text-text-muted">No favorites yet.</p>
<p class="text-text-muted">This user has no submissions or comments yet.</p>
{% endif %}
</div>
</div>