Skip to content

Commit

Permalink
fix: displays featured section only if featured posts exist
Browse files Browse the repository at this point in the history
  • Loading branch information
satnaing committed Dec 2, 2022
1 parent 292e6ce commit e0f93da
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import Socials from "@components/Socials.astro";
const posts = await Astro.glob<Frontmatter>("../contents/**/*.md");
const sortedPosts = getSortedPosts(posts);
const featuredPosts = sortedPosts.filter(
({ frontmatter }) => frontmatter.featured
);
---

<Layout>
Expand Down Expand Up @@ -59,25 +62,25 @@ const sortedPosts = getSortedPosts(posts);

<Hr />

<section id="featured">
<h2>Featured</h2>
<ul>
{
sortedPosts.map(
({ frontmatter }) =>
frontmatter.featured && (
{
featuredPosts.length > 0 && (
<>
<section id="featured">
<h2>Featured</h2>
<ul>
{featuredPosts.map(({ frontmatter }) => (
<Card
href={`/posts/${slugify(frontmatter)}`}
post={frontmatter}
secHeading={false}
/>
)
)
}
</ul>
</section>

<Hr />
))}
</ul>
</section>
<Hr />
</>
)
}

<section id="recent-posts">
<h2>Recent Posts</h2>
Expand Down

0 comments on commit e0f93da

Please sign in to comment.