mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-13 23:16:47 +00:00
feat(email encrypt): implement base64 encoding for contact email config, only supports HEO theme
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
lib/plugins/mailEncrypt.js
Normal file
12
lib/plugins/mailEncrypt.js
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import { siteConfig } from '@/lib/config'
|
||||
import { useRef } from 'react'
|
||||
import { handleEmailClick } from '@/lib/plugins/mailEncrypt'
|
||||
|
||||
/**
|
||||
* 社交联系方式按钮组
|
||||
@@ -16,6 +18,9 @@ const SocialButton = () => {
|
||||
const ENABLE_RSS = siteConfig('ENABLE_RSS')
|
||||
const CONTACT_BILIBILI = siteConfig('CONTACT_BILIBILI')
|
||||
const CONTACT_YOUTUBE = siteConfig('CONTACT_YOUTUBE')
|
||||
|
||||
const emailIcon = useRef(null)
|
||||
|
||||
return (
|
||||
<div className='w-full justify-center flex-wrap flex'>
|
||||
<div className='space-x-12 text-3xl text-gray-600 dark:text-gray-300 '>
|
||||
@@ -75,10 +80,10 @@ const SocialButton = () => {
|
||||
)}
|
||||
{CONTACT_EMAIL && (
|
||||
<a
|
||||
target='_blank'
|
||||
rel='noreferrer'
|
||||
title={'email'}
|
||||
href={`mailto:${CONTACT_EMAIL}`}>
|
||||
onClick={e => handleEmailClick(e, emailIcon, CONTACT_EMAIL)}
|
||||
title='email'
|
||||
className='cursor-pointer'
|
||||
ref={emailIcon}>
|
||||
<i className='transform hover:scale-125 duration-150 fas fa-envelope dark:hover:text-indigo-400 hover:text-indigo-600' />
|
||||
</a>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user