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
+11 -8
View File
@@ -13,6 +13,9 @@ import Socials from "@components/Socials.astro";
const posts = await Astro.glob<Frontmatter>("../contents/**/*.md"); const posts = await Astro.glob<Frontmatter>("../contents/**/*.md");
const sortedPosts = getSortedPosts(posts); const sortedPosts = getSortedPosts(posts);
const featuredPosts = sortedPosts.filter(
({ frontmatter }) => frontmatter.featured
);
--- ---
<Layout> <Layout>
@@ -59,25 +62,25 @@ const sortedPosts = getSortedPosts(posts);
<Hr /> <Hr />
{
featuredPosts.length > 0 && (
<>
<section id="featured"> <section id="featured">
<h2>Featured</h2> <h2>Featured</h2>
<ul> <ul>
{ {featuredPosts.map(({ frontmatter }) => (
sortedPosts.map(
({ frontmatter }) =>
frontmatter.featured && (
<Card <Card
href={`/posts/${slugify(frontmatter)}`} href={`/posts/${slugify(frontmatter)}`}
post={frontmatter} post={frontmatter}
secHeading={false} secHeading={false}
/> />
) ))}
)
}
</ul> </ul>
</section> </section>
<Hr /> <Hr />
</>
)
}
<section id="recent-posts"> <section id="recent-posts">
<h2>Recent Posts</h2> <h2>Recent Posts</h2>