diff --git a/conf/contact.config.js b/conf/contact.config.js index d2a53274047..2784e3600b1 100644 --- a/conf/contact.config.js +++ b/conf/contact.config.js @@ -3,7 +3,12 @@ */ module.exports = { // 社交链接,不需要可留空白,例如 CONTACT_WEIBO:'' - CONTACT_EMAIL: process.env.NEXT_PUBLIC_CONTACT_EMAIL || '', // 邮箱地址 例如mail@tangly1024.com + CONTACT_EMAIL: + (process.env.NEXT_PUBLIC_CONTACT_EMAIL && + btoa( + unescape(encodeURIComponent(process.env.NEXT_PUBLIC_CONTACT_EMAIL)) + )) || + '', // 邮箱地址 例如mail@tangly1024.com CONTACT_WEIBO: process.env.NEXT_PUBLIC_CONTACT_WEIBO || '', // 你的微博个人主页 CONTACT_TWITTER: process.env.NEXT_PUBLIC_CONTACT_TWITTER || '', // 你的twitter个人主页 CONTACT_GITHUB: process.env.NEXT_PUBLIC_CONTACT_GITHUB || '', // 你的github个人主页 例如 https://github.com/tangly1024 diff --git a/lib/notion/getNotionConfig.js b/lib/notion/getNotionConfig.js index 029c7b96b5d..3e111fcda9a 100644 --- a/lib/notion/getNotionConfig.js +++ b/lib/notion/getNotionConfig.js @@ -157,9 +157,14 @@ export async function getConfigMapFromConfigPage(allPages) { // 只导入生效的配置 if (config.enable) { // console.log('[Notion配置]', config.key, config.value) - notionConfig[config.key] = - parseTextToJson(config.value) || config.value || null - // 配置不能是undefined,至少是null + if (config.key === 'CONTACT_EMAIL') { + notionConfig[config.key] = + (config.value && btoa(unescape(encodeURIComponent(config.value)))) || null + } else { + notionConfig[config.key] = + parseTextToJson(config.value) || config.value || null + // 配置不能是undefined,至少是null + } } } } diff --git a/lib/plugins/mailEncrypt.js b/lib/plugins/mailEncrypt.js new file mode 100644 index 00000000000..091c39b3bb8 --- /dev/null +++ b/lib/plugins/mailEncrypt.js @@ -0,0 +1,12 @@ +export const handleEmailClick = (e, emailIcon, CONTACT_EMAIL) => { + if (CONTACT_EMAIL && emailIcon && !emailIcon.current.href) { + e.preventDefault() + try { + const email = decodeURIComponent(escape(atob(CONTACT_EMAIL))) + emailIcon.current.href = `mailto:${email}` + emailIcon.current.click() + } catch (error) { + console.error('解密邮箱失败:', error) + } + } +} diff --git a/themes/commerce/components/SocialButton.js b/themes/commerce/components/SocialButton.js index 24823924127..adf18d7f790 100644 --- a/themes/commerce/components/SocialButton.js +++ b/themes/commerce/components/SocialButton.js @@ -1,77 +1,93 @@ import { siteConfig } from '@/lib/config' +import { useRef } from 'react' +import { handleEmailClick } from '@/lib/plugins/mailEncrypt' + /** * 社交联系方式按钮组 * @returns {JSX.Element} * @constructor */ const SocialButton = () => { + const CONTACT_GITHUB = siteConfig('CONTACT_GITHUB') + const CONTACT_TWITTER = siteConfig('CONTACT_TWITTER') + const CONTACT_TELEGRAM = siteConfig('CONTACT_TELEGRAM') + const CONTACT_LINKEDIN = siteConfig('CONTACT_LINKEDIN') + const CONTACT_WEIBO = siteConfig('CONTACT_WEIBO') + const CONTACT_INSTAGRAM = siteConfig('CONTACT_INSTAGRAM') + const CONTACT_EMAIL = siteConfig('CONTACT_EMAIL') + const ENABLE_RSS = siteConfig('ENABLE_RSS') + const CONTACT_BILIBILI = siteConfig('CONTACT_BILIBILI') + const CONTACT_YOUTUBE = siteConfig('CONTACT_YOUTUBE') + + const emailIcon = useRef(null) + return (