fix: displays featured section only if featured posts exist

This commit is contained in:
satnaing
2022-12-02 23:00:57 +06:30
parent 292e6ce3cb
commit e0f93dab02
+17 -14
View File
@@ -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>
@@ -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>