--- import { apiClient, resolvePublicApiBaseUrl, resolvePublicCommentTurnstileSiteKey, } from '../lib/api/client'; import { getI18n } from '../lib/i18n'; import type { Comment } from '../lib/api/client'; import type { SiteSettings } from '../lib/types'; interface Props { postSlug: string; class?: string; siteSettings: SiteSettings; } const { postSlug, class: className = '', siteSettings } = Astro.props as Props; const { locale, t } = getI18n(Astro); const publicApiBaseUrl = resolvePublicApiBaseUrl(Astro.url); const commentVerificationMode = siteSettings.comments.verificationMode; const turnstileSiteKey = commentVerificationMode === 'turnstile' ? siteSettings.comments.turnstileSiteKey || resolvePublicCommentTurnstileSiteKey() : ''; let comments: Comment[] = []; let error: string | null = null; try { comments = await apiClient.getComments(postSlug, { approved: true, scope: 'article' }); } catch (e) { error = e instanceof Error ? e.message : t('comments.loadFailed'); console.error('Failed to fetch comments:', e); } function formatCommentDate(dateStr: string): string { const date = new Date(dateStr); const now = new Date(); const diff = now.getTime() - date.getTime(); const days = Math.floor(diff / (1000 * 60 * 60 * 24)); if (days === 0) return t('comments.today'); if (days === 1) return t('comments.yesterday'); if (days < 7) return t('comments.daysAgo', { count: days }); if (days < 30) return t('comments.weeksAgo', { count: Math.floor(days / 7) }); return date.toLocaleDateString(locale, { month: 'short', day: 'numeric' }); } ---
{t('comments.kicker')}

{t('comments.title')}

{t('comments.description', { count: comments.length })}

{error ? (
{error}
) : comments.length === 0 ? (

{t('comments.emptyTitle')}

{t('comments.emptyDescription')}

) : ( comments.map(comment => (
{comment.author || t('comments.anonymous')} {formatCommentDate(comment.created_at)}

{comment.content}

)) )}