mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-17 07:26:46 +00:00
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
import BlogPostCard from './BlogPostCard'
|
|
import BLOG from '@/blog.config'
|
|
import BlogPostListEmpty from './BlogPostListEmpty'
|
|
import PaginationSimple from './PaginationSimple'
|
|
import { useRouter } from 'next/router'
|
|
|
|
/**
|
|
* 文章列表分页表格
|
|
* @param page 当前页
|
|
* @param posts 所有文章
|
|
* @param tags 所有标签
|
|
* @returns {JSX.Element}
|
|
* @constructor
|
|
*/
|
|
const BlogPostListPage = ({ page = 1, posts = [], postCount }) => {
|
|
let filteredPosts = Object.assign(posts)
|
|
const searchKey = getSearchKey()
|
|
if (searchKey) {
|
|
filteredPosts = posts.filter(post => {
|
|
const tagContent = post.tags ? post.tags.join(' ') : ''
|
|
const searchContent = post.title + post.summary + tagContent
|
|
return searchContent.toLowerCase().includes(searchKey.toLowerCase())
|
|
})
|
|
}
|
|
const filteredPostsCount = filteredPosts.length
|
|
const totalPage = Math.ceil(filteredPostsCount / BLOG.POSTS_PER_PAGE)
|
|
|
|
if (!posts || posts.length === 0) {
|
|
return <BlogPostListEmpty />
|
|
} else {
|
|
return (
|
|
<div id="container" className='w-full justify-center'>
|
|
{/* 文章列表 */}
|
|
{filteredPosts.map(post => (
|
|
<BlogPostCard key={post.id} post={post} />
|
|
))}
|
|
<PaginationSimple page={page} totalPage={totalPage} />
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
|
|
function getSearchKey () {
|
|
const router = useRouter()
|
|
if (router.query && router.query.s) {
|
|
return router.query.s
|
|
}
|
|
return null
|
|
}
|
|
|
|
export default BlogPostListPage
|