yufan.me/src/components/page/post/PostCards.astro

26 lines
748 B
Plaintext
Raw Normal View History

2024-06-14 02:11:26 +08:00
---
import Pagination from '@/components/page/pagination/Pagination.astro';
import { slicePosts } from '@/helpers/formatter';
2024-06-14 02:11:26 +08:00
import type { Post } from '@/helpers/schema';
import options from '@/options';
import PostCard from './PostCard.astro';
2024-06-14 02:11:26 +08:00
interface Props {
posts: Post[];
pageNum: number;
2024-06-14 02:11:26 +08:00
}
const { pageNum, posts } = Astro.props;
const results = slicePosts(posts, pageNum, options.settings.pagination.posts);
if (!results) {
return Astro.redirect('/404');
}
const { currentPosts, totalPage } = results;
2024-06-14 02:11:26 +08:00
---
<div class="content-wrapper content-wrapper col-12 col-xl-9">
<div class="list-grid">{currentPosts.map((post) => <PostCard post={post} />)}</div>
<Pagination current={pageNum} total={totalPage} rootPath={'/'} />
</div>