import { useGlobal } from '@/lib/global' import { useRouter } from 'next/router' import Link from 'next/link' import BlogPost from './BlogPost' import { useEffect, useRef } from 'react' import { siteConfig } from '@/lib/config' export const BlogListPage = props => { const { page = 1, posts, postCount } = props const { locale } = useGlobal() const router = useRouter() const totalPage = Math.ceil(postCount / parseInt(siteConfig('POSTS_PER_PAGE'))) const currentPage = +page const showPrev = currentPage > 1 const showNext = page < totalPage const pagePrefix = router.asPath.split('?')[0].replace(/\/page\/[1-9]\d*/, '').replace(/\/$/, '') const blogPostRefs = useRef([]) useEffect(() => { const observer = new IntersectionObserver(entries => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.toggle('visible') } }) }, { threshold: 0.1 // 调整阈值以达到最佳效果 }) blogPostRefs.current.forEach(ref => { observer.observe(ref) }) return () => { observer.disconnect() } }, []) return (