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..a47999c7 100644
--- a/components/WalineComponent.js
+++ b/components/WalineComponent.js
@@ -3,28 +3,34 @@ import { init } from '@waline/client'
import BLOG from '@/blog.config'
import { useRouter } from 'next/router'
+const path = ''
+let waline = null
/**
* @see https://waline.js.org/guide/get-started.html
* @param {*} props
* @returns
*/
const WalineComponent = (props) => {
- const walineInstanceRef = React.useRef(null)
const containerRef = React.createRef()
const router = useRouter()
const updateWaline = url => {
- walineInstanceRef.current?.update(props)
+ if (url !== path) {
+ waline.update(props)
+ }
}
React.useEffect(() => {
- walineInstanceRef.current = init({
- ...props,
- el: containerRef.current,
- serverURL: BLOG.COMMENT_WALINE_SERVER_URL
- })
- router.events.on('routeChangeComplete', updateWaline)
+ if (!waline) {
+ waline = init({
+ ...props,
+ el: containerRef.current,
+ serverURL: BLOG.COMMENT_WALINE_SERVER_URL
+ })
+ }
+ // 跳转评论
+ router.events.on('routeChangeComplete', updateWaline)
const anchor = window.location.hash
if (anchor) {
// 选择需要观察变动的节点
@@ -54,7 +60,8 @@ const WalineComponent = (props) => {
}
return () => {
- walineInstanceRef.current?.destroy()
+ waline.destroy()
+ waline = null
router.events.off('routeChangeComplete', updateWaline)
}
}, [])
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()
})
}
diff --git a/next.config.js b/next.config.js
index 50e4c1c8..f2a86bc5 100644
--- a/next.config.js
+++ b/next.config.js
@@ -17,6 +17,14 @@ module.exports = withBundleAnalyzer({
'images.unsplash.com'
]
},
+ async rewrites() {
+ return [
+ {
+ source: '/:path*.html',
+ destination: '/:path*'
+ }
+ ]
+ },
async headers() {
return [
{
diff --git a/pages/[...slug].js b/pages/[...slug].js
index 63eb5e51..997297e7 100644
--- a/pages/[...slug].js
+++ b/pages/[...slug].js
@@ -24,6 +24,7 @@ const Slug = props => {
const [lock, setLock] = React.useState(post?.password && post?.password !== '')
React.useEffect(() => {
+ changeLoadingState(false)
if (post?.password && post?.password !== '') {
setLock(true)
} else {
@@ -32,7 +33,6 @@ const Slug = props => {
}, [post])
if (!post) {
- changeLoadingState(true)
setTimeout(() => {
if (isBrowser()) {
const article = document.getElementById('container')
@@ -47,8 +47,6 @@ const Slug = props => {
return