refactor(OGCard): replace static image with dynamic generated graph (#10115)

* refactor(OGCard): replace static image with dynamic generated graph

- Replace CherryLogo import with GeneratedGraph component for dynamic preview
- Extract image height to constant for consistency
- Use useCallback for GeneratedGraph to optimize performance

* chore: remove unused banner.png asset

* style(OGCard): change image height from pixels to rem units

Use rem units for better responsiveness and consistency with the design system
This commit is contained in:
Phantom 2025-09-11 22:20:52 +08:00 committed by GitHub
parent 5e19e7ac6c
commit d17362d8c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 6 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 299 KiB

View File

@ -1,8 +1,7 @@
import CherryLogo from '@renderer/assets/images/banner.png'
import Favicon from '@renderer/components/Icons/FallbackFavicon' import Favicon from '@renderer/components/Icons/FallbackFavicon'
import { useMetaDataParser } from '@renderer/hooks/useMetaDataParser' import { useMetaDataParser } from '@renderer/hooks/useMetaDataParser'
import { Skeleton, Typography } from 'antd' import { Skeleton, Typography } from 'antd'
import { useEffect, useMemo } from 'react' import { useCallback, useEffect, useMemo } from 'react'
import styled from 'styled-components' import styled from 'styled-components'
const { Title, Paragraph } = Typography const { Title, Paragraph } = Typography
@ -11,6 +10,8 @@ type Props = {
show: boolean show: boolean
} }
const IMAGE_HEIGHT = '9rem' // equals h-36
export const OGCard = ({ link, show }: Props) => { export const OGCard = ({ link, show }: Props) => {
const openGraph = ['og:title', 'og:description', 'og:image', 'og:imageAlt'] as const const openGraph = ['og:title', 'og:description', 'og:image', 'og:imageAlt'] as const
const { metadata, isLoading, parseMetadata } = useMetaDataParser(link, openGraph) const { metadata, isLoading, parseMetadata } = useMetaDataParser(link, openGraph)
@ -32,6 +33,14 @@ export const OGCard = ({ link, show }: Props) => {
} }
}, [parseMetadata, isLoading, show]) }, [parseMetadata, isLoading, show])
const GeneratedGraph = useCallback(() => {
return (
<div className="flex h-36 items-center justify-center bg-accent p-4">
<h2 className="text-2xl font-bold">{metadata['og:title'] || hostname}</h2>
</div>
)
}, [hostname, metadata])
if (isLoading) { if (isLoading) {
return <CardSkeleton /> return <CardSkeleton />
} }
@ -45,7 +54,7 @@ export const OGCard = ({ link, show }: Props) => {
)} )}
{!hasImage && ( {!hasImage && (
<PreviewImageContainer> <PreviewImageContainer>
<PreviewImage src={CherryLogo} alt={'no image'} /> <GeneratedGraph />
</PreviewImageContainer> </PreviewImageContainer>
)} )}
@ -113,8 +122,8 @@ const PreviewContainer = styled.div<{ hasImage?: boolean }>`
const PreviewImageContainer = styled.div` const PreviewImageContainer = styled.div`
width: 100%; width: 100%;
height: 140px; height: ${IMAGE_HEIGHT};
min-height: 140px; min-height: ${IMAGE_HEIGHT};
overflow: hidden; overflow: hidden;
` `
@ -128,7 +137,7 @@ const PreviewContent = styled.div`
const PreviewImage = styled.img` const PreviewImage = styled.img`
width: 100%; width: 100%;
height: 140px; height: ${IMAGE_HEIGHT};
object-fit: cover; object-fit: cover;
` `