feat(link-preview): frontend interface for Telegram-style URL preview

Adds the front-end side of the link-preview feature so the back-end
team has a fixed contract to implement against.

- docs/link-preview.md: full spec for the `/api/link-preview` proxy
  and the preferred inline-on-Post integration. Covers caching, SSRF
  guards, metadata-extraction precedence, provider quirks, and the
  front-end rendering rules. Scope is the first URL only.
- types/post.ts: new `LinkPreview` type and optional `linkPreview`
  field on `Post`.
- LinkPreviewCard: clickable card with a themeColor accent bar,
  siteName / title / description (line-clamped), and an optional
  1.91:1 thumbnail. Whole card is an `<a target="_blank">` to the
  canonical URL.
- MessageBubble: render the card between the bubble body and the
  timestamp, with padding that matches visual vs. text-only bubbles.
- mockPosts: example `linkPreview` payloads on p-005 and p-010 so
  the visual works when running with VITE_USE_MOCK_POSTS=true,
  and so the back-end has concrete reference values.
This commit is contained in:
TerryM
2026-05-30 01:40:00 +08:00
parent 09d887dd52
commit 29dc71d2dd
5 changed files with 371 additions and 0 deletions

View File

@@ -156,6 +156,19 @@ export const MOCK_POSTS: Post[] = [
isRecommended: false,
publishedAt: "2026-01-19T16:20:00.000Z",
updatedAt: "2026-01-19T16:20:00.000Z",
// Mock: only the FIRST URL in the text is previewed.
linkPreview: {
url: "https://coinmarketcap.com/currencies/ark-defai/",
canonicalUrl: "https://coinmarketcap.com/currencies/ark-defai/",
siteName: "coinmarketcap.com",
title: "ARK DeFAI Price, Chart & Market Cap",
description:
"Track ARK DeFAI live price, market cap, volume and historical chart on CoinMarketCap. Verified contract address, holders and on-chain analytics.",
imageUrl: img(81, 1200, 630),
imageWidth: 1200,
imageHeight: 630,
themeColor: "#2962FF",
},
},
// 6) 纯文本 + 单链接(简短公告)
@@ -254,6 +267,15 @@ export const MOCK_POSTS: Post[] = [
categorySlug: "meeting",
language: "zh-CN",
text: "📌 ARK DeFAI 方舟晨间时刻\n\n🧠 会议主题:市场概况交流 & 市场问题讨论。\n🕙 会议时间3月1日10:00\n🎬 直播腾讯会议链接https://meeting.tencent.com/l/G718S4Sedm38",
linkPreview: {
url: "https://meeting.tencent.com/l/G718S4Sedm38",
canonicalUrl: "https://meeting.tencent.com/l/G718S4Sedm38",
siteName: "meeting.tencent.com",
title: "腾讯会议 · ARK DeFAI 方舟晨间时刻",
description:
"点击直接加入直播会议。需要 App 或浏览器插件。会议号会在点击后自动补全。",
themeColor: "#0080FF",
},
attachments: [
{
id: "a-010",