Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/link-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ export async function fetchOgp(url: string): Promise<OgpData | null> {
})

if (result.success) {
const rawImage = result.ogImage?.[0]?.url || ""
const ogpData: OgpData = {
title: result.ogTitle || result.dcTitle || extractTitleFromUrl(url),
description: result.ogDescription || result.dcDescription || "",
image: result.ogImage?.[0]?.url || "",
image: isValidProductImage(rawImage) ? rawImage : "",
url: result.ogUrl || url,
siteName: result.ogSiteName || extractDomain(url),
}
Expand All @@ -54,6 +55,19 @@ export async function fetchOgp(url: string): Promise<OgpData | null> {
return fallbackData
}

// Amazonロゴなど無効な画像を除外
function isValidProductImage(imageUrl: string): boolean {
if (!imageUrl) return false

const invalidPatterns = [
/amazon.*share.*logo/i,
/images\/G\/.*\.gif$/i, // Amazon generic images
/\/images\/G\//i, // Amazon site assets
]

return !invalidPatterns.some((pattern) => pattern.test(imageUrl))
}

function extractDomain(url: string): string {
try {
const hostname = new URL(url).hostname
Expand Down
6 changes: 3 additions & 3 deletions styles/global-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const GlobalStyles = createGlobalStyle`
.link-card-image {
flex-shrink: 0;
width: 120px;
min-height: 100px;
aspect-ratio: 1.2;
background-color: ${(props) => props.theme.colorBorder};
display: flex;
align-items: center;
Expand All @@ -122,7 +122,7 @@ const GlobalStyles = createGlobalStyle`
img {
width: 100%;
height: 100%;
object-fit: cover;
object-fit: contain;
margin: 0;
}
}
Expand Down Expand Up @@ -174,7 +174,7 @@ const GlobalStyles = createGlobalStyle`
@media (max-width: 480px) {
.link-card-image {
width: 80px;
min-height: 80px;
aspect-ratio: 1;
}

.link-card-content {
Expand Down