This commit is contained in:
tangly1024
2022-02-13 13:22:58 +08:00
parent 22c9ca095b
commit 75d6a04d50
6 changed files with 115 additions and 27 deletions

View File

@@ -13,17 +13,7 @@ import { useRouter } from 'next/router'
* @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)
const totalPage = Math.ceil(postCount / BLOG.POSTS_PER_PAGE)
if (!posts || posts.length === 0) {
return <BlogPostListEmpty />
@@ -31,7 +21,7 @@ const BlogPostListPage = ({ page = 1, posts = [], postCount }) => {
return (
<div id="container" className='w-full justify-center'>
{/* 文章列表 */}
{filteredPosts.map(post => (
{posts.map(post => (
<BlogPostCard key={post.id} post={post} />
))}
<PaginationSimple page={page} totalPage={totalPage} />
@@ -40,12 +30,4 @@ const BlogPostListPage = ({ page = 1, posts = [], postCount }) => {
}
}
function getSearchKey () {
const router = useRouter()
if (router.query && router.query.s) {
return router.query.s
}
return null
}
export default BlogPostListPage