mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
fix: displays featured section only if featured posts exist
This commit is contained in:
+17
-14
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user