Allowed card images to be optional

This commit is contained in:
srleom
2024-03-20 10:27:41 +08:00
parent eb09d991d9
commit 63ece67478

View File

@ -15,8 +15,11 @@ const {
imageClass
} = Astro.props
const images = import.meta.glob<{ default: ImageMetadata }>('/src/assets/*.{jpeg,jpg,png,gif}')
if (!images[imagePath])
throw new Error(`"${imagePath}" does not exist in glob: "src/assets/*.{jpeg,jpg,png,gif}"`)
if (imagePath) {
if (!images[imagePath])
throw new Error(`"${imagePath}" does not exist in glob: "src/assets/*.{jpeg,jpg,png,gif}"`)
}
---
<Tag
@ -27,12 +30,16 @@ if (!images[imagePath])
)}
href={href}
>
<Image
src={images[imagePath]()}
alt={altText}
class={cn('mb-3 md:absolute md:mb-0', imageClass)}
loading='eager'
/>
{
imagePath && (
<Image
src={images[imagePath]()}
alt={altText}
class={cn('mb-3 md:absolute md:mb-0', imageClass)}
loading='eager'
/>
)
}
<div class='flex flex-col gap-y-1.5'>
<div class='flex flex-col gap-y-0.5'>
<h1 class='text-lg font-medium'>{heading}</h1>