feat(blog): comment count badge on post overview
PostCard now shows a small comment-count pill in the top-left of the image when count > 0. BlogOverview bulk-fetches counts for the visible posts via the new `/api/comments/counts?ids=…` endpoint and passes them down. One request per page render, regardless of card count. - New helper `getCommentCounts()` in `cms.ts` - `BlogOverview.svelte` derives slugs from posts, fires bulk fetch in `$effect`, hands the result map to `PostCard` - `PostCard.svelte` accepts `commentCount?: number | null`, renders pill only when value is a positive number Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import Icon from "@iconify/svelte";
|
||||
import "$lib/iconify-offline";
|
||||
import type { PostEntry } from "$lib/cms";
|
||||
import PostMeta from "./PostMeta.svelte";
|
||||
import EventBadges from "./EventBadges.svelte";
|
||||
@@ -15,10 +17,13 @@
|
||||
post,
|
||||
href,
|
||||
tagBase = "/posts/tag",
|
||||
commentCount = null,
|
||||
}: {
|
||||
post: PostWithImage;
|
||||
href: string;
|
||||
tagBase?: string;
|
||||
/** Approved comment count. `null` = unknown/loading, hide badge. `0` = also hide. */
|
||||
commentCount?: number | null;
|
||||
} = $props();
|
||||
|
||||
const rawImg = $derived(post._rawImageUrl);
|
||||
@@ -89,6 +94,18 @@
|
||||
</span>
|
||||
</div>
|
||||
{/if}
|
||||
{#if commentCount != null && commentCount > 0}
|
||||
<div class="absolute top-2 left-2">
|
||||
<span
|
||||
class="inline-flex items-center gap-1 rounded-full bg-white/90 px-2 py-1 text-[.65rem] font-semibold tabular-nums text-zinc-700 shadow-sm"
|
||||
aria-label="{commentCount} Kommentare"
|
||||
title="{commentCount} Kommentare"
|
||||
>
|
||||
<Icon icon="mdi:comment-outline" class="size-3" />
|
||||
{commentCount}
|
||||
</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="flex-1 flex flex-col justify-start p-4">
|
||||
<PostMeta
|
||||
|
||||
Reference in New Issue
Block a user