From 250e9e03f9d4532ca1306d8971e2f0104db0325d Mon Sep 17 00:00:00 2001 From: tlyong1992 Date: Wed, 25 May 2022 11:06:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E7=94=A8=E5=8E=9F=E7=94=9FValine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog.config.js | 6 ++++-- components/Comment.js | 26 +++++++------------------- components/ValineComponent.js | 26 ++++++++++++++++++++++++++ package.json | 4 ++-- 4 files changed, 39 insertions(+), 23 deletions(-) create mode 100644 components/ValineComponent.js diff --git a/blog.config.js b/blog.config.js index 72307871..2bb079aa 100644 --- a/blog.config.js +++ b/blog.config.js @@ -102,10 +102,12 @@ const BLOG = { COMMENT_DAO_VOICE_ID: process.env.NEXT_PUBLIC_COMMENT_DAO_VOICE_ID || '', // DaoVoice http://dashboard.daovoice.io/get-started COMMENT_TIDIO_ID: process.env.NEXT_PUBLIC_COMMENT_TIDIO_ID || '', // [tidio_id] -> //code.tidio.co/[tidio_id].js - COMMENT_VALINE_APP_ID: process.env.NEXT_PUBLIC_VALINE_ID || '', // Valine @see https://github.com/stonehank/react-valine#%E8%8E%B7%E5%8F%96app-id-%E5%92%8C-app-key + COMMENT_VALINE_APP_ID: process.env.NEXT_PUBLIC_VALINE_ID || '', // Valine @see https://valine.js.org/quickstart.html 或 https://github.com/stonehank/react-valine#%E8%8E%B7%E5%8F%96app-id-%E5%92%8C-app-key COMMENT_VALINE_APP_KEY: process.env.NEXT_PUBLIC_VALINE_KEY || '', + COMMENT_VALINE_SERVER_URLS: process.env.NEXT_PUBLIC_VALINE_SERVER_URLS || '', // 该配置适用于国内自定义域名用户, 海外版本会自动检测(无需手动填写) @see https://valine.js.org/configuration.html#serverURLs + COMMENT_VALINE_PLACEHOLDER: process.env.NEXT_PUBLIC_VALINE_PLACEHOLDER || '抢个沙发吧~', - // 站点统计 + // 站点统计 ANALYTICS_BUSUANZI_ENABLE: true, // 展示网站阅读量、访问数 see http://busuanzi.ibruce.info/ ANALYTICS_BAIDU_ID: process.env.NEXT_PUBLIC_ANALYTICS_BAIDU_ID || '', // e.g 只需要填写百度统计的id,[baidu_id] -> https://hm.baidu.com/hm.js?[baidu_id] ANALYTICS_CNZZ_ID: process.env.NEXT_PUBLIC_ANALYTICS_CNZZ_ID || '', // 只需要填写站长统计的id, [cnzz_id] -> https://s9.cnzz.com/z_stat.php?id=[cnzz_id]&web_id=[cnzz_id] diff --git a/components/Comment.js b/components/Comment.js index d8f7769c..890a92d1 100644 --- a/components/Comment.js +++ b/components/Comment.js @@ -23,13 +23,10 @@ const GiscusComponent = dynamic( }, { ssr: false } ) -const Valine = dynamic(() => import('@/components/Valine'), { + +const ValineComponent = dynamic(() => import('@/components/ValineComponent'), { ssr: false }) -const ValinePanel = dynamic( - () => import('@/components/ValinePanel'), - { ssr: false } -) const Comment = ({ frontMatter }) => { if (!frontMatter) { @@ -37,7 +34,7 @@ const Comment = ({ frontMatter }) => { } const router = useRouter() const { locale, isDarkMode } = useGlobal() - const theme = isDarkMode ? 'dark' : 'light' + // const theme = isDarkMode ? 'dark' : 'light' return (
@@ -49,21 +46,12 @@ const Comment = ({ frontMatter }) => {
)} - {BLOG.COMMENT_UTTERRANCES_REPO && (
- + {BLOG.COMMENT_VALINE_APP_ID && (
+
)} - {BLOG.COMMENT_VALINE_APP_ID && (
- - - - + {BLOG.COMMENT_UTTERRANCES_REPO && (
+
)} {BLOG.COMMENT_CUSDIS_APP_ID && (
diff --git a/components/ValineComponent.js b/components/ValineComponent.js new file mode 100644 index 00000000..2829ace7 --- /dev/null +++ b/components/ValineComponent.js @@ -0,0 +1,26 @@ +import BLOG from '@/blog.config' +import React from 'react' +import Valine from 'valine' + +const ValineComponent = (props) => { + const { path } = props + React.useEffect(() => { + const valine = Valine({ + el: '#vcomments', + appId: BLOG.COMMENT_VALINE_APP_ID, + appKey: BLOG.COMMENT_VALINE_APP_KEY, + avatar: '', + path: path, + recordIP: false, + placeholder: BLOG.COMMENT_VALINE_PLACEHOLDER, + serverURLs: BLOG.COMMENT_VALINE_SERVER_URLS, + visitor: true + }) + if (!valine) { + console.error('valine插件加载失败') + } + }) + return
+} + +export default ValineComponent diff --git a/package.json b/package.json index 912c81f5..8c9c3d05 100644 --- a/package.json +++ b/package.json @@ -45,10 +45,10 @@ "react-messenger-customer-chat": "^0.8.0", "react-notion-x": "6.6.2", "react-share": "^4.4.0", - "react-valine": "^0.6.2", "smoothscroll-polyfill": "^0.4.4", "typed.js": "^2.0.12", - "use-ackee": "^3.0.0" + "use-ackee": "^3.0.0", + "valine": "^1.4.18" }, "devDependencies": { "autoprefixer": "^10.2.5",