import { siteConfig } from '@/lib/config' import { useGlobal } from '@/lib/global' import Link from 'next/link' import { useRouter } from 'next/router' import { useEffect, useState } from 'react' import CONFIG from '../config' /** * 上一篇,下一篇文章 * @param {prev,next} param0 * @returns */ export default function PostAdjacent({ prev, next }) { const [isShow, setIsShow] = useState(false) const router = useRouter() const { locale } = useGlobal() useEffect(() => { setIsShow(false) }, [router]) useEffect(() => { // 文章到底部时显示下一篇文章推荐 const articleEnd = document.getElementById('article-end') const footerBottom = document.getElementById('footer-bottom') const handleIntersect = entries => { entries.forEach(entry => { if (entry.target === articleEnd) { if (entry.isIntersecting) { setIsShow(true) } } else if (entry.target === footerBottom) { if (entry.isIntersecting) { setIsShow(false) } } }) } const options = { root: null, rootMargin: '0px', threshold: 0.1 } const observer = new IntersectionObserver(handleIntersect, options) if (articleEnd) observer.observe(articleEnd) if (footerBottom) observer.observe(footerBottom) return () => { if (articleEnd) observer.unobserve(articleEnd) if (footerBottom) observer.unobserve(footerBottom) observer.disconnect() } }, []) if (!prev || !next || !siteConfig('HEO_ARTICLE_ADJACENT', null, CONFIG)) { return <>> } return (