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> </div>
<div id="tab-favorites" class="hidden [&:target]:block"> <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"> <div class="favorites-list space-y-4">
{% for favorite in page.favorites %} {% for item in user_activity %}
{% if favorite.title %} {% if item.title %}
<!-- Render as Post --> <!-- Render as Post -->
<div class="mb-4"> <div class="mb-4">
<article class="flex flex-col md:flex-row items-start"> <article class="flex flex-col md:flex-row items-start">
@@ -130,8 +134,8 @@
<!-- Post Title --> <!-- Post Title -->
<p class="mt-0 mb-0.5"> <p class="mt-0 mb-0.5">
<strong> <strong>
<a href="{{ favorite.url }}" class="text-text-title font-bold text-md md:text-sm hover:underline"> <a href="{{ item.url }}" class="text-text-title font-bold text-md md:text-sm hover:underline">
{{ favorite.title }} {{ item.title }}
</a> </a>
</strong> </strong>
</p> </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="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> {{ favorite.upvotes | default: 0 }} <i class="fa-solid fa-arrow-up mr-1"></i> {{ item.upvotes | default: 0 }}
</span> </span>
<!-- Assuming a generic 'reply' action or link --> <!-- Link to the post's comment section -->
<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"> <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 <i class="fas fa-reply mr-1"></i> REPLY
</a> </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"> <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> {{ favorite.comments_count | default: 0 }} <i class="fas fa-comment mr-1"></i> {{ item.comments_count | default: 0 }}
</a> </a>
</div> </div>
<small class="text-sm font-action"> <small class="text-sm font-action">
<a href="/user/{{ favorite.author }}/" class="text-sm hover:underline">{{ favorite.author }}</a> <a href="/user/{{ item.author }}/" class="text-sm hover:underline">{{ item.author }}</a>
<span class="text-text-muted text-sm opacity-75">{{ favorite.date | date: "%d %b %Y" }}</span> <span class="text-text-muted text-sm opacity-75">{{ item.date | date: "%d %b %Y" }}</span>
</small> </small>
</div> </div>
</div> </div>
@@ -162,26 +166,27 @@
{% else %} {% else %}
<!-- Render as Comment --> <!-- Render as Comment -->
<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">{{ 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="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> {{ favorite.upvotes | default: 0 }} <i class="fa-solid fa-arrow-up mr-1"></i> {{ item.upvotes | default: 0 }}
</span> </span>
<!-- Link to the comment or its parent post --> <!-- Link to the comment's reply page 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-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 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 <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/{{ favorite.author }}/" class="text-sm hover:underline">{{ favorite.author }}</a> <a href="/user/{{ item.author }}/" class="text-sm hover:underline">{{ item.author }}</a>
<span class="text-text-muted text-sm opacity-75">{{ favorite.date | date: "%d %b %Y" }}</span> <span class="text-text-muted text-sm opacity-75">{{ item.date | date: "%d %b %Y" }}</span>
{% if favorite.post_title %} {% assign parent_post = site.posts | where_exp: "post", "post.comments contains item" | first %}
<span class="text-text-muted text-sm opacity-75">on: <a href="{{ favorite.post_url }}" class="hover:underline">{{ favorite.post_title }}</a></span> {% 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 %} {% endif %}
</small> </small>
</div> </div>
@@ -190,7 +195,7 @@
{% endfor %} {% endfor %}
</div> </div>
{% else %} {% 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 %} {% endif %}
</div> </div>
</div> </div>