From 9973d6bf7381b2f90b4e3d01421b209e59f33657 Mon Sep 17 00:00:00 2001 From: anime Date: Sat, 12 Apr 2025 03:22:21 +0800 Subject: [PATCH] feat(email encrypt): implement base64 encoding for contact email config Closes #2438 Closes #3319 --- themes/commerce/components/SocialButton.js | 20 ++++++++------------ themes/fukasawa/components/SocialButton.js | 14 +++++++++----- themes/gitbook/components/SocialButton.js | 12 ++++++++---- themes/hexo/components/SocialButton.js | 14 +++++++++----- themes/magzine/components/SocialButton.js | 14 +++++++++----- themes/matery/components/SocialButton.js | 19 +++++++------------ themes/medium/components/SocialButton.js | 19 +++++++------------ themes/nav/components/SocialButton.js | 19 +++++++------------ themes/plog/components/SocialButton.js | 19 +++++++------------ themes/starter/components/SocialButton.js | 19 +++++++------------ 10 files changed, 78 insertions(+), 91 deletions(-) diff --git a/themes/commerce/components/SocialButton.js b/themes/commerce/components/SocialButton.js index 3572010a..adf18d7f 100644 --- a/themes/commerce/components/SocialButton.js +++ b/themes/commerce/components/SocialButton.js @@ -1,5 +1,7 @@ import { siteConfig } from '@/lib/config' -import { useEffect, useRef } from 'react' +import { useRef } from 'react' +import { handleEmailClick } from '@/lib/plugins/mailEncrypt' + /** * 社交联系方式按钮组 * @returns {JSX.Element} @@ -18,12 +20,7 @@ const SocialButton = () => { const CONTACT_YOUTUBE = siteConfig('CONTACT_YOUTUBE') const emailIcon = useRef(null) - useEffect(() => { - if (CONTACT_EMAIL && emailIcon.current) { - emailIcon.current.href = - 'mailto:' + decodeURIComponent(escape(atob(CONTACT_EMAIL))) - } - }, [CONTACT_EMAIL]) + return (
@@ -83,11 +80,10 @@ const SocialButton = () => { )} {CONTACT_EMAIL && ( + onClick={e => handleEmailClick(e, emailIcon, CONTACT_EMAIL)} + title='email' + className='cursor-pointer' + ref={emailIcon}> )} diff --git a/themes/fukasawa/components/SocialButton.js b/themes/fukasawa/components/SocialButton.js index a2bfa2f8..d8d3c421 100644 --- a/themes/fukasawa/components/SocialButton.js +++ b/themes/fukasawa/components/SocialButton.js @@ -1,6 +1,7 @@ import QrCode from '@/components/QrCode' import { siteConfig } from '@/lib/config' -import { useState } from 'react' +import { useRef, useState } from 'react' +import { handleEmailClick } from '@/lib/plugins/mailEncrypt' /** * 社交联系方式按钮组 @@ -32,6 +33,9 @@ const SocialButton = () => { setQrCodeShow(false) } + const emailIcon = useRef(null) + + return (
@@ -91,10 +95,10 @@ const SocialButton = () => { )} {CONTACT_EMAIL && ( + onClick={e => handleEmailClick(e, emailIcon, CONTACT_EMAIL)} + title='email' + className='cursor-pointer' + ref={emailIcon}> )} diff --git a/themes/gitbook/components/SocialButton.js b/themes/gitbook/components/SocialButton.js index a2bfa2f8..80078ae7 100644 --- a/themes/gitbook/components/SocialButton.js +++ b/themes/gitbook/components/SocialButton.js @@ -1,6 +1,7 @@ import QrCode from '@/components/QrCode' import { siteConfig } from '@/lib/config' import { useState } from 'react' +import { handleEmailClick } from '@/lib/plugins/mailEncrypt' /** * 社交联系方式按钮组 @@ -32,6 +33,9 @@ const SocialButton = () => { setQrCodeShow(false) } + const emailIcon = useRef(null) + + return (
@@ -91,10 +95,10 @@ const SocialButton = () => { )} {CONTACT_EMAIL && ( + onClick={e => handleEmailClick(e, emailIcon, CONTACT_EMAIL)} + title='email' + className='cursor-pointer' + ref={emailIcon}> )} diff --git a/themes/hexo/components/SocialButton.js b/themes/hexo/components/SocialButton.js index 3e220cf7..e7dbf127 100644 --- a/themes/hexo/components/SocialButton.js +++ b/themes/hexo/components/SocialButton.js @@ -1,6 +1,7 @@ import QrCode from '@/components/QrCode' import { siteConfig } from '@/lib/config' -import { useState } from 'react' +import { useRef, useState } from 'react' +import { handleEmailClick } from '@/lib/plugins/mailEncrypt' /** * 社交联系方式按钮组 @@ -32,6 +33,9 @@ const SocialButton = () => { const closePopover = () => { setQrCodeShow(false) } + + const emailIcon = useRef(null) + return (
@@ -91,10 +95,10 @@ const SocialButton = () => { )} {CONTACT_EMAIL && ( + onClick={e => handleEmailClick(e, emailIcon, CONTACT_EMAIL)} + title='email' + className='cursor-pointer' + ref={emailIcon}> )} diff --git a/themes/magzine/components/SocialButton.js b/themes/magzine/components/SocialButton.js index 5b3a3954..aa790cdf 100644 --- a/themes/magzine/components/SocialButton.js +++ b/themes/magzine/components/SocialButton.js @@ -1,6 +1,7 @@ import QrCode from '@/components/QrCode' import { siteConfig } from '@/lib/config' -import { useState } from 'react' +import { useRef, useState } from 'react' +import { handleEmailClick } from '@/lib/plugins/mailEncrypt' /** * 社交联系方式按钮组 @@ -31,6 +32,9 @@ const SocialButton = () => { setQrCodeShow(false) } + const emailIcon = useRef(null) + + return (
@@ -90,10 +94,10 @@ const SocialButton = () => { )} {CONTACT_EMAIL && ( + onClick={e => handleEmailClick(e, emailIcon, CONTACT_EMAIL)} + title='email' + className='cursor-pointer' + ref={emailIcon}> )} diff --git a/themes/matery/components/SocialButton.js b/themes/matery/components/SocialButton.js index 678ad4fd..74e18597 100644 --- a/themes/matery/components/SocialButton.js +++ b/themes/matery/components/SocialButton.js @@ -1,5 +1,6 @@ import { siteConfig } from '@/lib/config' -import { useEffect, useRef, useState } from 'react' +import { useRef, useState } from 'react' +import { handleEmailClick } from '@/lib/plugins/mailEncrypt' /** * 社交联系方式按钮组 可折叠的组件 @@ -24,12 +25,7 @@ const SocialButton = () => { const CONTACT_YOUTUBE = siteConfig('CONTACT_YOUTUBE') const emailIcon = useRef(null) - useEffect(() => { - if (CONTACT_EMAIL && emailIcon.current) { - emailIcon.current.href = - 'mailto:' + decodeURIComponent(escape(atob(CONTACT_EMAIL))) - } - }, [CONTACT_EMAIL]) + return (
@@ -97,11 +93,10 @@ const SocialButton = () => { )} {CONTACT_EMAIL && ( + onClick={e => handleEmailClick(e, emailIcon, CONTACT_EMAIL)} + title='email' + className='cursor-pointer' + ref={emailIcon}> )} diff --git a/themes/medium/components/SocialButton.js b/themes/medium/components/SocialButton.js index 40ae1ca4..66899971 100644 --- a/themes/medium/components/SocialButton.js +++ b/themes/medium/components/SocialButton.js @@ -1,5 +1,6 @@ import { siteConfig } from '@/lib/config' -import { useEffect, useRef } from 'react' +import { useRef } from 'react' +import { handleEmailClick } from '@/lib/plugins/mailEncrypt' /** * 社交联系方式按钮组 @@ -19,12 +20,7 @@ const SocialButton = () => { const CONTACT_YOUTUBE = siteConfig('CONTACT_YOUTUBE') const emailIcon = useRef(null) - useEffect(() => { - if (CONTACT_EMAIL && emailIcon.current) { - emailIcon.current.href = - 'mailto:' + decodeURIComponent(escape(atob(CONTACT_EMAIL))) - } - }, [CONTACT_EMAIL]) + return (
{CONTACT_GITHUB && ( @@ -83,11 +79,10 @@ const SocialButton = () => { )} {CONTACT_EMAIL && ( + onClick={e => handleEmailClick(e, emailIcon, CONTACT_EMAIL)} + title='email' + className='cursor-pointer' + ref={emailIcon}> )} diff --git a/themes/nav/components/SocialButton.js b/themes/nav/components/SocialButton.js index 64aa4cc1..e6992904 100755 --- a/themes/nav/components/SocialButton.js +++ b/themes/nav/components/SocialButton.js @@ -1,5 +1,6 @@ import { siteConfig } from '@/lib/config' -import { useEffect, useRef } from 'react' +import { useRef } from 'react' +import { handleEmailClick } from '@/lib/plugins/mailEncrypt' /** * 社交联系方式按钮组 @@ -17,12 +18,7 @@ const SocialButton = () => { const ENABLE_RSS = siteConfig('ENABLE_RSS') const emailIcon = useRef(null) - useEffect(() => { - if (CONTACT_EMAIL && emailIcon.current) { - emailIcon.current.href = - 'mailto:' + decodeURIComponent(escape(atob(CONTACT_EMAIL))) - } - }, [CONTACT_EMAIL]) + return (
{CONTACT_GITHUB && ( @@ -81,11 +77,10 @@ const SocialButton = () => { )} {CONTACT_EMAIL && ( + onClick={e => handleEmailClick(e, emailIcon, CONTACT_EMAIL)} + title='email' + className='cursor-pointer' + ref={emailIcon}> )} diff --git a/themes/plog/components/SocialButton.js b/themes/plog/components/SocialButton.js index c48909bd..7d6aa1a8 100644 --- a/themes/plog/components/SocialButton.js +++ b/themes/plog/components/SocialButton.js @@ -1,5 +1,6 @@ import { siteConfig } from '@/lib/config' -import { useEffect, useRef } from 'react' +import { useRef } from 'react' +import { handleEmailClick } from '@/lib/plugins/mailEncrypt' /** * 社交联系方式按钮组 @@ -19,12 +20,7 @@ const SocialButton = () => { const CONTACT_YOUTUBE = siteConfig('CONTACT_YOUTUBE') const emailIcon = useRef(null) - useEffect(() => { - if (CONTACT_EMAIL && emailIcon.current) { - emailIcon.current.href = - 'mailto:' + decodeURIComponent(escape(atob(CONTACT_EMAIL))) - } - }, [CONTACT_EMAIL]) + return (
@@ -84,11 +80,10 @@ const SocialButton = () => { )} {CONTACT_EMAIL && ( + onClick={e => handleEmailClick(e, emailIcon, CONTACT_EMAIL)} + title='email' + className='cursor-pointer' + ref={emailIcon}> )} diff --git a/themes/starter/components/SocialButton.js b/themes/starter/components/SocialButton.js index a90d533b..2cac8bf6 100644 --- a/themes/starter/components/SocialButton.js +++ b/themes/starter/components/SocialButton.js @@ -1,5 +1,6 @@ import { siteConfig } from '@/lib/config' -import { useEffect, useRef } from 'react' +import { useRef } from 'react' +import { handleEmailClick } from '@/lib/plugins/mailEncrypt' /** * 社交联系方式按钮组 @@ -19,12 +20,7 @@ const SocialButton = () => { const CONTACT_YOUTUBE = siteConfig('CONTACT_YOUTUBE') const emailIcon = useRef(null) - useEffect(() => { - if (CONTACT_EMAIL && emailIcon.current) { - emailIcon.current.href = - 'mailto:' + decodeURIComponent(escape(atob(CONTACT_EMAIL))) - } - }, [CONTACT_EMAIL]) + return (