Skip to content

Commit

Permalink
fix: handle case where main image is missing (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
niccofyren authored Sep 23, 2024
1 parent 8d0b2c1 commit 9cd0915
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/components/NewsComp.astro
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface Article {
name: string;
slug: string;
}>;
main_image: {
main_image?: {
url: string;
full_url: string;
width: number;
Expand Down Expand Up @@ -75,11 +75,11 @@ const articles = await fetchArticles();
)}
</time>
</div>
<img
{article.main_image && <img
src={article.main_image.full_url}
alt={article.main_image.alt}
class="w-24 h-24 object-cover ml-2 rounded-lg"
/>
/>}
</article>
</a>
))
Expand Down
6 changes: 3 additions & 3 deletions src/pages/news/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ const article = await fetchArticleById(articleId);
{new Date(article.meta.first_published_at).toLocaleDateString()}
</time>
<!-- Main Image -->
<img
{article.main_image && <img
src={article.main_image.full_url}
alt={article.main_image.alt}
class="w-auto h-auto mb-4"
/>
/>}
<!-- Article Content -->
<div class="text-white" set:html={article.body}></div>
</Main>
</Layout>
</Layout>

0 comments on commit 9cd0915

Please sign in to comment.