Spaces:
Sleeping
Sleeping
Download frontend/src/components/PostCard.tsx from Ethscriptions/cut: direct link, hf CLI and curl.
- Browser
- Download file 5.26 kB
-
https://huggingface.co/spaces/Ethscriptions/cut/resolve/main/frontend/src/components/PostCard.tsx
- Command line
-
hf download hf://spaces/Ethscriptions/cut/frontend/src/components/PostCard.tsx
-
curl -L -o PostCard.tsx https://huggingface.co/spaces/Ethscriptions/cut/resolve/main/frontend/src/components/PostCard.tsx
5.26 kB
| import { ExternalLink, Eye, Heart, MessageCircle, Repeat2, Send } from 'lucide-react' | |
| import { formatCount, timeAgo } from '@/lib/format' | |
| import type { Post } from '@/lib/types' | |
| import CodeBadge from './CodeBadge' | |
| const KIND_LABEL: Record<string, string> = { gift: '赠链', box: '盲盒链接', talk: '讨论' } | |
| function sourceLabel(post: Post) { | |
| if (post.source === 'telegram') return 'Telegram' | |
| if (post.source === 'manual') return '手动添加' | |
| return 'X' | |
| } | |
| /** Render text with links clickable and the gift links highlighted. */ | |
| function RichText({ text }: { text: string }) { | |
| const parts = text.split(/(https?:\/\/[^\s<>"'))】]+)/g) | |
| return ( | |
| <p className="whitespace-pre-wrap break-words text-[14px] leading-6 text-fg-base"> | |
| {parts.map((part, i) => | |
| /^https?:\/\//.test(part) ? ( | |
| <a | |
| key={i} | |
| href={part} | |
| target="_blank" | |
| rel="noreferrer" | |
| className={ | |
| /mystery-box\/g\//i.test(part) | |
| ? 'rounded bg-brand-10 px-1 font-mono text-[13px] text-brand-100 hover:underline' | |
| : 'text-brand-100 hover:underline' | |
| } | |
| > | |
| {part.replace(/^https?:\/\//, '').slice(0, 60)} | |
| {part.replace(/^https?:\/\//, '').length > 60 ? '…' : ''} | |
| </a> | |
| ) : ( | |
| <span key={i}>{part}</span> | |
| ) | |
| )} | |
| </p> | |
| ) | |
| } | |
| export default function PostCard({ post }: { post: Post }) { | |
| const media = (post.media || []).filter((m) => m?.url).slice(0, 4) | |
| const author = post.author_name || post.author || '未知' | |
| const handle = post.source === 'x' && post.author ? `@${post.author}` : null | |
| const created = post.created_at ? post.created_at * 1000 : null | |
| const codes = post.codes || [] | |
| const usable = codes.some((c) => c.usable) | |
| const text = post.text || '' | |
| return ( | |
| <article | |
| className={`rounded-[14px] border bg-[var(--bg-subtle)] p-4 transition-colors ${ | |
| usable ? 'border-brand-60' : 'border-[var(--border-strong)]' | |
| }`} | |
| > | |
| <header className="flex items-start justify-between gap-3"> | |
| <div className="min-w-0"> | |
| <div className="flex flex-wrap items-center gap-x-2 gap-y-0.5"> | |
| <span className="truncate text-sm font-bold">{author}</span> | |
| {handle && <span className="text-xs text-fg-muted">{handle}</span>} | |
| </div> | |
| <div className="mt-0.5 flex flex-wrap items-center gap-x-2 text-[11px] text-fg-muted"> | |
| <span className="inline-flex items-center gap-1"> | |
| {post.source === 'telegram' && <Send className="h-3 w-3" />} | |
| {sourceLabel(post)} | |
| </span> | |
| {post.via && post.source === 'telegram' && <span className="truncate">· {post.via}</span>} | |
| {created && <span>· {timeAgo(created)}</span>} | |
| </div> | |
| </div> | |
| <div className="flex shrink-0 items-center gap-2"> | |
| <span | |
| className={`rounded-full px-2 py-0.5 text-[11px] font-medium ${ | |
| post.kind === 'gift' ? 'bg-brand-10 text-brand-100' : 'bg-[var(--bg-subtle-hover)] text-fg-muted' | |
| }`} | |
| > | |
| {KIND_LABEL[post.kind] || post.kind} | |
| </span> | |
| {post.url && ( | |
| <a | |
| href={post.url} | |
| target="_blank" | |
| rel="noreferrer" | |
| className="text-fg-muted hover:text-fg-base" | |
| title="打开原帖" | |
| > | |
| <ExternalLink className="h-4 w-4" /> | |
| </a> | |
| )} | |
| </div> | |
| </header> | |
| {text && ( | |
| <div className="mt-3"> | |
| <RichText text={text.length > 900 ? `${text.slice(0, 900)}…` : text} /> | |
| </div> | |
| )} | |
| {media.length > 0 && ( | |
| <div className={`mt-3 grid gap-1.5 ${media.length > 1 ? 'grid-cols-2' : 'grid-cols-1'}`}> | |
| {media.map((m, i) => ( | |
| <a key={i} href={m.url} target="_blank" rel="noreferrer" className="block overflow-hidden rounded-lg"> | |
| <img src={m.url} alt="" loading="lazy" className="max-h-72 w-full object-cover" /> | |
| </a> | |
| ))} | |
| </div> | |
| )} | |
| {codes.length > 0 && ( | |
| <div className="mt-3 flex flex-wrap gap-2"> | |
| {codes.map((code) => ( | |
| <CodeBadge key={code.code} info={code} /> | |
| ))} | |
| </div> | |
| )} | |
| {post.source === 'x' && (post.views || post.likes || post.reposts || post.replies) ? ( | |
| <footer className="mt-3 flex flex-wrap gap-4 text-[11px] text-fg-muted"> | |
| <span className="inline-flex items-center gap-1"> | |
| <MessageCircle className="h-3 w-3" /> | |
| {formatCount(post.replies)} | |
| </span> | |
| <span className="inline-flex items-center gap-1"> | |
| <Repeat2 className="h-3 w-3" /> | |
| {formatCount(post.reposts)} | |
| </span> | |
| <span className="inline-flex items-center gap-1"> | |
| <Heart className="h-3 w-3" /> | |
| {formatCount(post.likes)} | |
| </span> | |
| <span className="inline-flex items-center gap-1"> | |
| <Eye className="h-3 w-3" /> | |
| {formatCount(post.views)} | |
| </span> | |
| </footer> | |
| ) : null} | |
| </article> | |
| ) | |
| } | |