Skip to content

Commit 3ae08d9

Browse files
authored
Merge pull request #20 from ansidev/feature/component-post-list
Feature: Component PostList
2 parents 5fc47ff + d560b15 commit 3ae08d9

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/components/post/PostList.astro

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
import type { CollectionEntry } from 'astro:content'
3+
4+
import PostItem from '@/components/post/PostItem.astro'
5+
6+
export interface Props {
7+
posts: CollectionEntry<any>[];
8+
}
9+
10+
const { posts = [] } = Astro.props
11+
---
12+
13+
<div role="list" class="grid grid-cols-1 gap-4">
14+
{
15+
posts.map((p) => (
16+
<PostItem
17+
title={`${p.data.title}`}
18+
href={`/${p.slug}`}
19+
/>
20+
))
21+
}
22+
</div>

src/pages/index.astro

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
import { getCollection } from 'astro:content'
33
4-
import PostItem from '@/components/post/PostItem.astro'
4+
import PostList from '@/components/post/PostList.astro'
55
import siteConfig from '@/configs/site'
66
import AppLayout from '@/layouts/AppLayout.astro'
77
88
const { title, description, author } = siteConfig
99
10-
const allPosts = await getCollection('leetcode-solutions')
10+
const posts = await getCollection('leetcode-solutions')
1111
---
1212

1313
<AppLayout
@@ -17,12 +17,6 @@ const allPosts = await getCollection('leetcode-solutions')
1717
headerCssClasses="max-w-xl px-8"
1818
>
1919
<main class="mx-auto my-4 p-4 max-w-xl text-site-header-text">
20-
<div role="list" class="grid grid-cols-1 gap-4">
21-
{
22-
allPosts.map((p) => (
23-
<PostItem href={`/${p.slug}`} title={p.data.title} />
24-
))
25-
}
26-
</div>
20+
<PostList posts={posts} />
2721
</main>
2822
</AppLayout>

0 commit comments

Comments
 (0)