import { cn } from '@/utils/cn' import Image from 'next/image' type ImageWrapperProps = { src: string alt?: string /** Visible caption. Falls back to the alt text when omitted. */ caption?: string isListing?: boolean /** Preload the image. Only set this for above-the-fold images (covers, latest post). */ priority?: boolean } export function ImageWrapper({ src, alt, caption, isListing, priority }: ImageWrapperProps) { const captionText = caption ?? alt // When the caption just repeats the alt text, hide it from screen readers so it isn't // announced twice const captionIsAlt = caption === undefined return (
{alt
{!isListing && captionText && (
{captionText}
)}
) }