Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove recent posts section if there's no post #238

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const posts = await getCollection("blog");

const sortedPosts = getSortedPosts(posts);
const featuredPosts = sortedPosts.filter(({ data }) => data.featured);
const recentPosts = sortedPosts.filter(({ data }) => !data.featured);

const socialCount = SOCIALS.filter(social => social.active).length;
---
Expand Down Expand Up @@ -83,18 +84,17 @@ const socialCount = SOCIALS.filter(social => social.active).length;
))}
</ul>
</section>
<Hr />
{recentPosts.length > 0 && <Hr />}
</>
)
}

<section id="recent-posts">
<h2>Recent Posts</h2>
<ul>
{
sortedPosts
.filter(({ data }) => !data.featured)
.map(
{
recentPosts.length > 0 && (
<section id="recent-posts">
<h2>Recent Posts</h2>
<ul>
{recentPosts.map(
({ data, slug }, index) =>
index < 4 && (
<Card
Expand All @@ -103,20 +103,22 @@ const socialCount = SOCIALS.filter(social => social.active).length;
secHeading={false}
/>
)
)
}
</ul>
<div class="all-posts-btn-wrapper">
<LinkButton href="/posts">
All Posts
<svg xmlns="http://www.w3.org/2000/svg"
><path
d="m11.293 17.293 1.414 1.414L19.414 12l-6.707-6.707-1.414 1.414L15.586 11H6v2h9.586z"
></path>
</svg>
</LinkButton>
</div>
</section>
)}
</ul>
</section>
)
}

<div class="all-posts-btn-wrapper">
<LinkButton href="/posts">
All Posts
<svg xmlns="http://www.w3.org/2000/svg"
><path
d="m11.293 17.293 1.414 1.414L19.414 12l-6.707-6.707-1.414 1.414L15.586 11H6v2h9.586z"
></path>
</svg>
</LinkButton>
</div>
</main>

<Footer />
Expand Down
Loading