terry-staging #12
@@ -1,5 +1,27 @@
|
|||||||
import type { LinkPreview } from "../../types/post";
|
import type { LinkPreview } from "../../types/post";
|
||||||
|
|
||||||
|
const LINK_ACCENT = "#eeb726";
|
||||||
|
|
||||||
|
const DOMAIN_ACCENT_OVERRIDES: Array<[string, string]> = [
|
||||||
|
// Tencent Meeting returns themeColor="#000000", which disappears on the
|
||||||
|
// dark bubble surface. Keep it consistent with inline link color instead.
|
||||||
|
["meeting.tencent.com", LINK_ACCENT],
|
||||||
|
];
|
||||||
|
|
||||||
|
function linkPreviewAccent(preview: LinkPreview): string {
|
||||||
|
const url = preview.canonicalUrl || preview.url;
|
||||||
|
try {
|
||||||
|
const host = new URL(url).hostname.replace(/^www\./, "");
|
||||||
|
const match = DOMAIN_ACCENT_OVERRIDES.find(
|
||||||
|
([domain]) => host === domain || host.endsWith(`.${domain}`),
|
||||||
|
);
|
||||||
|
if (match) return match[1];
|
||||||
|
} catch {
|
||||||
|
// Ignore malformed preview URLs and fall back below.
|
||||||
|
}
|
||||||
|
return preview.themeColor || LINK_ACCENT;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Telegram-style rich preview card for a single URL embedded in a post.
|
* Telegram-style rich preview card for a single URL embedded in a post.
|
||||||
*
|
*
|
||||||
@@ -8,7 +30,7 @@ import type { LinkPreview } from "../../types/post";
|
|||||||
* that opens `canonicalUrl` in a new tab.
|
* that opens `canonicalUrl` in a new tab.
|
||||||
*/
|
*/
|
||||||
export function LinkPreviewCard({ preview }: { preview: LinkPreview }) {
|
export function LinkPreviewCard({ preview }: { preview: LinkPreview }) {
|
||||||
const accent = preview.themeColor || "#EEB726";
|
const accent = linkPreviewAccent(preview);
|
||||||
const hasUsefulText =
|
const hasUsefulText =
|
||||||
preview.title.length > 0 || preview.description.length > 0;
|
preview.title.length > 0 || preview.description.length > 0;
|
||||||
if (!hasUsefulText && !preview.imageUrl) return null;
|
if (!hasUsefulText && !preview.imageUrl) return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user