Skip to content

Commit

Permalink
fix images
Browse files Browse the repository at this point in the history
  • Loading branch information
tadaspetra committed Jun 4, 2024
1 parent c2cabc3 commit 683224c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/components/ArticleCard.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
import { Image } from "astro:assets";
const { article } = Astro.props;
const images = import.meta.glob<{ default: ImageMetadata }>(
"/src/assets/*.{jpeg,jpg,png,gif}"
);
const image = images[article.data.image]();
if (!image)
throw new Error(
`"${article.data.image}" does not exist in glob: "src/assets/*.{jpeg,jpg,png,gif}"`
);
---

<div class="flex flex-col mb-2">
Expand All @@ -10,11 +19,9 @@ const { article } = Astro.props;
class="rounded-lg p-4 hover:bg-gray-100 flex"
>
<Image
class="w-1/4 mr-4 rounded hidden md:block"
src={article.data.image}
class="w-1/4 mr-4 rounded hidden sm:block"
src={image}
alt={article.data.alt}
width={200}
height={200}
/>
<div>
<h2 class="font-semibold">{article.data.title}</h2>
Expand Down

0 comments on commit 683224c

Please sign in to comment.