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) /** * 组件持久化 */