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 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 />
<section id="featured"> {
<h2>Featured</h2> featuredPosts.length > 0 && (
<ul> <>
{ <section id="featured">
sortedPosts.map( <h2>Featured</h2>
({ frontmatter }) => <ul>
frontmatter.featured && ( {featuredPosts.map(({ frontmatter }) => (
<Card <Card
href={`/posts/${slugify(frontmatter)}`} href={`/posts/${slugify(frontmatter)}`}
post={frontmatter} post={frontmatter}
secHeading={false} secHeading={false}
/> />
) ))}
) </ul>
} </section>
</ul> <Hr />
</section> </>
)
<Hr /> }
<section id="recent-posts"> <section id="recent-posts">
<h2>Recent Posts</h2> <h2>Recent Posts</h2>