diff --git a/themes/next/Layout404.js b/themes/next/Layout404.js index 64341ec1..ee743351 100644 --- a/themes/next/Layout404.js +++ b/themes/next/Layout404.js @@ -16,13 +16,13 @@ export const Layout404 = props => { } } }, 3000) - }) + }, []) return
-

404

+

404

页面无法加载,即将返回首页

diff --git a/themes/next/LayoutSearch.js b/themes/next/LayoutSearch.js index 0a1c5fcc..5423f60e 100644 --- a/themes/next/LayoutSearch.js +++ b/themes/next/LayoutSearch.js @@ -2,21 +2,17 @@ import LayoutBase from './LayoutBase' import StickyBar from './components/StickyBar' import BlogPostListScroll from './components/BlogPostListScroll' import { useGlobal } from '@/lib/global' -import { useEffect } from 'react' export const LayoutSearch = (props) => { const { locale } = useGlobal() const { posts, keyword } = props - useEffect(() => { - setTimeout(() => { - const container = document.getElementById('container') - if (container && container.innerHTML) { - const re = new RegExp(`${keyword}`, 'gim') - container.innerHTML = container.innerHTML.replace(re, `${keyword}`) - } - }, - 100) - }) + setTimeout(() => { + const container = document.getElementById('container') + if (container && container.innerHTML) { + const re = new RegExp(`${keyword}`, 'gim') + container.innerHTML = container.innerHTML.replace(re, `${keyword}`) + } + }, 200) return ( @@ -26,7 +22,7 @@ export const LayoutSearch = (props) => {
- +
) diff --git a/themes/next/components/BlogPostListScroll.js b/themes/next/components/BlogPostListScroll.js index a220c8ad..d3b78fa6 100644 --- a/themes/next/components/BlogPostListScroll.js +++ b/themes/next/components/BlogPostListScroll.js @@ -44,7 +44,7 @@ const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = CONFIG_NE return () => { window.removeEventListener('scroll', scrollTrigger) } - }) + }, []) const targetRef = useRef(null) const { locale } = useGlobal() @@ -57,7 +57,7 @@ const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = CONFIG_NE {/* 文章列表 */}
{postsToShow.map(post => ( - + ))}
@@ -65,7 +65,7 @@ const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = CONFIG_NE
{ handleGetMore() }} - className='w-full my-4 py-4 text-center cursor-pointer glassmorphism shadow hover:shadow-xl duration-200 dark:text-gray-200' + className='w-full my-4 py-4 text-center cursor-pointer glassmorphism shadow hover:shadow-xl duration-200 dark:text-gray-200' > {hasMore ? locale.COMMON.MORE : `${locale.COMMON.NO_MORE} 😰`}
diff --git a/themes/next/components/Header.js b/themes/next/components/Header.js index 2b63ee72..37eb5e50 100644 --- a/themes/next/components/Header.js +++ b/themes/next/components/Header.js @@ -27,7 +27,7 @@ export default function Header(props) { }) ) } - }) + }, []) const { isDarkMode } = useGlobal() const autoScrollEnd = () => { @@ -90,7 +90,7 @@ export default function Header(props) { window.removeEventListener('scroll', scrollTrigger) window.removeEventListener('resize', updateHeaderHeight) } - }) + }, []) return (
{ if (window) { initLive2DWife() } - }) + }, []) return <> - + } -function initLive2DWife () { +function initLive2DWife() { // 注意:live2d_path 参数应使用绝对路径 const live2dPath = 'https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/' // const live2d_path = "/live2d-widget/"; diff --git a/themes/next/components/SideBarDrawer.js b/themes/next/components/SideBarDrawer.js index 9bc04d48..8a22505d 100644 --- a/themes/next/components/SideBarDrawer.js +++ b/themes/next/components/SideBarDrawer.js @@ -18,7 +18,7 @@ const SideBarDrawer = ({ post, cRef, tags, slot, categories, currentCategory }) useEffect(() => { const sideBarWrapperElement = document.getElementById('sidebar-wrapper') sideBarWrapperElement?.classList?.remove('hidden') - }) + }, []) const router = useRouter() useEffect(() => { @@ -52,7 +52,7 @@ const SideBarDrawer = ({ post, cRef, tags, slot, categories, currentCategory }) {/* 背景蒙版 */} - } /** * 更新字数统计和阅读时间 */ -function countWords () { +function countWords() { if (window) { const articleElement = document.getElementById('notion-article') if (articleElement) { @@ -33,13 +33,13 @@ function countWords () { } // 去除html标签 -function deleteHtmlTag (str) { +function deleteHtmlTag(str) { str = str.replace(/<[^>]+>|&[^>]+;/g, '').trim()// 去掉所有的html标签和 之类的特殊符合 return str } // 用word方式计算正文字数 -function fnGetCpmisWords (str) { +function fnGetCpmisWords(str) { let sLen = 0 try { // eslint-disable-next-line no-irregular-whitespace