mirror of
https://github.com/runyanjake/cooking.git
synced 2026-03-26 09:53:17 -07:00
Placeholder image when no image provided for the recipe
This commit is contained in:
parent
6bbbb74e9a
commit
4cf3b526a1
@ -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,14 +19,20 @@ 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">
|
||||||
<Image
|
{imageSrc ? (
|
||||||
src={imageSrc}
|
<Image
|
||||||
alt={`${recipe.title} - Recipe photo`}
|
src={imageSrc}
|
||||||
fill
|
alt={`${recipe.title} - Recipe photo`}
|
||||||
className="object-cover"
|
fill
|
||||||
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
|
className="object-cover"
|
||||||
unoptimized
|
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
|
||||||
/>
|
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">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user