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 } else { return (
{/* 文章列表 */} {filteredPosts.map(post => ( ))}
) } } function getSearchKey () { const router = useRouter() if (router.query && router.query.s) { return router.query.s } return null } export default BlogPostListPage