Skip to content

Commit 383d559

Browse files
committed
Only show "tags" and "latest posts" on homepage when applicable
1 parent 456e502 commit 383d559

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/pages/index.astro

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ if (home.length > 0) {
2121
homeGithubCalendar = homeEntry.data.githubCalendar
2222
}
2323
const sortedPosts = await getSortedPosts()
24+
const postsHaveTags = sortedPosts.some(
25+
(post) => post.data.tags && post.data.tags.length > 0,
26+
)
2427
---
2528

2629
<Layout>
@@ -31,11 +34,25 @@ const sortedPosts = await getSortedPosts()
3134
</HomeBanner>
3235
)
3336
}
34-
<BlockHeader>Tags</BlockHeader>
35-
<TagsSection posts={sortedPosts} />
36-
<BlockHeader>Latest Posts</BlockHeader>
37-
{sortedPosts.slice(0, siteConfig.pageSize).map((post) => <PostPreview post={post} />)}
38-
<Pagination nextLink="/posts" nextText="Archive" />
37+
{
38+
postsHaveTags && (
39+
<>
40+
<BlockHeader>Tags</BlockHeader>
41+
<TagsSection posts={sortedPosts} />
42+
</>
43+
)
44+
}
45+
{
46+
sortedPosts.length > 0 && (
47+
<>
48+
<BlockHeader>Latest Posts</BlockHeader>
49+
{sortedPosts.slice(0, siteConfig.pageSize).map((post) => (
50+
<PostPreview post={post} />
51+
))}
52+
<Pagination nextLink="/posts" nextText="Archive" />
53+
</>
54+
)
55+
}
3956
</Layout>
4057

4158
<style is:global>

0 commit comments

Comments
 (0)