From 23fe756f34986bf2688a4ece28a470121b6b953c Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Tue, 6 Dec 2022 22:35:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=A4=8D=E8=AF=B7=E6=B1=82=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Busuanzi.js | 19 ++++++++----------- components/PrismMac.js | 13 +------------ components/WalineComponent.js | 6 +++++- lib/busuanzi.js | 2 +- 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/components/Busuanzi.js b/components/Busuanzi.js index 12e592d8..fec41e5f 100644 --- a/components/Busuanzi.js +++ b/components/Busuanzi.js @@ -4,26 +4,23 @@ import { useGlobal } from '@/lib/global' // import { useRouter } from 'next/router' import React from 'react' +let path = '' + export default function Busuanzi () { const { theme } = useGlobal() - const router = useRouter() - - // 切换文章时更新 - React.useEffect(() => { - const busuanziRouteChange = url => { + const Router = useRouter() + Router.events.on('routeChangeComplete', (url, option) => { + if (url !== path) { + path = url busuanzi.fetch() } - router.events.on('routeChangeComplete', busuanziRouteChange) - return () => { - router.events.off('routeChangeComplete', busuanziRouteChange) - } - }, [router.events]) + }) // 更换主题时更新 React.useEffect(() => { if (theme) { busuanzi.fetch() } - }) + }, [theme]) return null } diff --git a/components/PrismMac.js b/components/PrismMac.js index 1aab0ddc..9193cfa6 100644 --- a/components/PrismMac.js +++ b/components/PrismMac.js @@ -9,26 +9,15 @@ import 'prismjs/plugins/line-numbers/prism-line-numbers.css' // mermaid图 import mermaid from 'mermaid' -import { useGlobal } from '@/lib/global' -import { useRouter } from 'next/router' /** * @author https://github.com/txs/ * @returns */ const PrismMac = () => { - const router = useRouter() - const { isDarkMode } = useGlobal() - const scrollTop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop - React.useEffect(() => { renderPrismMac() - window.scrollTo(0, scrollTop) - router.events.on('routeChangeComplete', renderPrismMac) - return () => { - router.events.off('routeChangeComplete', renderPrismMac) - } - }, [isDarkMode]) + }) return <> } diff --git a/components/WalineComponent.js b/components/WalineComponent.js index 2bff99f1..a8ccb3ac 100644 --- a/components/WalineComponent.js +++ b/components/WalineComponent.js @@ -3,6 +3,8 @@ import { init } from '@waline/client' import BLOG from '@/blog.config' import { useRouter } from 'next/router' +const path = '' + /** * @see https://waline.js.org/guide/get-started.html * @param {*} props @@ -14,7 +16,9 @@ const WalineComponent = (props) => { const router = useRouter() const updateWaline = url => { - walineInstanceRef.current?.update(props) + if (url !== path) { + walineInstanceRef.current?.update(props) + } } React.useEffect(() => { diff --git a/lib/busuanzi.js b/lib/busuanzi.js index df0564c4..9255485a 100644 --- a/lib/busuanzi.js +++ b/lib/busuanzi.js @@ -55,7 +55,7 @@ bszCaller = { const fetch = () => { bszTag && bszTag.hides() bszCaller.fetch('//busuanzi.ibruce.info/busuanzi?jsonpCallback=BusuanziCallback', function (t) { - // console.log('不蒜子请求结果',t) + // console.log('不蒜子',t) bszTag.texts(t), bszTag.shows() }) }