From 05d6f0b0655e8bb27975cd1a78aa6615661204b2 Mon Sep 17 00:00:00 2001 From: velor2012 <38395332+velor2012@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:41:04 +0800 Subject: [PATCH 1/4] Update Twikoo.js --- components/Twikoo.js | 55 +++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/components/Twikoo.js b/components/Twikoo.js index 6899cfaa..3d3a08ff 100644 --- a/components/Twikoo.js +++ b/components/Twikoo.js @@ -1,6 +1,6 @@ import { siteConfig } from '@/lib/config' -// import { loadExternalResource } from '@/lib/utils' -import { useEffect } from 'react' +import { loadExternalResource } from '@/lib/utils' +import { useEffect, useRef, useState } from 'react' /** * Giscus评论 @see https://giscus.app/zh-CN @@ -12,23 +12,46 @@ import { useEffect } from 'react' const Twikoo = ({ isDarkMode }) => { const envId = siteConfig('COMMENT_TWIKOO_ENV_ID') const el = siteConfig('COMMENT_TWIKOO_ELEMENT_ID', '#twikoo') - + const twikooCDNURL = siteConfig('COMMENT_TWIKOO_CDN_URL') const lang = siteConfig('LANG') - useEffect(() => { - const twikoo = window?.twikoo - if (typeof twikoo !== 'undefined' && twikoo && typeof twikoo.init === 'function') { - twikoo.init({ - envId: envId, // 腾讯云环境填 envId;Vercel 环境填地址(https://xxx.vercel.app) - el: el, // 容器元素 - lang: lang // 用于手动设定评论区语言,支持的语言列表 https://github.com/imaegoo/twikoo/blob/main/src/client/utils/i18n/index.js - // region: 'ap-guangzhou', // 环境地域,默认为 ap-shanghai,腾讯云环境填 ap-shanghai 或 ap-guangzhou;Vercel 环境不填 - // path: location.pathname, // 用于区分不同文章的自定义 js 路径,如果您的文章路径不是 location.pathname,需传此参数 - }) + const [isInit] = useState(useRef(false)) + + const loadTwikoo = async () => { + try { + await loadExternalResource(twikooCDNURL, 'js') + const twikoo = window?.twikoo + if ( + typeof twikoo !== 'undefined' && + twikoo && + typeof twikoo.init === 'function' + ) { + twikoo.init({ + envId: envId, // 腾讯云环境填 envId;Vercel 环境填地址(https://xxx.vercel.app) + el: el, // 容器元素 + lang: lang // 用于手动设定评论区语言,支持的语言列表 https://github.com/imaegoo/twikoo/blob/main/src/client/utils/i18n/index.js + // region: 'ap-guangzhou', // 环境地域,默认为 ap-shanghai,腾讯云环境填 ap-shanghai 或 ap-guangzhou;Vercel 环境不填 + // path: location.pathname, // 用于区分不同文章的自定义 js 路径,如果您的文章路径不是 location.pathname,需传此参数 + }) + console.log('twikoo init', twikoo) + isInit.current = true + } + } catch (error) { + console.error('twikoo 加载失败', error) } + } + + useEffect(() => { + const interval = setInterval(() => { + if (isInit.current) { + console.log('twioo init! clear interval') + clearInterval(interval) + } else { + loadTwikoo() + } + }, 1000) + return () => clearInterval(interval) }, [isDarkMode]) - return ( -
- ) + return
} export default Twikoo From f89e3a66bf0798a41abb01c2df40f5475efefa07 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Mon, 29 Jan 2024 19:04:45 +0800 Subject: [PATCH 2/4] Next Theme - WWAds --- themes/next/components/ArticleDetail.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/themes/next/components/ArticleDetail.js b/themes/next/components/ArticleDetail.js index 6ba1c48e..efb20983 100644 --- a/themes/next/components/ArticleDetail.js +++ b/themes/next/components/ArticleDetail.js @@ -14,6 +14,7 @@ import NotionIcon from '@/components/NotionIcon' import LazyImage from '@/components/LazyImage' import { formatDateFmt } from '@/lib/formatDate' import { siteConfig } from '@/lib/config' +import WWAds from '@/components/WWAds' /** * @@ -79,7 +80,9 @@ export default function ArticleDetail(props) { {/* Notion内容主体 */}
+ {post && ()} +
{showArticleInfo && <> From 48bf3012e8cb9662317f8d998a84fb280288b0f9 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Tue, 30 Jan 2024 10:58:47 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=BE=AE=E8=BD=AFclarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog.config.js | 3 +++ components/Busuanzi.js | 8 ++++---- components/ExternalPlugins.js | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/blog.config.js b/blog.config.js index 50e16921..8f35f94d 100644 --- a/blog.config.js +++ b/blog.config.js @@ -352,6 +352,9 @@ const BLOG = { SEO_BAIDU_SITE_VERIFICATION: process.env.NEXT_PUBLIC_SEO_BAIDU_SITE_VERIFICATION || '', // Remove the value or replace it with your own google site verification code + // 微软 Clarity 站点分析 + CLARITY_ID: process.env.NEXT_PUBLIC_CLARITY_ID || null , // 只需要复制Clarity脚本中的ID部分,ID是一个十位的英文数字组合 + // <---- 站点统计 // START---->营收相关 diff --git a/components/Busuanzi.js b/components/Busuanzi.js index fec41e5f..cbeb54da 100644 --- a/components/Busuanzi.js +++ b/components/Busuanzi.js @@ -2,14 +2,14 @@ import busuanzi from '@/lib/busuanzi' import { useRouter } from 'next/router' import { useGlobal } from '@/lib/global' // import { useRouter } from 'next/router' -import React from 'react' +import { useEffect } from 'react' let path = '' export default function Busuanzi () { const { theme } = useGlobal() - const Router = useRouter() - Router.events.on('routeChangeComplete', (url, option) => { + const router = useRouter() + router.events.on('routeChangeComplete', (url, option) => { if (url !== path) { path = url busuanzi.fetch() @@ -17,7 +17,7 @@ export default function Busuanzi () { }) // 更换主题时更新 - React.useEffect(() => { + useEffect(() => { if (theme) { busuanzi.fetch() } diff --git a/components/ExternalPlugins.js b/components/ExternalPlugins.js index 77433f97..b426ee65 100644 --- a/components/ExternalPlugins.js +++ b/components/ExternalPlugins.js @@ -78,6 +78,7 @@ const ExternalPlugin = (props) => { const DIFY_CHATBOT_ENABLED = siteConfig('DIFY_CHATBOT_ENABLED') const TIANLI_KEY = siteConfig('TianliGPT_KEY') const GLOBAL_JS = siteConfig('GLOBAL_JS') + const CLARITY_ID = siteConfig('CLARITY_ID') // 自定义样式css和js引入 if (isBrowser) { @@ -167,6 +168,19 @@ const ExternalPlugin = (props) => { }} /> )} + + {CLARITY_ID && (<> +