From 5b5f7bc58830bff8a691c76b50581353f7e43fbe Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Thu, 21 Nov 2024 12:56:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E8=AE=BA=20=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Comment.js | 104 +++++++++++++++++++++--------------------- lib/utils/index.js | 13 ++---- 2 files changed, 55 insertions(+), 62 deletions(-) diff --git a/components/Comment.js b/components/Comment.js index fce7078d..fc63dfc9 100644 --- a/components/Comment.js +++ b/components/Comment.js @@ -6,56 +6,6 @@ import { useRouter } from 'next/router' import { useEffect, useRef, useState } from 'react' import Artalk from './Artalk' -const WalineComponent = dynamic( - () => { - return import('@/components/WalineComponent') - }, - { ssr: false } -) - -const CusdisComponent = dynamic( - () => { - return import('@/components/CusdisComponent') - }, - { ssr: false } -) - -const TwikooCompenent = dynamic( - () => { - return import('@/components/Twikoo') - }, - { ssr: false } -) - -const GitalkComponent = dynamic( - () => { - return import('@/components/Gitalk') - }, - { ssr: false } -) -const UtterancesComponent = dynamic( - () => { - return import('@/components/Utterances') - }, - { ssr: false } -) -const GiscusComponent = dynamic( - () => { - return import('@/components/Giscus') - }, - { ssr: false } -) -const WebMentionComponent = dynamic( - () => { - return import('@/components/WebMention') - }, - { ssr: false } -) - -const ValineComponent = dynamic(() => import('@/components/ValineComponent'), { - ssr: false -}) - /** * 评论组件 * 只有当前组件在浏览器可见范围内才会加载内容 @@ -114,10 +64,10 @@ const Comment = ({ frontMatter, className }) => { } if (!frontMatter) { - return <>Loading... + return null } - if (isSearchEngineBot()) { + if (isSearchEngineBot) { return null } @@ -204,4 +154,54 @@ const Comment = ({ frontMatter, className }) => { ) } +const WalineComponent = dynamic( + () => { + return import('@/components/WalineComponent') + }, + { ssr: false } +) + +const CusdisComponent = dynamic( + () => { + return import('@/components/CusdisComponent') + }, + { ssr: false } +) + +const TwikooCompenent = dynamic( + () => { + return import('@/components/Twikoo') + }, + { ssr: false } +) + +const GitalkComponent = dynamic( + () => { + return import('@/components/Gitalk') + }, + { ssr: false } +) +const UtterancesComponent = dynamic( + () => { + return import('@/components/Utterances') + }, + { ssr: false } +) +const GiscusComponent = dynamic( + () => { + return import('@/components/Giscus') + }, + { ssr: false } +) +const WebMentionComponent = dynamic( + () => { + return import('@/components/WebMention') + }, + { ssr: false } +) + +const ValineComponent = dynamic(() => import('@/components/ValineComponent'), { + ssr: false +}) + export default Comment diff --git a/lib/utils/index.js b/lib/utils/index.js index 7817ed74..fddca08b 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -27,16 +27,9 @@ export const shuffleArray = array => { * google机器人 * @returns */ -export const isSearchEngineBot = () => { - if (typeof navigator === 'undefined') { - return false - } - // 获取用户代理字符串 - const userAgent = navigator.userAgent - // 使用正则表达式检测是否包含搜索引擎爬虫关键字 - return /Googlebot|bingbot|Baidu/.test(userAgent) -} - +export const isSearchEngineBot = + typeof navigator !== 'undefined' && + /Googlebot|bingbot|Baidu/.test(navigator.userAgent) /** * 组件持久化 */