import { useState, useEffect } from 'react' import Image from 'next/image' import { useRouter } from 'next/router' import type { Page, MdxFile } from 'nextra' import { Author } from '../Author/Authors' import { Video } from '../Video' const BlogCard = ({ page, handleTagClick, selectedTags = [], }: { page: MdxFile & Page handleTagClick: (tag: string) => void selectedTags?: string[] }) => { const router = useRouter() const [cardWidth, setCardWidth] = useState(0) const [maxDescriptionLength, setMaxDescriptionLength] = useState(160) const handleCardClick = () => { router.push(page.route) } useEffect(() => { setMaxDescriptionLength(cardWidth > 260 ? 145 : 46) // Adjust maxLength based on card width }, [cardWidth]) useEffect(() => { const updateCardWidth = () => { setCardWidth(document.querySelector('.blog-card')?.clientWidth ?? 0) } window.addEventListener('resize', updateCardWidth) updateCardWidth() return () => { window.removeEventListener('resize', updateCardWidth) } }, []) const truncateDescription = (text) => { if (text.length > maxDescriptionLength) { return text.slice(0, maxDescriptionLength) + '...' } return text } return (