Placeholder image when no image provided for the recipe

This commit is contained in:
Jake Runyan 2026-02-10 09:40:25 -08:00
parent 6bbbb74e9a
commit 4cf3b526a1

View File

@ -8,9 +8,9 @@ interface RecipeCardProps {
export default function RecipeCard({ recipe }: RecipeCardProps) { export default function RecipeCard({ recipe }: RecipeCardProps) {
// Convert relative path to public URL // Convert relative path to public URL
const imageSrc = recipe.displayPhoto.startsWith('./') const imageSrc = recipe.displayPhoto && recipe.displayPhoto.startsWith('./')
? `/recipes/${recipe.folderPath}/${recipe.displayPhoto.replace('./', '')}`.replace(/\\/g, '/') ? `/recipes/${recipe.folderPath}/${recipe.displayPhoto.replace('./', '')}`.replace(/\\/g, '/')
: recipe.displayPhoto; : recipe.displayPhoto || null;
return ( return (
<Link <Link
@ -19,6 +19,7 @@ export default function RecipeCard({ recipe }: RecipeCardProps) {
aria-label={`View recipe: ${recipe.title}`} aria-label={`View recipe: ${recipe.title}`}
> >
<div className="aspect-video bg-gray-200 dark:bg-gray-700 relative overflow-hidden"> <div className="aspect-video bg-gray-200 dark:bg-gray-700 relative overflow-hidden">
{imageSrc ? (
<Image <Image
src={imageSrc} src={imageSrc}
alt={`${recipe.title} - Recipe photo`} alt={`${recipe.title} - Recipe photo`}
@ -27,6 +28,11 @@ export default function RecipeCard({ recipe }: RecipeCardProps) {
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw" sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
unoptimized unoptimized
/> />
) : (
<div className="flex items-center justify-center h-full text-4xl text-gray-400 dark:text-gray-600">
🍽
</div>
)}
</div> </div>
<div className="p-4 space-y-2"> <div className="p-4 space-y-2">