@@ -7,7 +7,7 @@ import Image from 'next/image'
77import Link from 'next/link'
88import { usePathname , useSearchParams } from 'next/navigation'
99import posthog from 'posthog-js'
10- import { useCallback , useRef , useState } from 'react'
10+ import { useCallback , useState } from 'react'
1111
1212interface BlogCardProps {
1313 id : string
@@ -23,6 +23,7 @@ interface BlogCardProps {
2323 href : string
2424 reactionsLength : number
2525 commentsLength : number
26+ priority ?: boolean
2627}
2728
2829export const BlogCard = ( {
@@ -35,11 +36,10 @@ export const BlogCard = ({
3536 image,
3637 reactionsLength,
3738 commentsLength,
39+ priority = false ,
3840} : BlogCardProps ) => {
3941 const pathname = usePathname ( )
4042 const searchParams = useSearchParams ( )
41- const cardImageId = `card-image-${ id } `
42- const cardImageElementRef = useRef < HTMLDivElement > ( null )
4343
4444 const [ hasLike , setHasLike ] = useState ( false )
4545
@@ -57,15 +57,8 @@ export const BlogCard = ({
5757 setHasLike ( ( oldState ) => ! oldState )
5858 } , [ ] )
5959
60- const handleImageOnLoad = useCallback ( ( ) => {
61- const div = cardImageElementRef . current
62- if ( div ) {
63- div . className = `${ div ?. className } loaded not-blur`
64- }
65- } , [ ] )
66-
6760 return (
68- < div className = "rounded-lg hover:bg-slate-100 dark:hover:bg-gray-700 overflow-hidden shadow-lg transition border-gray-400 dark:border-black hover:border-indigo-300 hover:border border bg-slate-50 dark:bg-gray-800" >
61+ < div className = "rounded-lg hover:bg-slate-100 dark:hover:bg-gray-700 overflow-hidden shadow-lg transition-all duration-200 border border -gray-200 dark:border-gray-700 hover:border-indigo-300 hover:shadow-xl bg-white dark:bg-gray-800" >
6962 < Link
7063 href = { href }
7164 onClick = { ( ) => {
@@ -76,53 +69,44 @@ export const BlogCard = ({
7669 } }
7770 >
7871 { image && (
79- < >
80- < div
81- id = { cardImageId }
82- ref = { cardImageElementRef }
83- className = "h-64 relative blurred-img"
84- style = {
85- ( image ?. blurDataURL && {
86- backgroundImage : `url(${ image ?. blurDataURL } )` ,
87- backgroundRepeat : 'no-repeat' ,
88- backgroundSize : 'cover' ,
89- } ) ||
90- { }
91- }
92- >
93- < Image
94- className = "object-cover"
95- fill
96- loading = "lazy"
97- onLoad = { handleImageOnLoad }
98- src = { image . src }
99- alt = { image . alt || title }
100- />
101- </ div >
102- </ >
72+ < div className = "relative aspect-video bg-gray-100 dark:bg-gray-700 overflow-hidden" >
73+ < Image
74+ className = "object-cover transition-transform duration-200 hover:scale-105"
75+ fill
76+ priority = { priority }
77+ loading = { priority ? 'eager' : 'lazy' }
78+ placeholder = { image . blurDataURL ? 'blur' : 'empty' }
79+ blurDataURL = { image . blurDataURL }
80+ sizes = "(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
81+ src = { image . src }
82+ alt = { image . alt || title }
83+ />
84+ </ div >
10385 ) }
104- < div className = "px-6 py-4" >
105- < h2 className = "font-bold text-slate-900 dark:text-white text-xl mb-2" >
86+ < div className = "px-6 py-4 flex flex-col gap-2 " >
87+ < h2 className = "font-bold text-slate-900 dark:text-white text-xl mb-2 line-clamp-2 " >
10688 { title }
10789 </ h2 >
10890 < p className = "text-gray-400 text-sm mb-2" >
109- { new Intl . DateTimeFormat ( 'pt-BR' , {
110- dateStyle : 'long' ,
111- } ) . format ( new Date ( publishedTime ) ) }
91+ < time dateTime = { new Date ( publishedTime ) . toISOString ( ) } >
92+ { new Intl . DateTimeFormat ( 'pt-BR' , {
93+ dateStyle : 'long' ,
94+ } ) . format ( new Date ( publishedTime ) ) }
95+ </ time >
11296 </ p >
113- < p className = "text-gray-700 dark:text-slate-300 text-base " >
97+ < p className = "text-gray-700 dark:text-slate-300 text-sm line-clamp-3 " >
11498 { description }
11599 </ p >
116100 </ div >
117101 </ Link >
118102
119- < div className = "px-6 pt-4 pb-2 " >
103+ < div className = "px-6 pt-4 flex flex-wrap gap-2 mb-4 text-blue-800 dark:text-blue-300 " >
120104 { tags ?. map ( ( tag ) => (
121105 < Link
122106 key = { `tag-${ tag } -${ id } ` }
123107 href = { pathname + '?' + createQueryString ( 'tag' , tag ) }
124108 rel = "noopener nofollow"
125- className = "inline-block bg-gray-200 dark:bg-slate-400 rounded-full px-3 py-1 text-sm font-semibold text -gray-700 dark:text-gray-800 mr-2 mb-2 "
109+ className = "inline-block bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300 rounded-full px-3 py-1 text-xs font-normal hover:bg -gray-300 dark:hover:bg-slate-300 transition-colors duration-200 "
126110 >
127111 #{ tag }
128112 </ Link >
0 commit comments