From 63ece674781b892115ea2a8c084f576c5302c57d Mon Sep 17 00:00:00 2001 From: srleom Date: Wed, 20 Mar 2024 10:27:41 +0800 Subject: [PATCH] Allowed card images to be optional --- src/components/Card.astro | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/components/Card.astro b/src/components/Card.astro index 75a7586..ef26099 100644 --- a/src/components/Card.astro +++ b/src/components/Card.astro @@ -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}"`) +} --- - {altText} + { + imagePath && ( + {altText} + ) + }

{heading}