diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000000..9a5de93f7ec --- /dev/null +++ b/.prettierignore @@ -0,0 +1,43 @@ +# 构建输出 +.next/ +out/ +build/ +dist/ + +# 依赖 +node_modules/ + +# 日志 +logs/ +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# 缓存目录 +.npm +.eslintcache +.vercel + +# 特定项目文件 +public/ +.github/ +lib/plugins/ + +# 包锁文件 +package-lock.json +yarn.lock +pnpm-lock.yaml + +# 静态资源 +*.svg +*.ico +*.jpg +*.jpeg +*.png +*.gif +*.webp +*.pdf +*.ttf +*.woff +*.woff2 \ No newline at end of file diff --git a/.prettierrc.json b/.prettierrc.json index 213aca02dcd..48507ec849e 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -6,5 +6,5 @@ "printWidth": 80, "bracketSpacing": true, "jsxSingleQuote": true, - "jsxBracketSameLine": true + "bracketSameLine": true } diff --git a/blog.config.js b/blog.config.js index a8a972a702f..c563d56b82d 100644 --- a/blog.config.js +++ b/blog.config.js @@ -20,7 +20,8 @@ const BLOG = { KEYWORDS: process.env.NEXT_PUBLIC_KEYWORD || 'Notion, 博客', // 网站关键词 英文逗号隔开 BLOG_FAVICON: process.env.NEXT_PUBLIC_FAVICON || '/favicon.ico', // blog favicon 配置, 默认使用 /public/favicon.ico,支持在线图片,如 https://img.imesong.com/favicon.png BEI_AN: process.env.NEXT_PUBLIC_BEI_AN || '', // 备案号 闽ICP备XXXXXX - BEI_AN_LINK: process.env.NEXT_PUBLIC_BEI_AN_LINK || 'https://beian.miit.gov.cn/', // 备案查询链接,如果用了萌备等备案请在这里填写 + BEI_AN_LINK: + process.env.NEXT_PUBLIC_BEI_AN_LINK || 'https://beian.miit.gov.cn/', // 备案查询链接,如果用了萌备等备案请在这里填写 // RSS订阅 ENABLE_RSS: process.env.NEXT_PUBLIC_ENABLE_RSS || true, // 是否开启RSS订阅功能 diff --git a/components/Ackee.js b/components/Ackee.js index 88618369976..cb84718ef41 100644 --- a/components/Ackee.js +++ b/components/Ackee.js @@ -62,16 +62,18 @@ const handleAckee = async function (pathname, environment, options = {}) { const instance = ackeeTracker?.create(environment.server, options) if (instance == null) { - console.warn('Skipped record creation because useAckee has been called in a non-browser environment') + console.warn( + 'Skipped record creation because useAckee has been called in a non-browser environment' + ) return } - const hasPathname = ( - pathname != null && pathname !== '' - ) + const hasPathname = pathname != null && pathname !== '' if (hasPathname === false) { - console.warn('Skipped record creation because useAckee has been called without pathname') + console.warn( + 'Skipped record creation because useAckee has been called without pathname' + ) return } diff --git a/components/AdBlockDetect.js b/components/AdBlockDetect.js index 00758a08caa..84596fd8408 100644 --- a/components/AdBlockDetect.js +++ b/components/AdBlockDetect.js @@ -14,10 +14,13 @@ export default function AdBlockDetect() { const wwadsCns = document.getElementsByClassName('wwads-cn') if (wwadsCns && wwadsCns.length > 0) { for (const wwadsCn of wwadsCns) { - wwadsCn.insertAdjacentHTML('beforeend', "
为了本站的长期运营,请将我们的网站加入广告拦截器的白名单,感谢您的支持!万维广告
") + wwadsCn.insertAdjacentHTML( + 'beforeend', + "
为了本站的长期运营,请将我们的网站加入广告拦截器的白名单,感谢您的支持!万维广告
" + ) } } - }; + } // check document ready function docReady(t) { diff --git a/components/Artalk.js b/components/Artalk.js index c7ac5441213..40095aed271 100644 --- a/components/Artalk.js +++ b/components/Artalk.js @@ -28,8 +28,8 @@ const Artalk = ({ siteInfo }) => { darkMode: document.documentElement.classList.contains('dark') }) - const observer = new MutationObserver((mutations) => { - mutations.forEach((mutation) => { + const observer = new MutationObserver(mutations => { + mutations.forEach(mutation => { if (mutation.attributeName === 'class') { const isDark = document.documentElement.classList.contains('dark') artalk?.setDarkMode(isDark) @@ -45,7 +45,7 @@ const Artalk = ({ siteInfo }) => { return () => observer.disconnect() } - return
+ return
} export default Artalk diff --git a/components/Badge.js b/components/Badge.js index 9eab49a2787..8fcbe80e8a4 100644 --- a/components/Badge.js +++ b/components/Badge.js @@ -2,10 +2,13 @@ * 红点 */ export default function Badge() { - return <> - {/* 红点 */} - - - - + return ( + <> + {/* 红点 */} + + + + + + ) } diff --git a/components/Busuanzi.js b/components/Busuanzi.js index ebdab36fd56..6a0a9a06bc7 100644 --- a/components/Busuanzi.js +++ b/components/Busuanzi.js @@ -6,7 +6,7 @@ import { useEffect } from 'react' let path = '' -export default function Busuanzi () { +export default function Busuanzi() { const { theme } = useGlobal() const router = useRouter() router.events.on('routeChangeComplete', (url, option) => { diff --git a/components/ChatBase.js b/components/ChatBase.js index b114fdf6a13..679afb04ade 100644 --- a/components/ChatBase.js +++ b/components/ChatBase.js @@ -10,10 +10,11 @@ export default function ChatBase() { return <> } - return + return ( + + ) } diff --git a/components/CursorDot.js b/components/CursorDot.js index 7fb36603c2c..1d01857e68f 100644 --- a/components/CursorDot.js +++ b/components/CursorDot.js @@ -1,107 +1,109 @@ -import { useRouter } from 'next/router'; -import { useEffect } from 'react'; +import { useRouter } from 'next/router' +import { useEffect } from 'react' /** * 白点鼠标跟随 - * @returns + * @returns */ const CursorDot = () => { - const router = useRouter(); - useEffect(() => { - // 创建小白点元素 - const dot = document.createElement('div'); - dot.classList.add('cursor-dot'); - document.body.appendChild(dot); + const router = useRouter() + useEffect(() => { + // 创建小白点元素 + const dot = document.createElement('div') + dot.classList.add('cursor-dot') + document.body.appendChild(dot) - // 鼠标坐标和缓动目标坐标 - let mouse = { x: -100, y: -100 }; // 初始位置在屏幕外 - let dotPos = { x: mouse.x, y: mouse.y }; + // 鼠标坐标和缓动目标坐标 + let mouse = { x: -100, y: -100 } // 初始位置在屏幕外 + let dotPos = { x: mouse.x, y: mouse.y } - // 监听鼠标移动 - const handleMouseMove = (e) => { - mouse.x = e.clientX; - mouse.y = e.clientY; - }; - document.addEventListener('mousemove', handleMouseMove); + // 监听鼠标移动 + const handleMouseMove = e => { + mouse.x = e.clientX + mouse.y = e.clientY + } + document.addEventListener('mousemove', handleMouseMove) - // 监听鼠标悬停在可点击对象上的事件 - const handleMouseEnter = () => { - dot.classList.add('cursor-dot-hover'); // 添加放大样式 - }; - const handleMouseLeave = () => { - dot.classList.remove('cursor-dot-hover'); // 移除放大样式 - }; + // 监听鼠标悬停在可点击对象上的事件 + const handleMouseEnter = () => { + dot.classList.add('cursor-dot-hover') // 添加放大样式 + } + const handleMouseLeave = () => { + dot.classList.remove('cursor-dot-hover') // 移除放大样式 + } + // 为所有可点击元素和包含 hover 或 group-hover 类名的元素添加事件监听 + setTimeout(() => { + const clickableElements = document.querySelectorAll( + 'a, button, [role="button"], [onclick], [cursor="pointer"], [class*="hover"], [class*="group-hover"], [class*="cursor-pointer"]' + ) + clickableElements.forEach(el => { + el.addEventListener('mouseenter', handleMouseEnter) + el.addEventListener('mouseleave', handleMouseLeave) + }) + }, 200) // 延时 200ms 执行 - // 为所有可点击元素和包含 hover 或 group-hover 类名的元素添加事件监听 - setTimeout(() => { - const clickableElements = document.querySelectorAll( - 'a, button, [role="button"], [onclick], [cursor="pointer"], [class*="hover"], [class*="group-hover"], [class*="cursor-pointer"]' - ); - clickableElements.forEach((el) => { - el.addEventListener('mouseenter', handleMouseEnter); - el.addEventListener('mouseleave', handleMouseLeave); - }); - }, 200); // 延时 200ms 执行 + // 动画循环:延迟更新小白点位置 + const updateDotPosition = () => { + const damping = 0.2 // 阻尼系数,值越小延迟越明显 + dotPos.x += (mouse.x - dotPos.x) * damping + dotPos.y += (mouse.y - dotPos.y) * damping - // 动画循环:延迟更新小白点位置 - const updateDotPosition = () => { - const damping = 0.2; // 阻尼系数,值越小延迟越明显 - dotPos.x += (mouse.x - dotPos.x) * damping; - dotPos.y += (mouse.y - dotPos.y) * damping; + // 更新DOM + dot.style.left = `${dotPos.x}px` + dot.style.top = `${dotPos.y}px` - // 更新DOM - dot.style.left = `${dotPos.x}px`; - dot.style.top = `${dotPos.y}px`; + requestAnimationFrame(updateDotPosition) + } - requestAnimationFrame(updateDotPosition); - }; + // 启动动画 + updateDotPosition() - // 启动动画 - updateDotPosition(); + // 清理函数 + return () => { + document.removeEventListener('mousemove', handleMouseMove) + const clickableElements = document.querySelectorAll( + 'a, button, [role="button"], [onclick], [cursor="pointer"], [class*="hover"], [class*="group-hover"], [class*="cursor-pointer"]' + ) + clickableElements.forEach(el => { + el.removeEventListener('mouseenter', handleMouseEnter) + el.removeEventListener('mouseleave', handleMouseLeave) + }) + document.body.removeChild(dot) + } + }, [router]) - // 清理函数 - return () => { - document.removeEventListener('mousemove', handleMouseMove); - const clickableElements = document.querySelectorAll( - 'a, button, [role="button"], [onclick], [cursor="pointer"], [class*="hover"], [class*="group-hover"], [class*="cursor-pointer"]' - ); - clickableElements.forEach((el) => { - el.removeEventListener('mouseenter', handleMouseEnter); - el.removeEventListener('mouseleave', handleMouseLeave); - }); - document.body.removeChild(dot); - }; - }, [router]); + return ( + + ) +} - .dark .cursor-dot-hover { - border: 1px solid rgba(66, 66, 66, 0.66); /* 鼠标悬停时的深灰色边框,厚度为1px */ - } - `} - ); -}; - -export default CursorDot; \ No newline at end of file +export default CursorDot diff --git a/components/CusdisComponent.js b/components/CusdisComponent.js index 148ee0c7d5c..fefe117606d 100644 --- a/components/CusdisComponent.js +++ b/components/CusdisComponent.js @@ -8,8 +8,14 @@ const CusdisComponent = ({ frontMatter }) => { const router = useRouter() const { isDarkMode, lang } = useGlobal() const src = siteConfig('COMMENT_CUSDIS_SCRIPT_SRC') - const i18nForCusdis = siteConfig('LANG').toLowerCase().indexOf('zh') === 0 ? siteConfig('LANG').toLowerCase() : siteConfig('LANG').toLowerCase().substring(0, 2) - const langCDN = siteConfig('COMMENT_CUSDIS_LANG_SRC', `https://cusdis.com/js/widget/lang/${i18nForCusdis}.js`) + const i18nForCusdis = + siteConfig('LANG').toLowerCase().indexOf('zh') === 0 + ? siteConfig('LANG').toLowerCase() + : siteConfig('LANG').toLowerCase().substring(0, 2) + const langCDN = siteConfig( + 'COMMENT_CUSDIS_LANG_SRC', + `https://cusdis.com/js/widget/lang/${i18nForCusdis}.js` + ) // 处理cusdis主题 useEffect(() => { @@ -23,15 +29,17 @@ const CusdisComponent = ({ frontMatter }) => { window?.CUSDIS?.initial() } - return
+ return ( +
+ ) } export default CusdisComponent diff --git a/components/CustomContextMenu.js b/components/CustomContextMenu.js index 19b65395f1d..bd4c6a5c275 100644 --- a/components/CustomContextMenu.js +++ b/components/CustomContextMenu.js @@ -117,13 +117,17 @@ export default function CustomContextMenu(props) { function handleCopy() { const selectedText = document.getSelection().toString() if (selectedText) { - const tempInput = document.createElement('input'); - tempInput.value = selectedText; - document.body.appendChild(tempInput); - tempInput.select(); - document.execCommand('copy'); - if (tempInput && tempInput.parentNode && tempInput.parentNode.contains(tempInput)) { - tempInput.parentNode.removeChild(tempInput); + const tempInput = document.createElement('input') + tempInput.value = selectedText + document.body.appendChild(tempInput) + tempInput.select() + document.execCommand('copy') + if ( + tempInput && + tempInput.parentNode && + tempInput.parentNode.contains(tempInput) + ) { + tempInput.parentNode.removeChild(tempInput) } // alert("Text copied: " + selectedText); } else { diff --git a/components/DifyChatbot.js b/components/DifyChatbot.js index 6190c58bd23..eea1e2d5f25 100644 --- a/components/DifyChatbot.js +++ b/components/DifyChatbot.js @@ -1,34 +1,40 @@ -import { useEffect } from 'react'; -import { siteConfig } from '@/lib/config'; +import { useEffect } from 'react' +import { siteConfig } from '@/lib/config' export default function DifyChatbot() { useEffect(() => { // 这里使用 siteConfig() 函数调用来获取配置值 if (!siteConfig('DIFY_CHATBOT_ENABLED')) { - return; + return } // 配置 DifyChatbot,同样需要调用 siteConfig() 获取相应的配置值 window.difyChatbotConfig = { token: siteConfig('DIFY_CHATBOT_TOKEN'), baseUrl: siteConfig('DIFY_CHATBOT_BASE_URL') - }; + } // 加载 DifyChatbot 脚本 - const script = document.createElement('script'); - script.src = `${siteConfig('DIFY_CHATBOT_BASE_URL')}/embed.min.js`; // 注意调用 siteConfig() - script.id = siteConfig('DIFY_CHATBOT_TOKEN'); // 注意调用 siteConfig() - script.defer = true; - document.body.appendChild(script); + const script = document.createElement('script') + script.src = `${siteConfig('DIFY_CHATBOT_BASE_URL')}/embed.min.js` // 注意调用 siteConfig() + script.id = siteConfig('DIFY_CHATBOT_TOKEN') // 注意调用 siteConfig() + script.defer = true + document.body.appendChild(script) return () => { // 在组件卸载时清理 script 标签 - const existingScript = document.getElementById(siteConfig('DIFY_CHATBOT_TOKEN')); // 注意调用 siteConfig() - if (existingScript && existingScript.parentNode && existingScript.parentNode.contains(existingScript)) { - existingScript.parentNode.removeChild(existingScript); + const existingScript = document.getElementById( + siteConfig('DIFY_CHATBOT_TOKEN') + ) // 注意调用 siteConfig() + if ( + existingScript && + existingScript.parentNode && + existingScript.parentNode.contains(existingScript) + ) { + existingScript.parentNode.removeChild(existingScript) } - }; - }, []); // 注意依赖数组为空,意味着脚本将仅在加载页面时执行一次 + } + }, []) // 注意依赖数组为空,意味着脚本将仅在加载页面时执行一次 - return null; + return null } diff --git a/components/Equation.js b/components/Equation.js index 86685d625f6..a053b857134 100644 --- a/components/Equation.js +++ b/components/Equation.js @@ -13,7 +13,13 @@ const katexSettings = { * @param {} param0 * @returns */ -export const Equation = ({ block, math, inline = false, className, ...rest }) => { +export const Equation = ({ + block, + math, + inline = false, + className, + ...rest +}) => { math = math || getBlockTitle(block, null) if (!math) return null @@ -21,8 +27,7 @@ export const Equation = ({ block, math, inline = false, className, ...rest }) => + className={`notion-equation ${inline ? 'notion-equation-inline' : 'notion-equation-block'}`}> ) diff --git a/components/ExternalPlugins.js b/components/ExternalPlugins.js index fd92820ec81..a881f0668c9 100644 --- a/components/ExternalPlugins.js +++ b/components/ExternalPlugins.js @@ -13,7 +13,6 @@ import WebWhiz from './Webwhiz' import { useGlobal } from '@/lib/global' import IconFont from './IconFont' - /** * 各种插件脚本 * @param {*} props @@ -22,7 +21,7 @@ import IconFont from './IconFont' const ExternalPlugin = props => { // 读取自Notion的配置 const { NOTION_CONFIG } = props - const {lang} = useGlobal() + const { lang } = useGlobal() const DISABLE_PLUGIN = siteConfig('DISABLE_PLUGIN', null, NOTION_CONFIG) const THEME_SWITCH = siteConfig('THEME_SWITCH', null, NOTION_CONFIG) const DEBUG = siteConfig('DEBUG', null, NOTION_CONFIG) @@ -172,7 +171,7 @@ const ExternalPlugin = props => { setTimeout(() => { // 映射url - convertInnerUrl({ allPages:props?.allNavPages, lang:lang }) + convertInnerUrl({ allPages: props?.allNavPages, lang: lang }) }, 500) }, [router]) diff --git a/components/FacebookMessenger.js b/components/FacebookMessenger.js index 9531b322a84..e1c87e0e079 100644 --- a/components/FacebookMessenger.js +++ b/components/FacebookMessenger.js @@ -8,34 +8,38 @@ export default function Messenger() { const language = siteConfig('LANG').replace('-', '_') // 新增一个状态变量用于追踪是否已经滚动过 - const [showMessenger, setShowMessenger] = useState(false); + const [showMessenger, setShowMessenger] = useState(false) const showTheComponent = () => { - window.removeEventListener('scroll', showTheComponent); + window.removeEventListener('scroll', showTheComponent) if (!showMessenger) { - setShowMessenger(true); + setShowMessenger(true) } - }; + } // 延时7秒,或页面滚动时加载该组件 useEffect(() => { - window.addEventListener('scroll', showTheComponent); + window.addEventListener('scroll', showTheComponent) setTimeout(() => { showTheComponent() - }, 7000); + }, 7000) return () => { - window.removeEventListener('scroll', showTheComponent); - }; - }, []); + window.removeEventListener('scroll', showTheComponent) + } + }, []) - return <> - {showMessenger && } + return ( + <> + {showMessenger && ( + + )} + ) } /** @@ -51,8 +55,8 @@ class MessengerCustomerChat extends Component { } /** - * 初始化 - */ + * 初始化 + */ componentDidMount() { this.setFbAsyncInit() this.reloadSDKAsynchronously() @@ -61,19 +65,19 @@ class MessengerCustomerChat extends Component { componentDidUpdate(prevProps) { if ( prevProps.pageId !== this.props.pageId || - prevProps.appId !== this.props.appId || - prevProps.shouldShowDialog !== this.props.shouldShowDialog || - prevProps.htmlRef !== this.props.htmlRef || - prevProps.minimized !== this.props.minimized || - prevProps.themeColor !== this.props.themeColor || - prevProps.loggedInGreeting !== this.props.loggedInGreeting || - prevProps.loggedOutGreeting !== this.props.loggedOutGreeting || - prevProps.greetingDialogDisplay !== this.props.greetingDialogDisplay || - prevProps.greetingDialogDelay !== this.props.greetingDialogDelay || - prevProps.autoLogAppEvents !== this.props.autoLogAppEvents || - prevProps.xfbml !== this.props.xfbml || - prevProps.version !== this.props.version || - prevProps.language !== this.props.language + prevProps.appId !== this.props.appId || + prevProps.shouldShowDialog !== this.props.shouldShowDialog || + prevProps.htmlRef !== this.props.htmlRef || + prevProps.minimized !== this.props.minimized || + prevProps.themeColor !== this.props.themeColor || + prevProps.loggedInGreeting !== this.props.loggedInGreeting || + prevProps.loggedOutGreeting !== this.props.loggedOutGreeting || + prevProps.greetingDialogDisplay !== this.props.greetingDialogDisplay || + prevProps.greetingDialogDelay !== this.props.greetingDialogDelay || + prevProps.autoLogAppEvents !== this.props.autoLogAppEvents || + prevProps.xfbml !== this.props.xfbml || + prevProps.version !== this.props.version || + prevProps.language !== this.props.language ) { this.setFbAsyncInit() this.reloadSDKAsynchronously() @@ -87,8 +91,8 @@ class MessengerCustomerChat extends Component { } /** - * 初始化 - */ + * 初始化 + */ setFbAsyncInit() { const { appId, autoLogAppEvents, xfbml, version } = this.props @@ -105,24 +109,24 @@ class MessengerCustomerChat extends Component { } loadSDKAsynchronously() { - const { language } = this.props; + const { language } = this.props /* eslint-disable */ - (function (d, s, id) { - var js, - fjs = d.getElementsByTagName(s)[0]; - if (d.getElementById(id)) { - return; - } - js = d.createElement(s); - js.id = id; - js.src = `https://connect.facebook.net/${language}/sdk/xfbml.customerchat.js`; - if (fjs && fjs.parentNode && fjs.parentNode.contains(fjs)) { - fjs.parentNode.insertBefore(js, fjs); - } else { - document.body.appendChild(js); - } - })(document, 'script', 'facebook-jssdk'); - /* eslint-enable */ + ;(function (d, s, id) { + var js, + fjs = d.getElementsByTagName(s)[0] + if (d.getElementById(id)) { + return + } + js = d.createElement(s) + js.id = id + js.src = `https://connect.facebook.net/${language}/sdk/xfbml.customerchat.js` + if (fjs && fjs.parentNode && fjs.parentNode.contains(fjs)) { + fjs.parentNode.insertBefore(js, fjs) + } else { + document.body.appendChild(js) + } + })(document, 'script', 'facebook-jssdk') + /* eslint-enable */ } removeFacebookSDK() { @@ -178,25 +182,25 @@ class MessengerCustomerChat extends Component { const refAttribute = htmlRef !== undefined ? `ref="${htmlRef}"` : '' const minimizedAttribute = - minimized !== undefined ? `minimized="${minimized}"` : '' + minimized !== undefined ? `minimized="${minimized}"` : '' const themeColorAttribute = - themeColor !== undefined ? `theme_color="${themeColor}"` : '' + themeColor !== undefined ? `theme_color="${themeColor}"` : '' const loggedInGreetingAttribute = - loggedInGreeting !== undefined - ? `logged_in_greeting="${loggedInGreeting}"` - : '' + loggedInGreeting !== undefined + ? `logged_in_greeting="${loggedInGreeting}"` + : '' const loggedOutGreetingAttribute = - loggedOutGreeting !== undefined - ? `logged_out_greeting="${loggedOutGreeting}"` - : '' + loggedOutGreeting !== undefined + ? `logged_out_greeting="${loggedOutGreeting}"` + : '' const greetingDialogDisplayAttribute = - greetingDialogDisplay !== undefined - ? `greeting_dialog_display="${greetingDialogDisplay}"` - : '' + greetingDialogDisplay !== undefined + ? `greeting_dialog_display="${greetingDialogDisplay}"` + : '' const greetingDialogDelayAttribute = - greetingDialogDelay !== undefined - ? `greeting_dialog_delay="${greetingDialogDelay}"` - : '' + greetingDialogDelay !== undefined + ? `greeting_dialog_delay="${greetingDialogDelay}"` + : '' return { __html: `
{ + event => { const element = event.target if ( element.className && - typeof element.className === 'string' && - element.className.includes('fb_dialog') + typeof element.className === 'string' && + element.className.includes('fb_dialog') ) { this.controlPlugin() } @@ -239,8 +243,8 @@ class MessengerCustomerChat extends Component { } } -const removeElementByIds = (ids) => { - ids.forEach((id) => { +const removeElementByIds = ids => { + ids.forEach(id => { const element = document.getElementById(id) if (element && element.parentNode) { element.parentNode.removeChild(element) diff --git a/components/FacebookPage.js b/components/FacebookPage.js index a869c1e5b8f..1dd2c35110f 100644 --- a/components/FacebookPage.js +++ b/components/FacebookPage.js @@ -10,25 +10,31 @@ const FacebookPage = () => { if (!siteConfig('FACEBOOK_APP_ID') || !siteConfig('FACEBOOK_PAGE')) { return <> } - return
- {siteConfig('FACEBOOK_PAGE') && ( -
- - - - - {siteConfig('FACEBOOK_PAGE_TITLE')} - -
- )} - {siteConfig('FACEBOOK_APP_ID') && - - } -
+ return ( +
+ {siteConfig('FACEBOOK_PAGE') && ( +
+ + + + + {siteConfig('FACEBOOK_PAGE_TITLE')} + +
+ )} + {siteConfig('FACEBOOK_APP_ID') && ( + + + + )} +
+ ) } export default FacebookPage diff --git a/components/FlipCard.js b/components/FlipCard.js index 13f81f24155..b4f115c24b5 100644 --- a/components/FlipCard.js +++ b/components/FlipCard.js @@ -13,44 +13,48 @@ export default function FlipCard(props) { } return ( -
-
- {props.frontContent} -
-
- {props.backContent} -
- -
+
+
+ {props.frontContent} +
+
+ {props.backContent} +
+ +
) } diff --git a/components/FullScreenButton.js b/components/FullScreenButton.js index 6c7ec2e41dd..9443b6a3421 100644 --- a/components/FullScreenButton.js +++ b/components/FullScreenButton.js @@ -39,9 +39,9 @@ const FullScreenButton = () => { } return ( - + ) } diff --git a/components/Gitalk.js b/components/Gitalk.js index b60d0cd0d4c..88495a0c20c 100644 --- a/components/Gitalk.js +++ b/components/Gitalk.js @@ -17,7 +17,7 @@ const Gitalk = ({ frontMatter }) => { const admin = siteConfig('COMMENT_GITALK_ADMIN').split(',') const distractionFreeMode = siteConfig('COMMENT_GITALK_DISTRACTION_FREE_MODE') - const loadGitalk = async() => { + const loadGitalk = async () => { await loadExternalResource(gitalkCSSCDN, 'css') await loadExternalResource(gitalkJSCDN, 'js') const Gitalk = window.Gitalk @@ -43,7 +43,7 @@ const Gitalk = ({ frontMatter }) => { loadGitalk() }, []) - return
+ return
} export default Gitalk diff --git a/components/GlobalStyle.js b/components/GlobalStyle.js index 2bb807462ff..4d989252267 100644 --- a/components/GlobalStyle.js +++ b/components/GlobalStyle.js @@ -10,11 +10,11 @@ import { siteConfig } from '@/lib/config' const GlobalStyle = () => { // 从NotionConfig中读取样式 const GLOBAL_CSS = siteConfig('GLOBAL_CSS') - return () + return ( + + ) } export { GlobalStyle } diff --git a/components/HeroIcons.js b/components/HeroIcons.js index caea96104aa..cdfeb325a09 100644 --- a/components/HeroIcons.js +++ b/components/HeroIcons.js @@ -4,97 +4,283 @@ */ export const Moon = () => { - return - + return ( + + + ) } export const Sun = () => { - return - + return ( + + + ) } export const Home = ({ className }) => { - return - + return ( + + + ) } export const User = ({ className }) => { - return - + return ( + + + ) } export const ArrowPath = ({ className }) => { - return - + return ( + + + ) } export const ChevronLeft = ({ className }) => { - return - + return ( + + + ) } export const ChevronRight = ({ className }) => { - return - + return ( + + + ) } export const ChevronDoubleLeft = ({ className }) => { - return - - + return ( + + + + ) } export const ChevronDoubleRight = ({ className }) => { - return - - + return ( + + + + ) } export const InformationCircle = ({ className }) => { - return - + return ( + + + ) } export const HashTag = ({ className }) => { - return - + return ( + + + ) } export const GlobeAlt = ({ className }) => { - return - + return ( + + + ) } export const ArrowRightCircle = ({ className }) => { - return - - + return ( + + + + ) } export const PlusSmall = ({ className }) => { - return - - + return ( + + + + ) } export const ArrowSmallRight = ({ className }) => { - return - - + return ( + + + + ) } export const ArrowSmallUp = ({ className }) => { - return - - + return ( + + + + ) } diff --git a/components/IconFont.js b/components/IconFont.js index 72b8349b40f..d71d8368fd7 100644 --- a/components/IconFont.js +++ b/components/IconFont.js @@ -7,50 +7,65 @@ import { useEffect } from 'react' * iconfont */ export default function IconFont() { - const router = useRouter() + const router = useRouter() - useEffect(() => { - loadExternalResource('/webfonts/iconfont.js') - .then(u => { - console.log('iconfont loaded:', u); + useEffect(() => { + loadExternalResource('/webfonts/iconfont.js') + .then(u => { + console.log('iconfont loaded:', u) - // 查找所有 标签且 class 包含 'icon-' - const iElements = document.querySelectorAll('i[class*="icon-"]'); - iElements.forEach(element => { - const className = Array.from(element.classList).find(cls => cls.startsWith('icon-')); - if (className) { - // 创建新的 元素 - const svgElement = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); - svgElement.setAttribute('class', 'icon'); - svgElement.setAttribute('aria-hidden', 'true'); + // 查找所有 标签且 class 包含 'icon-' + const iElements = document.querySelectorAll('i[class*="icon-"]') + iElements.forEach(element => { + const className = Array.from(element.classList).find(cls => + cls.startsWith('icon-') + ) + if (className) { + // 创建新的 元素 + const svgElement = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'svg' + ) + svgElement.setAttribute('class', 'icon') + svgElement.setAttribute('aria-hidden', 'true') - const useElement = document.createElementNS('http://www.w3.org/2000/svg', 'use'); - useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', `#${className}`); - svgElement.appendChild(useElement); + const useElement = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'use' + ) + useElement.setAttributeNS( + 'http://www.w3.org/1999/xlink', + 'xlink:href', + `#${className}` + ) + svgElement.appendChild(useElement) - // 替换原来的 元素 - element.replaceWith(svgElement); - // console.log(`Replaced with class "${className}" to `); - } - }); - }) - .catch(error => { - console.warn('Failed to load iconfont.js:', error); - }); - }, [router]); + // 替换原来的 元素 + element.replaceWith(svgElement) + // console.log(`Replaced with class "${className}" to `); + } + }) + }) + .catch(error => { + console.warn('Failed to load iconfont.js:', error) + }) + }, [router]) - return + ) } diff --git a/components/KatexReact.js b/components/KatexReact.js index 9adc887098b..ceba897429f 100644 --- a/components/KatexReact.js +++ b/components/KatexReact.js @@ -17,7 +17,7 @@ const TeX = ({ ...props }) => { const Component = asComponent || (block ? 'div' : 'span') - const content = (children ?? math) + const content = children ?? math const [state, setState] = useState({ innerHtml: '' }) useEffect(() => { diff --git a/components/LA51.js b/components/LA51.js index df5066666df..dc5748786df 100644 --- a/components/LA51.js +++ b/components/LA51.js @@ -10,7 +10,12 @@ export default function LA51() { useEffect(() => { const LA = window.LA if (LA) { - LA.init({ id: `${ANALYTICS_51LA_ID}`, ck: `${ANALYTICS_51LA_CK}`, hashMode: true, autoTrack: true }) + LA.init({ + id: `${ANALYTICS_51LA_ID}`, + ck: `${ANALYTICS_51LA_CK}`, + hashMode: true, + autoTrack: true + }) } }, []) diff --git a/components/Lenis.js b/components/Lenis.js index 43b1c062738..854a21e4598 100644 --- a/components/Lenis.js +++ b/components/Lenis.js @@ -23,14 +23,14 @@ const Lenis = () => { // 创建 Lenis 实例 const lenis = new Lenis({ duration: 1.2, - easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // https://www.desmos.com/calculator/brs54l4xou + easing: t => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // https://www.desmos.com/calculator/brs54l4xou direction: 'vertical', // vertical, horizontal gestureDirection: 'vertical', // vertical, horizontal, both smooth: true, mouseMultiplier: 1, smoothTouch: false, touchMultiplier: 2, - infinite: false, + infinite: false }) // 存储实例到 ref diff --git a/components/Loading.js b/components/Loading.js index 2207eb9144f..a224271ae4e 100644 --- a/components/Loading.js +++ b/components/Loading.js @@ -1,13 +1,19 @@ - /** * 异步文件加载时的占位符 * @returns */ -const Loading = (props) => { - return
-
-
+const Loading = props => { + return ( +
+
+
+ {' '} +
+
+ ) } export default Loading diff --git a/components/Mark.js b/components/Mark.js index ec2a7901f70..0f49c61cf9b 100644 --- a/components/Mark.js +++ b/components/Mark.js @@ -9,7 +9,10 @@ export default async function replaceSearchResult({ doms, search, target }) { } try { - await loadExternalResource('https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js', 'js') + await loadExternalResource( + 'https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js', + 'js' + ) const Mark = window.Mark if (doms instanceof HTMLCollection) { for (const container of doms) { diff --git a/components/NotionIcon.js b/components/NotionIcon.js index e60b064008e..027058648aa 100644 --- a/components/NotionIcon.js +++ b/components/NotionIcon.js @@ -11,7 +11,7 @@ const NotionIcon = ({ icon }) => { } if (icon.startsWith('http') || icon.startsWith('data:')) { - return + return } return {icon} diff --git a/components/OpenWrite.js b/components/OpenWrite.js index 8866ff61641..002970407b0 100644 --- a/components/OpenWrite.js +++ b/components/OpenWrite.js @@ -75,7 +75,7 @@ const OpenWrite = () => { useEffect(() => { const isInYellowList = isPathInList(router.asPath, yellowList) const isInWhiteList = isPathInList(router.asPath, whiteList) - + // 优先判断黄名单 if (yellowList && yellowList.length > 0) { if (!isInYellowList) { @@ -87,22 +87,22 @@ const OpenWrite = () => { console.log('当前路径在白名单中,放行') return } - + if (isSignedIn) { // 用户已登录免检 console.log('用户已登录,放行') return } - + if (process.env.NODE_ENV === 'development') { // 开发环境免检 console.log('开发环境:屏蔽OpenWrite') return } - + if (isBrowser && blogId && !isSignedIn) { toggleTocItems(true) // 禁止目录项的点击 - + // 检查是否已加载 const readMoreWrap = document.getElementById('read-more-wrap') if (!readMoreWrap) { diff --git a/components/PWA.js b/components/PWA.js index 2a2921002b1..cdeead957e9 100644 --- a/components/PWA.js +++ b/components/PWA.js @@ -34,7 +34,11 @@ export function PWA(post, siteInfo) { // 删除已有的 manifest link 元素(如果存在) const existingManifest = document.querySelector('link[rel="manifest"]') - if (existingManifest && existingManifest.parentNode && existingManifest.parentNode.contains(existingManifest)) { + if ( + existingManifest && + existingManifest.parentNode && + existingManifest.parentNode.contains(existingManifest) + ) { existingManifest.parentNode.removeChild(existingManifest) } diff --git a/components/PrismMac.js b/components/PrismMac.js index 7e81fc01074..3d20925901a 100644 --- a/components/PrismMac.js +++ b/components/PrismMac.js @@ -160,7 +160,7 @@ const renderCollapseCode = (codeCollapse, codeCollapseExpandDefault) => { /** * 将mermaid语言 渲染成图片 */ -const renderMermaid = async(mermaidCDN) => { +const renderMermaid = async mermaidCDN => { const observer = new MutationObserver(async mutationsList => { for (const m of mutationsList) { if (m.target.className === 'notion-code language-mermaid') { diff --git a/components/Sakura.js b/components/Sakura.js index e60b38c0200..9064d29d8b7 100644 --- a/components/Sakura.js +++ b/components/Sakura.js @@ -5,11 +5,11 @@ import { loadExternalResource } from '@/lib/utils' const Sakura = () => { useEffect(() => { loadExternalResource('/js/sakura.js', 'js').then(url => { - window.createSakura && window.createSakura({}) + window.createSakura && window.createSakura({}) }) return () => window.destroySakura && window.destroySakura() }, []) return <> } -export default Sakura \ No newline at end of file +export default Sakura diff --git a/components/Select.js b/components/Select.js index 3ab8cb73fc0..167d0872082 100644 --- a/components/Select.js +++ b/components/Select.js @@ -4,21 +4,24 @@ import React from 'react' * 下拉单选框 */ class Select extends React.Component { - constructor (props) { + constructor(props) { super(props) this.handleChange = this.handleChange.bind(this) } - handleChange (event) { + handleChange(event) { const { onChange } = this.props onChange(event.target.value) } - render () { + render() { return (
- {this.props.options?.map(o => (
- ); -}; + ) +} -export default Tabs; +export default Tabs diff --git a/components/TianliGPT.js b/components/TianliGPT.js index 07aa2db61d7..3fa1afb07e4 100644 --- a/components/TianliGPT.js +++ b/components/TianliGPT.js @@ -30,8 +30,8 @@ const TianLiGPT = () => { } await loadExternalResource(tianliCss, 'css') - window.tianliGPT_postSelector = '#notion-article'; - window.tianliGPT_key = tianliKey; + window.tianliGPT_postSelector = '#notion-article' + window.tianliGPT_key = tianliKey await loadExternalResource(tianliJs, 'js') } diff --git a/components/Twikoo.js b/components/Twikoo.js index 3d3a08ff9fc..2a713346fd1 100644 --- a/components/Twikoo.js +++ b/components/Twikoo.js @@ -51,7 +51,7 @@ const Twikoo = ({ isDarkMode }) => { }, 1000) return () => clearInterval(interval) }, [isDarkMode]) - return
+ return
} export default Twikoo diff --git a/components/TwikooCommentCount.js b/components/TwikooCommentCount.js index 29408d21c1d..b70ba9a7785 100644 --- a/components/TwikooCommentCount.js +++ b/components/TwikooCommentCount.js @@ -11,12 +11,16 @@ const TwikooCommentCount = ({ post, className }) => { if (!JSON.parse(siteConfig('COMMENT_TWIKOO_COUNT_ENABLE'))) { return null } - return + ) } export default TwikooCommentCount diff --git a/components/TwikooCommentCounter.js b/components/TwikooCommentCounter.js index 7e2a15df5a1..a5064b7f05c 100644 --- a/components/TwikooCommentCounter.js +++ b/components/TwikooCommentCounter.js @@ -10,7 +10,7 @@ import { useEffect } from 'react' * @constructor */ -const TwikooCommentCounter = (props) => { +const TwikooCommentCounter = props => { let commentsData = [] const { theme } = useGlobal() const router = useRouter() @@ -35,25 +35,28 @@ const TwikooCommentCounter = (props) => { * 加载外部twikoojs * @param {*} posts */ - const fetchTwikooData = async (posts) => { + const fetchTwikooData = async posts => { posts.forEach(post => { post.slug = post.slug.startsWith('/') ? post.slug : `/${post.slug}` }) try { await loadExternalResource(twikooCDNURL, 'js') const twikoo = window.twikoo - twikoo.getCommentsCount({ - envId: twikooENVID, // 环境 ID - // region: 'ap-guangzhou', // 环境地域,默认为 ap-shanghai,如果您的环境地域不是上海,需传此参数 - urls: posts?.map(post => post.slug), // 不包含协议、域名、参数的文章路径列表,必传参数 - includeReply: true // 评论数是否包括回复,默认:false - }).then(function (res) { - commentsData = res - updateCommentCount() - }).catch(function (err) { - // 发生错误 - console.error(err) - }) + twikoo + .getCommentsCount({ + envId: twikooENVID, // 环境 ID + // region: 'ap-guangzhou', // 环境地域,默认为 ap-shanghai,如果您的环境地域不是上海,需传此参数 + urls: posts?.map(post => post.slug), // 不包含协议、域名、参数的文章路径列表,必传参数 + includeReply: true // 评论数是否包括回复,默认:false + }) + .then(function (res) { + commentsData = res + updateCommentCount() + }) + .catch(function (err) { + // 发生错误 + console.error(err) + }) } catch (error) { console.error('twikoo 加载失败', error) } @@ -67,12 +70,16 @@ const TwikooCommentCounter = (props) => { const matchingRes = commentsData.find(r => r.url === post.slug) if (matchingRes) { // 修改评论数量div - const textElements = document.querySelectorAll(`.comment-count-text-${post.id}`) + const textElements = document.querySelectorAll( + `.comment-count-text-${post.id}` + ) textElements.forEach(element => { element.innerHTML = matchingRes.count }) // 取消隐藏 - const wrapperElements = document.querySelectorAll(`.comment-count-wrapper-${post.id}`) + const wrapperElements = document.querySelectorAll( + `.comment-count-wrapper-${post.id}` + ) wrapperElements.forEach(element => { element.classList.remove('hidden') }) diff --git a/components/TwikooRecentComments.js b/components/TwikooRecentComments.js index 306b17a2539..834a618bdd5 100644 --- a/components/TwikooRecentComments.js +++ b/components/TwikooRecentComments.js @@ -1,11 +1,10 @@ - /** * 显示最近评论 TODO * @returns {JSX.Element} * @constructor */ -const TwikooRecentComments = (props) => { +const TwikooRecentComments = props => { return null } diff --git a/components/Utterances.js b/components/Utterances.js index 15ceb97a14d..52b16d6a057 100644 --- a/components/Utterances.js +++ b/components/Utterances.js @@ -12,49 +12,52 @@ import { useGlobal } from '@/lib/global' const Utterances = ({ issueTerm, layout }) => { const { isDarkMode } = useGlobal() - const [isLoading, setLoading] = useState(true); + const [isLoading, setLoading] = useState(true) useEffect(() => { - const anchor = document.getElementById('comments'); + const anchor = document.getElementById('comments') if (!anchor) { return } - const script = document.createElement('script'); - script.onload = () => setLoading(false); - script.setAttribute('src', 'https://utteranc.es/client.js'); - script.setAttribute('crossorigin', 'anonymous'); - script.setAttribute('async', true); - script.setAttribute('repo', siteConfig('COMMENT_UTTERRANCES_REPO')); - script.setAttribute('issue-term', 'title'); + const script = document.createElement('script') + script.onload = () => setLoading(false) + script.setAttribute('src', 'https://utteranc.es/client.js') + script.setAttribute('crossorigin', 'anonymous') + script.setAttribute('async', true) + script.setAttribute('repo', siteConfig('COMMENT_UTTERRANCES_REPO')) + script.setAttribute('issue-term', 'title') // 初始主题 - script.setAttribute('theme', isDarkMode ? 'github-dark' : 'github-light'); - anchor?.appendChild(script); + script.setAttribute('theme', isDarkMode ? 'github-dark' : 'github-light') + anchor?.appendChild(script) return () => { // anchor.innerHTML = '' - }; - }, []); + } + }, []) useEffect(() => { // 直接设置 iframe 的类来改变主题,不重新加载脚本 - const iframe = document.querySelector('iframe.utterances-frame'); + const iframe = document.querySelector('iframe.utterances-frame') if (iframe) { - iframe.contentWindow.postMessage({ - type: 'set-theme', - theme: isDarkMode ? 'github-dark' : 'github-light' - }, 'https://utteranc.es'); + iframe.contentWindow.postMessage( + { + type: 'set-theme', + theme: isDarkMode ? 'github-dark' : 'github-light' + }, + 'https://utteranc.es' + ) } - }, [isDarkMode]); + }, [isDarkMode]) return ( -
+
{isLoading && ( -
-
+
+
)}
- ); + ) } export default Utterances diff --git a/components/VConsole.js b/components/VConsole.js index 158c68da755..5e1341efcb1 100644 --- a/components/VConsole.js +++ b/components/VConsole.js @@ -8,15 +8,17 @@ const VConsole = () => { const loadVConsole = async () => { try { - const url = await loadExternalResource('https://cdn.bootcss.com/vConsole/3.3.4/vconsole.min.js', 'js') + const url = await loadExternalResource( + 'https://cdn.bootcss.com/vConsole/3.3.4/vconsole.min.js', + 'js' + ) if (!url) { return } const VConsole = window.VConsole const vConsole = new VConsole() return vConsole - } catch (error) { - } + } catch (error) {} } useEffect(() => { @@ -26,15 +28,21 @@ const VConsole = () => { const centerX = window.innerWidth / 2 const centerY = window.innerHeight / 2 const range = 50 - const inRange = (event.clientX >= centerX - range && event.clientX <= centerX + range) && - (event.clientY >= centerY - range && event.clientY <= centerY + range) + const inRange = + event.clientX >= centerX - range && + event.clientX <= centerX + range && + event.clientY >= centerY - range && + event.clientY <= centerY + range if (!inRange) { return } // 如果在1秒内连续点击了8次 - if (now - lastClickTimeRef.current < 1000 && clickCountRef.current + 1 === 8) { + if ( + now - lastClickTimeRef.current < 1000 && + clickCountRef.current + 1 === 8 + ) { loadVConsole() clickCountRef.current = 0 // 重置计数器 clearTimeout(timerRef.current) // 清除定时器 diff --git a/components/ValineComponent.js b/components/ValineComponent.js index b26fb34d3af..aa5778dda7b 100644 --- a/components/ValineComponent.js +++ b/components/ValineComponent.js @@ -29,7 +29,7 @@ const ValineComponent = ({ path }) => { loadValine() }, []) - return
+ return
// const updateValine = url => { // // 移除旧的评论区,否则会重复渲染。 @@ -51,9 +51,9 @@ const ValineComponent = ({ path }) => { // } // }, []) -// return
-//
-//
+ // return
+ //
+ //
} export default ValineComponent diff --git a/components/Vercel.js b/components/Vercel.js index c7013fe17a2..a43e5c16895 100644 --- a/components/Vercel.js +++ b/components/Vercel.js @@ -1,37 +1,35 @@ const Vercel = () => { return ( + href='https://vercel.com?utm_source=Craigary&utm_campaign=oss' + target='_blank' + rel='noreferrer' + aria-label='Vercel'> - + width='135' + height='28' + viewBox='0 0 135 28' + fill='none' + xmlns='http://www.w3.org/2000/svg' + className='inline-block'> + - + - - + + diff --git a/components/WalineComponent.js b/components/WalineComponent.js index 960f153fee1..edf8b09a66a 100644 --- a/components/WalineComponent.js +++ b/components/WalineComponent.js @@ -1,4 +1,4 @@ -import { createRef, useEffect } from 'react' +import { createRef, useEffect } from 'react' import { init } from '@waline/client' import { useRouter } from 'next/router' import '@waline/client/dist/waline.css' @@ -11,7 +11,7 @@ let waline = null * @param {*} props * @returns */ -const WalineComponent = (props) => { +const WalineComponent = props => { const containerRef = createRef() const router = useRouter() @@ -46,7 +46,7 @@ const WalineComponent = (props) => { const targetNode = document.getElementsByClassName('wl-cards')[0] // 当观察到变动时执行的回调函数 - const mutationCallback = (mutations) => { + const mutationCallback = mutations => { for (const mutation of mutations) { const type = mutation.type if (type === 'childList') { diff --git a/components/WebMention.js b/components/WebMention.js index 61e11c6900d..67dfcffcd64 100644 --- a/components/WebMention.js +++ b/components/WebMention.js @@ -21,9 +21,11 @@ const WebmentionCount = ({ target }) => { } } const [counts, setCounts] = useState(initialCounts) - const fetchCounts = async (target) => { - const responseData = await fetch(`https://webmention.io/api/count.json?target=${encodeURIComponent(target)}`) - return (responseData.json) ? await responseData.json() : responseData + const fetchCounts = async target => { + const responseData = await fetch( + `https://webmention.io/api/count.json?target=${encodeURIComponent(target)}` + ) + return responseData.json ? await responseData.json() : responseData } useEffect(() => { async function getCounts() { @@ -35,27 +37,24 @@ const WebmentionCount = ({ target }) => { return (
- {counts - ? ( -
- - {counts.type.like || 0}Likes + {counts ? ( +
+ + {counts.type.like || 0}Likes + + + {counts.type.reply || 0}Replies + + + + {(counts.type.repost || 0) + (counts.type.mention || 0)} - - {counts.type.reply || 0}Replies - - - - {(counts.type.repost || 0) + (counts.type.mention || 0)} - - Mentions - -
- ) - : ( -

Failed to fetch Webmention counts

- ) - } + Mentions +
+
+ ) : ( +

Failed to fetch Webmention counts

+ )}
) } @@ -63,23 +62,23 @@ const WebmentionCount = ({ target }) => { const Avatar = ({ author }) => (
{author.name} ) const WebmentionReplies = ({ target }) => { const [mentions, setMentions] = useState([]) - const fetchMentions = async (target) => + const fetchMentions = async target => fetch( `https://webmention.io/api/mentions.jf2?per-page=500&target=${encodeURIComponent(target)}&token=${siteConfig('COMMENT_WEBMENTION_TOKEN')}` - ).then((response) => (response.json ? response.json() : response)) + ).then(response => (response.json ? response.json() : response)) useEffect(() => { async function getMentions() { const responseMentions = await fetchMentions(target) @@ -92,11 +91,11 @@ const WebmentionReplies = ({ target }) => { }, [target]) const distinctMentions = [ - ...new Map(mentions.map((item) => [item.author.url, item])).values() + ...new Map(mentions.map(item => [item.author.url, item])).values() ].sort((a, b) => new Date(a['wm-received']) - new Date(b['wm-received'])) const replies = mentions.filter( - (mention) => 'in-reply-to' in mention && 'content' in mention + mention => 'in-reply-to' in mention && 'content' in mention ) return ( @@ -107,30 +106,28 @@ const WebmentionReplies = ({ target }) => { : 'Be the first one to share this article!'}

- {distinctMentions.map((reply) => ( + {distinctMentions.map(reply => ( ))}
- {replies && replies.length - ? ( -
-

Replies

-
    - {replies.map((reply) => ( -
  • -
    - -
    -
    -

    {reply.author.name}

    -

    {reply.content.text}

    -
    -
  • - ))} -
-
- ) - : null} + {replies && replies.length ? ( +
+

Replies

+
    + {replies.map(reply => ( +
  • +
    + +
    +
    +

    {reply.author.name}

    +

    {reply.content.text}

    +
    +
  • + ))} +
+
+ ) : null}
) } @@ -143,23 +140,28 @@ const WebMentionBlock = ({ frontMatter }) => { return (

- powered by WebMention.io + powered by{' '} + + WebMention.io +

You can{' '} tweet this post{' '} + rel='noopener noreferrer'> + tweet this post + {' '} or{' '} discuss it on Twitter + rel='noopener noreferrer'> + discuss it on Twitter + , the comments will show up here.
diff --git a/components/Webwhiz.js b/components/Webwhiz.js index 4a736647b74..1fbe2a67a96 100644 --- a/components/Webwhiz.js +++ b/components/Webwhiz.js @@ -13,5 +13,5 @@ export default function WebWhiz() { baseUrl: siteConfig('WEB_WHIZ_BASE_URL'), chatbotId: siteConfig('WEB_WHIZ_CHAT_BOT_ID') } - return + return } diff --git a/components/WordCount.js b/components/WordCount.js index af808251136..4febaa6fa4d 100644 --- a/components/WordCount.js +++ b/components/WordCount.js @@ -20,4 +20,4 @@ export default function WordCount({ wordCount, readTime }) { ) -} \ No newline at end of file +} diff --git a/hooks/useAdjustStyle.js b/hooks/useAdjustStyle.js index db9978baa60..2622175d29a 100644 --- a/hooks/useAdjustStyle.js +++ b/hooks/useAdjustStyle.js @@ -1,5 +1,5 @@ -import { isBrowser } from '@/lib/utils'; -import { useEffect } from 'react'; +import { isBrowser } from '@/lib/utils' +import { useEffect } from 'react' /** * 样式调整的补丁 @@ -9,28 +9,30 @@ const useAdjustStyle = () => { * 避免 callout 含有图片时溢出撑开父容器 */ const adjustCalloutImg = () => { - const callOuts = document.querySelectorAll('.notion-callout-text'); - callOuts.forEach((callout) => { - const images = callout.querySelectorAll('figure.notion-asset-wrapper.notion-asset-wrapper-image > div'); - const calloutWidth = callout.offsetWidth; - images.forEach((container) => { - const imageWidth = container.offsetWidth; + const callOuts = document.querySelectorAll('.notion-callout-text') + callOuts.forEach(callout => { + const images = callout.querySelectorAll( + 'figure.notion-asset-wrapper.notion-asset-wrapper-image > div' + ) + const calloutWidth = callout.offsetWidth + images.forEach(container => { + const imageWidth = container.offsetWidth if (imageWidth + 50 > calloutWidth) { - container.style.setProperty('width', '100%'); + container.style.setProperty('width', '100%') } - }); - }); - }; + }) + }) + } useEffect(() => { if (isBrowser) { - adjustCalloutImg(); - window.addEventListener('resize', adjustCalloutImg); + adjustCalloutImg() + window.addEventListener('resize', adjustCalloutImg) return () => { - window.removeEventListener('resize', adjustCalloutImg); - }; + window.removeEventListener('resize', adjustCalloutImg) + } } - }, []); -}; + }, []) +} -export default useAdjustStyle; +export default useAdjustStyle diff --git a/hooks/useWindowSize.ts b/hooks/useWindowSize.ts index 90f685c438a..717bee51b2b 100644 --- a/hooks/useWindowSize.ts +++ b/hooks/useWindowSize.ts @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react' interface WindowSize { - width: number, + width: number height: number } diff --git a/lib/cache/local_file_cache.js b/lib/cache/local_file_cache.js index c411d6e59d2..e07522a546f 100644 --- a/lib/cache/local_file_cache.js +++ b/lib/cache/local_file_cache.js @@ -6,7 +6,7 @@ const cacheInvalidSeconds = 1000000000 * 1000 // 文件名 const jsonFile = path.resolve('./data.json') -export async function getCache (key) { +export async function getCache(key) { const exist = await fs.existsSync(jsonFile) if (!exist) return null const data = await fs.readFileSync(jsonFile) @@ -19,7 +19,9 @@ export async function getCache (key) { return null } // 缓存超过有效期就作废 - const cacheValidTime = new Date(parseInt(json[key + '_expire_time']) + cacheInvalidSeconds) + const cacheValidTime = new Date( + parseInt(json[key + '_expire_time']) + cacheInvalidSeconds + ) const currentTime = new Date() if (!cacheValidTime || cacheValidTime < currentTime) { return null @@ -33,7 +35,7 @@ export async function getCache (key) { * @param data * @returns {Promise} */ -export async function setCache (key, data) { +export async function setCache(key, data) { const exist = await fs.existsSync(jsonFile) const json = exist ? JSON.parse(await fs.readFileSync(jsonFile)) : {} json[key] = data @@ -41,7 +43,7 @@ export async function setCache (key, data) { fs.writeFileSync(jsonFile, JSON.stringify(json)) } -export async function delCache (key) { +export async function delCache(key) { const exist = await fs.existsSync(jsonFile) const json = exist ? JSON.parse(await fs.readFileSync(jsonFile)) : {} delete json.key diff --git a/lib/lang.js b/lib/lang.js index 47bb7093f47..40a128e07ff 100644 --- a/lib/lang.js +++ b/lib/lang.js @@ -121,4 +121,4 @@ export const redirectUserLang = (lang, pageId) => { } } } -} \ No newline at end of file +} diff --git a/lib/notion/getAllPageIds.js b/lib/notion/getAllPageIds.js index 6d606d9a66b..d63bd08faee 100644 --- a/lib/notion/getAllPageIds.js +++ b/lib/notion/getAllPageIds.js @@ -1,5 +1,9 @@ - -export default function getAllPageIds (collectionQuery, collectionId, collectionView, viewIds) { +export default function getAllPageIds( + collectionQuery, + collectionId, + collectionView, + viewIds +) { if (!collectionQuery && !collectionView) { return [] } @@ -7,18 +11,24 @@ export default function getAllPageIds (collectionQuery, collectionId, collection let pageIds = [] try { if (viewIds && viewIds.length > 0) { - const ids = collectionQuery[collectionId][viewIds[0]]?.collection_group_results?.blockIds + const ids = + collectionQuery[collectionId][viewIds[0]]?.collection_group_results + ?.blockIds for (const id of ids) { pageIds.push(id) } } } catch (error) { - console.error('Error fetching page IDs:', error); - return []; + console.error('Error fetching page IDs:', error) + return [] } // 否则按照数据库原始排序 - if (pageIds.length === 0 && collectionQuery && Object.values(collectionQuery).length > 0) { + if ( + pageIds.length === 0 && + collectionQuery && + Object.values(collectionQuery).length > 0 + ) { const pageSet = new Set() Object.values(collectionQuery[collectionId]).forEach(view => { view?.blockIds?.forEach(id => pageSet.add(id)) // group视图 diff --git a/lib/notion/getMetadata.js b/lib/notion/getMetadata.js index 70796ee1b14..78bc568c9b3 100644 --- a/lib/notion/getMetadata.js +++ b/lib/notion/getMetadata.js @@ -1,4 +1,4 @@ -export default function getMetadata (rawMetadata) { +export default function getMetadata(rawMetadata) { const metadata = { locked: rawMetadata?.format?.block_locked, page_full_width: rawMetadata?.format?.page_full_width, diff --git a/lib/notion/getPageTableOfContents.js b/lib/notion/getPageTableOfContents.js index 738c22031cf..0cfbac6f40f 100644 --- a/lib/notion/getPageTableOfContents.js +++ b/lib/notion/getPageTableOfContents.js @@ -89,7 +89,7 @@ function getBlockHeader(contents, recordMap, toc) { toc ) } else if (type === 'transclusion_container') { - getBlockHeader(block.content, recordMap, toc) + getBlockHeader(block.content, recordMap, toc) } } } diff --git a/lib/notion/mapImage.js b/lib/notion/mapImage.js index 85ed4e30b33..ae691a06af8 100644 --- a/lib/notion/mapImage.js +++ b/lib/notion/mapImage.js @@ -24,18 +24,17 @@ const mapImgUrl = (img, block, type = 'block', needCompress = true) => { } const hasConverted = - ret.indexOf('https://www.notion.so/image') === 0 || - ret.includes('notion.site/images/page-cover/') + ret.indexOf('https://www.notion.so/image') === 0 || + ret.includes('notion.site/images/page-cover/') // 需要转化的URL ; 识别aws图床地址,或者bookmark类型的外链图片 // Notion新图床资源 格式为 attachment:${id}:${name} const needConvert = - !hasConverted && - (block.type === 'bookmark' || - ret.includes('secure.notion-static.com') || - ret.includes('prod-files-secure')) || - ret.indexOf('attachment')===0 - + (!hasConverted && + (block.type === 'bookmark' || + ret.includes('secure.notion-static.com') || + ret.includes('prod-files-secure'))) || + ret.indexOf('attachment') === 0 // Notion旧图床 if (needConvert) { @@ -113,7 +112,7 @@ const compressImage = (image, width, quality = 50, fmt = 'webp') => { return image } - if (image.includes(".svg")) return image + if (image.includes('.svg')) return image if (!width || width === 0) { width = siteConfig('IMAGE_COMPRESS_WIDTH') diff --git a/lib/utils/index.js b/lib/utils/index.js index e12f2f85fc3..c7138e412ed 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -110,11 +110,11 @@ export function checkStrIsUuid(str) { return false } // 使用正则表达式进行匹配 - const regex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/ + const regex = + /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/ return regex.test(str) } - // 检查一个字符串是否notionid : 32位,仅由数字英文构成 export function checkStrIsNotionId(str) { if (!str) { diff --git a/package.json b/package.json index e5714c105eb..3ec2f0e282c 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,9 @@ "export": "cross-env EXPORT=true next build && next-sitemap --config next-sitemap.config.js", "bundle-report": "cross-env ANALYZE=true next build", "build-all-in-dev": "cross-env VERCEL_ENV=production next build", - "version": "echo $npm_package_version" + "version": "echo $npm_package_version", + "format": "prettier --write \"**/*.{js,jsx,ts,tsx}\"", + "format:check": "prettier --check \"**/*.{js,jsx,ts,tsx}\"" }, "dependencies": { "@clerk/localizations": "^3.0.4", diff --git a/pages/api/cache.js b/pages/api/cache.js index 97738651fbc..e3babc6f797 100644 --- a/pages/api/cache.js +++ b/pages/api/cache.js @@ -8,8 +8,12 @@ import { cleanCache } from '@/lib/cache/local_file_cache' export default async function handler(req, res) { try { await cleanCache() - res.status(200).json({ status: 'success', message: 'Clean cache successful!' }) + res + .status(200) + .json({ status: 'success', message: 'Clean cache successful!' }) } catch (error) { - res.status(400).json({ status: 'error', message: 'Clean cache failed!', error }) + res + .status(400) + .json({ status: 'error', message: 'Clean cache failed!', error }) } } diff --git a/pages/api/subscribe.js b/pages/api/subscribe.js index d2d77894e70..96a742adb84 100644 --- a/pages/api/subscribe.js +++ b/pages/api/subscribe.js @@ -9,12 +9,20 @@ export default async function handler(req, res) { if (req.method === 'POST') { const { email, firstName, lastName } = req.body try { - const response = await subscribeToMailchimpApi({ email, first_name: firstName, last_name: lastName }) + const response = await subscribeToMailchimpApi({ + email, + first_name: firstName, + last_name: lastName + }) const data = await response.json() console.log('data', data) - res.status(200).json({ status: 'success', message: 'Subscription successful!' }) + res + .status(200) + .json({ status: 'success', message: 'Subscription successful!' }) } catch (error) { - res.status(400).json({ status: 'error', message: 'Subscription failed!', error }) + res + .status(400) + .json({ status: 'error', message: 'Subscription failed!', error }) } } else { res.status(405).json({ status: 'error', message: 'Method not allowed' }) diff --git a/pages/sitemap.xml.js b/pages/sitemap.xml.js index 06c21f4297a..91673e95868 100644 --- a/pages/sitemap.xml.js +++ b/pages/sitemap.xml.js @@ -27,7 +27,7 @@ export const getServerSideProps = async ctx => { fields = fields.concat(localeFields) } - fields = getUniqueFields(fields); + fields = getUniqueFields(fields) // 缓存 ctx.res.setHeader( @@ -104,17 +104,20 @@ function generateLocalesSitemap(link, allPages, locale) { } function getUniqueFields(fields) { - const uniqueFieldsMap = new Map(); + const uniqueFieldsMap = new Map() fields.forEach(field => { - const existingField = uniqueFieldsMap.get(field.loc); + const existingField = uniqueFieldsMap.get(field.loc) - if (!existingField || new Date(field.lastmod) > new Date(existingField.lastmod)) { - uniqueFieldsMap.set(field.loc, field); + if ( + !existingField || + new Date(field.lastmod) > new Date(existingField.lastmod) + ) { + uniqueFieldsMap.set(field.loc, field) } - }); + }) - return Array.from(uniqueFieldsMap.values()); + return Array.from(uniqueFieldsMap.values()) } export default () => {} diff --git a/themes/commerce/components/AnalyticsCard.js b/themes/commerce/components/AnalyticsCard.js index 0ee1e1cdfb6..7fe21b06600 100644 --- a/themes/commerce/components/AnalyticsCard.js +++ b/themes/commerce/components/AnalyticsCard.js @@ -1,30 +1,32 @@ import Card from './Card' -export function AnalyticsCard (props) { +export function AnalyticsCard(props) { const { postCount } = props - return -
- 统计 -
-
-
-
-
文章数:
-
{postCount}
-
+ return ( + +
+ 统计
-
-
-
访问量:
-
+
+
+
+
文章数:
+
{postCount}
+
-
-
-
-
访客数:
-
+
+
+
访问量:
+
+
+
+
+
+
访客数:
+
+
-
- + + ) } diff --git a/themes/commerce/components/Announcement.js b/themes/commerce/components/Announcement.js index 695c26a4fe2..20c04de0536 100644 --- a/themes/commerce/components/Announcement.js +++ b/themes/commerce/components/Announcement.js @@ -6,14 +6,23 @@ const NotionPage = dynamic(() => import('@/components/NotionPage')) const Announcement = ({ post, className }) => { const { locale } = useGlobal() if (post?.blockMap) { - return
-
-
{locale.COMMON.ANNOUNCEMENT}
- {post && (
- -
)} + return ( +
+
+
+ + {locale.COMMON.ANNOUNCEMENT} +
+ {post && ( +
+ +
+ )}
-
+
+ ) } else { return <> } diff --git a/themes/commerce/components/ArticleAdjacent.js b/themes/commerce/components/ArticleAdjacent.js index 21ca9e325ae..19678f28ff8 100644 --- a/themes/commerce/components/ArticleAdjacent.js +++ b/themes/commerce/components/ArticleAdjacent.js @@ -6,7 +6,7 @@ import CONFIG from '../config' * @param {prev,next} param0 * @returns */ -export default function ArticleAdjacent ({ prev, next }) { +export default function ArticleAdjacent({ prev, next }) { if (!prev || !next || !CONFIG.ARTICLE_ADJACENT) { return <> } @@ -16,9 +16,8 @@ export default function ArticleAdjacent ({ prev, next }) { href={`/${prev.slug}`} passHref className='py-1 cursor-pointer hover:underline justify-start items-center dark:text-white flex w-full h-full duration-200'> - - {prev.title} - + + {prev.title} {next.title} - ) diff --git a/themes/commerce/components/ArticleCopyright.js b/themes/commerce/components/ArticleCopyright.js index 67c65bab89f..74116c1156e 100644 --- a/themes/commerce/components/ArticleCopyright.js +++ b/themes/commerce/components/ArticleCopyright.js @@ -5,7 +5,7 @@ import { useEffect, useState } from 'react' import CONFIG from '../config' import { siteConfig } from '@/lib/config' -export default function ArticleCopyright () { +export default function ArticleCopyright() { const router = useRouter() const [path, setPath] = useState(siteConfig('LINK') + router.asPath) useEffect(() => { @@ -19,17 +19,19 @@ export default function ArticleCopyright () { } return ( -
-
    +
    +
    • {locale.COMMON.AUTHOR}: - + {siteConfig('AUTHOR')}
    • - {locale.COMMON.URL}: - + {locale.COMMON.URL}: + {path}
    • @@ -39,5 +41,5 @@ export default function ArticleCopyright () {
    - ); + ) } diff --git a/themes/commerce/components/ArticleLock.js b/themes/commerce/components/ArticleLock.js index 9ef687e951b..d4c9024f501 100644 --- a/themes/commerce/components/ArticleLock.js +++ b/themes/commerce/components/ArticleLock.js @@ -27,25 +27,35 @@ export const ArticleLock = props => { passwordInputRef.current.focus() }, []) - return
    -
    -
    {locale.COMMON.ARTICLE_LOCK_TIPS}
    -
    - { + return ( +
    +
    +
    + {locale.COMMON.ARTICLE_LOCK_TIPS} +
    +
    + { if (e.key === 'Enter') { submitPassword() } }} ref={passwordInputRef} // 绑定ref到passwordInputRef变量 - className='outline-none w-full text-sm pl-5 rounded-l transition focus:shadow-lg font-light leading-10 bg-gray-100 dark:bg-gray-500'> - -
    -  {locale.COMMON.SUBMIT} + className='outline-none w-full text-sm pl-5 rounded-l transition focus:shadow-lg font-light leading-10 bg-gray-100 dark:bg-gray-500'> +
    + +  {locale.COMMON.SUBMIT} + +
    -
    -
    +
    -
    + ) } diff --git a/themes/commerce/components/ArticleRecommend.js b/themes/commerce/components/ArticleRecommend.js index b26aace1a3c..a537ebea0ab 100644 --- a/themes/commerce/components/ArticleRecommend.js +++ b/themes/commerce/components/ArticleRecommend.js @@ -14,47 +14,48 @@ export default function ArticleRecommend({ recommendPosts, siteInfo }) { if ( !CONFIG.ARTICLE_RECOMMEND || - !recommendPosts || - recommendPosts.length === 0 + !recommendPosts || + recommendPosts.length === 0 ) { return <> } return ( -
    -
    -
    - - {locale.COMMON.RELATE_POSTS} -
    -
    -
    - {recommendPosts.map(post => { - const headerImage = post?.pageCoverThumbnail - ? post.pageCoverThumbnail - : siteInfo?.pageCover - - return ( - ( - -
    -
    -
    - {post.title} -
    -
    - -
    - - ) - ) - })} -
    +
    +
    +
    + + {locale.COMMON.RELATE_POSTS}
    +
    +
    + {recommendPosts.map(post => { + const headerImage = post?.pageCoverThumbnail + ? post.pageCoverThumbnail + : siteInfo?.pageCover + + return ( + +
    +
    +
    + {post.title} +
    +
    + +
    + + ) + })} +
    +
    ) } diff --git a/themes/commerce/components/BlogPostArchive.js b/themes/commerce/components/BlogPostArchive.js index 8c3fbaaf878..e3ce04c754b 100644 --- a/themes/commerce/components/BlogPostArchive.js +++ b/themes/commerce/components/BlogPostArchive.js @@ -15,27 +15,23 @@ const BlogPostArchive = ({ posts = [], archiveTitle }) => { return (
    + className='pt-16 pb-4 text-3xl dark:text-gray-300' + id={archiveTitle}> {archiveTitle}
      {posts?.map(post => (
    • + className='border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-red-500 dark:hover:border-red-300 dark:border-red-400 transform duration-500'>
      - {post.date?.start_date}{' '} + {post.date?.start_date}{' '}   - + className='dark:text-gray-400 dark:hover:text-red-300 overflow-x-hidden hover:underline cursor-pointer text-gray-600'> {post.title} -
    • diff --git a/themes/commerce/components/BlogPostCardInfo.js b/themes/commerce/components/BlogPostCardInfo.js index 8b2f4a489f8..053ca5896a5 100644 --- a/themes/commerce/components/BlogPostCardInfo.js +++ b/themes/commerce/components/BlogPostCardInfo.js @@ -10,85 +10,92 @@ import formatDate from '@/lib/utils/formatDate' * @param {*} param0 * @returns */ -export const BlogPostCardInfo = ({ post, showPreview, showPageCover, showSummary }) => { - return
      -
      - {/* 标题 */} - - - {post.title} - +export const BlogPostCardInfo = ({ + post, + showPreview, + showPageCover, + showSummary +}) => { + return ( +
      +
      + {/* 标题 */} + + {post.title} {/* 分类 */} - { post?.category &&
      + {post?.category && ( +
      - - - {post.category} - + href={`/category/${post.category}`} + passHref + className='cursor-pointer font-light text-sm menu-link hover:text-red-700 dark:hover:text-red-400 transform'> + + {post.category} - -
      } + +
      + )} - {/* 摘要 */} - {(!showPreview || showSummary) && !post.results && ( -

      - {post.summary} -

      - )} + {/* 摘要 */} + {(!showPreview || showSummary) && !post.results && ( +

      + {post.summary} +

      + )} {/* 搜索结果 */} {post.results && ( -

      - {post.results.map((r, index) => ( - {r} - ))} -

      +

      + {post.results.map((r, index) => ( + {r} + ))} +

      )} {/* 预览 */} {showPreview && ( -
      - -
      +
      + +
      )} +
      -
      - -
      - {/* 日期标签 */} -
      - {/* 日期 */} - - - - {post?.publishDay || post.lastEditedDay} - - +
      + {/* 日期标签 */} +
      + {/* 日期 */} + + + {post?.publishDay || post.lastEditedDay} + -
      -
      - {' '} - {post.tagItems?.map(tag => ( - - ))} -
      +
      +
      + {' '} + {post.tagItems?.map(tag => ( + + ))}
      +
      -
      -
      +
      +
      + ) } diff --git a/themes/commerce/components/BlogPostListEmpty.js b/themes/commerce/components/BlogPostListEmpty.js index 5f75c3e7d0b..dc2a9c17ef3 100644 --- a/themes/commerce/components/BlogPostListEmpty.js +++ b/themes/commerce/components/BlogPostListEmpty.js @@ -7,8 +7,12 @@ import { useGlobal } from '@/lib/global' */ const BlogPostListEmpty = ({ currentSearch }) => { const { locale } = useGlobal() - return
      -
      {locale.COMMON.NO_MORE} {(currentSearch &&
      {currentSearch}
      )}
      -
      + return ( +
      +
      + {locale.COMMON.NO_MORE} {currentSearch &&
      {currentSearch}
      } +
      +
      + ) } export default BlogPostListEmpty diff --git a/themes/commerce/components/Card.js b/themes/commerce/components/Card.js index c2db0e49f71..37e6ed728d8 100644 --- a/themes/commerce/components/Card.js +++ b/themes/commerce/components/Card.js @@ -1,9 +1,11 @@ const Card = ({ children, headerSlot, className }) => { - return
      - <>{headerSlot} -
      + return ( +
      + <>{headerSlot} +
      {children} -
      -
      +
      +
      + ) } export default Card diff --git a/themes/commerce/components/CategoryGroup.js b/themes/commerce/components/CategoryGroup.js index 0b313088bd1..9df4d194d67 100644 --- a/themes/commerce/components/CategoryGroup.js +++ b/themes/commerce/components/CategoryGroup.js @@ -4,27 +4,37 @@ const CategoryGroup = ({ currentCategory, categories }) => { if (!categories) { return <> } - return <> -
      - {categories.map(category => { - const selected = currentCategory === category.name - return ( - - -
      {category.name}({category.count})
      - - - ); - })} -
      - ; + return ( + <> +
      + {categories.map(category => { + const selected = currentCategory === category.name + return ( + +
      + {' '} + + {category.name}({category.count}) +
      + + ) + })} +
      + + ) } export default CategoryGroup diff --git a/themes/commerce/components/Hero.js b/themes/commerce/components/Hero.js index af3caae1a9c..6485281732c 100644 --- a/themes/commerce/components/Hero.js +++ b/themes/commerce/components/Hero.js @@ -10,14 +10,17 @@ const Hero = props => { const { siteInfo } = props return ( - ) } diff --git a/themes/commerce/components/HexoRecentComments.js b/themes/commerce/components/HexoRecentComments.js index db712bea678..4c7b12940b9 100644 --- a/themes/commerce/components/HexoRecentComments.js +++ b/themes/commerce/components/HexoRecentComments.js @@ -10,7 +10,7 @@ import { RecentComments } from '@waline/client' * @param {*} props * @returns */ -const HexoRecentComments = (props) => { +const HexoRecentComments = props => { const [comments, updateComments] = useState([]) const { locale } = useGlobal() const [onLoading, changeLoading] = useState(true) @@ -25,22 +25,43 @@ const HexoRecentComments = (props) => { }, []) return ( - -
      - - {locale.COMMON.RECENT_COMMENTS} -
      - - {onLoading &&
      Loading...
      } - {!onLoading && comments && comments.length === 0 &&
      No Comments
      } - {!onLoading && comments && comments.length > 0 && comments.map((comment) =>
      -
      -
      - --{comment.nick} -
      -
      )} + +
      + + {locale.COMMON.RECENT_COMMENTS} +
      -
      + {onLoading && ( +
      + Loading... + +
      + )} + {!onLoading && comments && comments.length === 0 && ( +
      No Comments
      + )} + {!onLoading && + comments && + comments.length > 0 && + comments.map(comment => ( +
      +
      +
      + + --{comment.nick} + +
      +
      + ))} + ) } diff --git a/themes/commerce/components/InfoCard.js b/themes/commerce/components/InfoCard.js index 6b33034efca..1f18d7d1992 100644 --- a/themes/commerce/components/InfoCard.js +++ b/themes/commerce/components/InfoCard.js @@ -14,20 +14,26 @@ export function InfoCard(props) { const { className, siteInfo } = props const router = useRouter() return ( - -
      { - router.push('/') - }} - > - {/* eslint-disable-next-line @next/next/no-img-element */} - -
      -
      {siteConfig('AUTHOR')}
      -
      {siteConfig('BIO')}
      - - -
      + +
      { + router.push('/') + }}> + {/* eslint-disable-next-line @next/next/no-img-element */} + +
      +
      + {siteConfig('AUTHOR')} +
      +
      {siteConfig('BIO')}
      + + +
      ) } diff --git a/themes/commerce/components/JumpToCommentButton.js b/themes/commerce/components/JumpToCommentButton.js index ded36c9a53d..fe9f2be2f15 100644 --- a/themes/commerce/components/JumpToCommentButton.js +++ b/themes/commerce/components/JumpToCommentButton.js @@ -12,7 +12,10 @@ const JumpToCommentButton = () => { function navToComment() { if (document.getElementById('comment')) { - window.scrollTo({ top: document.getElementById('comment').offsetTop, behavior: 'smooth' }) + window.scrollTo({ + top: document.getElementById('comment').offsetTop, + behavior: 'smooth' + }) } // 兼容性不好 // const commentElement = document.getElementById('comment') @@ -20,9 +23,13 @@ const JumpToCommentButton = () => { // commentElement?.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'nearest' }) } - return (
      - -
      ) + return ( +
      + +
      + ) } export default JumpToCommentButton diff --git a/themes/commerce/components/JumpToTopButton.js b/themes/commerce/components/JumpToTopButton.js index a89899a9271..edb90ab2b57 100644 --- a/themes/commerce/components/JumpToTopButton.js +++ b/themes/commerce/components/JumpToTopButton.js @@ -15,10 +15,16 @@ const JumpToTopButton = ({ showPercent = true, percent }) => { if (!CONFIG.WIDGET_TO_TOP) { return <> } - return (
      window.scrollTo({ top: 0, behavior: 'smooth' })} > -
      - {showPercent && (
      {percent}
      )} -
      ) + return ( +
      window.scrollTo({ top: 0, behavior: 'smooth' })}> +
      + +
      + {showPercent &&
      {percent}
      } +
      + ) } export default JumpToTopButton diff --git a/themes/commerce/components/LatestPostsGroup.js b/themes/commerce/components/LatestPostsGroup.js index 3c4fadbcdf6..2b2834e2b7f 100644 --- a/themes/commerce/components/LatestPostsGroup.js +++ b/themes/commerce/components/LatestPostsGroup.js @@ -20,45 +20,50 @@ const LatestPostsGroup = ({ latestPosts, siteInfo }) => { return <> } - return <> -
      -
      - - {locale.COMMON.LATEST_POSTS} -
      + return ( + <> +
      +
      + + {locale.COMMON.LATEST_POSTS}
      - {latestPosts.map(post => { - const selected = currentPath === `${siteConfig('SUB_PATH', '')}/${post.slug}` - - const headerImage = post?.pageCoverThumbnail ? post.pageCoverThumbnail : siteInfo?.pageCover - - return ( - ( +
      + {latestPosts.map(post => { + const selected = + currentPath === `${siteConfig('SUB_PATH', '')}/${post.slug}` -
      - -
      -
      -
      -
      {post.title}
      -
      {post.lastEditedDay}
      -
      -
      + const headerImage = post?.pageCoverThumbnail + ? post.pageCoverThumbnail + : siteInfo?.pageCover - ) - ) - })} + return ( + +
      + +
      +
      +
      +
      {post.title}
      +
      {post.lastEditedDay}
      +
      +
      + + ) + })} + ) } export default LatestPostsGroup diff --git a/themes/commerce/components/LoadingCover.js b/themes/commerce/components/LoadingCover.js index c6418fad827..ede08a3f33b 100644 --- a/themes/commerce/components/LoadingCover.js +++ b/themes/commerce/components/LoadingCover.js @@ -1,8 +1,13 @@ -export default function LoadingCover () { - return (
      -
      - -
      -
      +export default function LoadingCover() { + return ( +
      +
      + +
      +
      ) } diff --git a/themes/commerce/components/LogoBar.js b/themes/commerce/components/LogoBar.js index de5a5bfeba1..ef79917e1a1 100644 --- a/themes/commerce/components/LogoBar.js +++ b/themes/commerce/components/LogoBar.js @@ -1,20 +1,20 @@ import Link from 'next/link' // import { siteConfig } from '@/lib/config' -import LazyImage from '@/components/LazyImage'; +import LazyImage from '@/components/LazyImage' /** * Logo图标 * @param {*} props * @returns */ -export default function LogoBar (props) { +export default function LogoBar(props) { const { siteInfo } = props return (
      - - - - {/*
      {siteConfig('TITLE')}
      */} + + + + {/*
      {siteConfig('TITLE')}
      */}
      - ); + ) } diff --git a/themes/commerce/components/NavButtonGroup.js b/themes/commerce/components/NavButtonGroup.js index 8539eb49161..556c0dc0a4e 100644 --- a/themes/commerce/components/NavButtonGroup.js +++ b/themes/commerce/components/NavButtonGroup.js @@ -5,14 +5,18 @@ import Link from 'next/link' * @param {*} props * @returns */ -const NavButtonGroup = (props) => { +const NavButtonGroup = props => { const { categoryOptions } = props if (!categoryOptions || categoryOptions.length === 0) { return <> } return ( -
- ); + ) } diff --git a/themes/fukasawa/components/ArticleLock.js b/themes/fukasawa/components/ArticleLock.js index 6acd6f69c2b..37e6a1e717d 100644 --- a/themes/fukasawa/components/ArticleLock.js +++ b/themes/fukasawa/components/ArticleLock.js @@ -29,34 +29,37 @@ const ArticleLock = props => { passwordInputRef.current.focus() }, []) - return (
-
-
-
-
{locale.COMMON.ARTICLE_LOCK_TIPS}
-
- { - if (e.key === 'Enter') { - submitPassword() - } - }} - ref={passwordInputRef} // 绑定ref到passwordInputRef变量 - className="outline-none w-full text-sm pl-5 rounded-l transition focus:shadow-lg font-light leading-10 bg-gray-100 dark:bg-gray-500" - > -
-  {locale.COMMON.SUBMIT} + return ( +
+
+
+
+
{locale.COMMON.ARTICLE_LOCK_TIPS}
+
+ { + if (e.key === 'Enter') { + submitPassword() + } + }} + ref={passwordInputRef} // 绑定ref到passwordInputRef变量 + className='outline-none w-full text-sm pl-5 rounded-l transition focus:shadow-lg font-light leading-10 bg-gray-100 dark:bg-gray-500'> +
+ +  {locale.COMMON.SUBMIT} + +
+
-
-
) + ) } export default ArticleLock diff --git a/themes/fukasawa/components/BlogCard.js b/themes/fukasawa/components/BlogCard.js index 2cfb0ce48bd..f64b7a9f5ac 100644 --- a/themes/fukasawa/components/BlogCard.js +++ b/themes/fukasawa/components/BlogCard.js @@ -12,7 +12,7 @@ import TagItemMini from './TagItemMini' * @returns */ const BlogCard = ({ showAnimate, post, showSummary }) => { -const {siteInfo} =useGlobal() + const { siteInfo } = useGlobal() const showPreview = siteConfig('FUKASAWA_POST_LIST_PREVIEW', null, CONFIG) && post.blockMap // fukasawa 强制显示图片 @@ -26,12 +26,9 @@ const {siteInfo} =useGlobal() const showPageCover = siteConfig('FUKASAWA_POST_LIST_COVER', null, CONFIG) && post?.pageCoverThumbnail - - const FUKASAWA_POST_LIST_ANIMATION = siteConfig( - 'FUKASAWA_POST_LIST_ANIMATION', - null, - CONFIG - ) || showAnimate + + const FUKASAWA_POST_LIST_ANIMATION = + siteConfig('FUKASAWA_POST_LIST_ANIMATION', null, CONFIG) || showAnimate // 动画样式 首屏卡片不用,后面翻出来的加动画 const aosProps = FUKASAWA_POST_LIST_ANIMATION diff --git a/themes/fukasawa/components/BlogListEmpty.js b/themes/fukasawa/components/BlogListEmpty.js index 59c5c892f94..b9cfda8ae6f 100644 --- a/themes/fukasawa/components/BlogListEmpty.js +++ b/themes/fukasawa/components/BlogListEmpty.js @@ -7,8 +7,13 @@ import { useGlobal } from '@/lib/global' */ const BlogListEmpty = ({ currentSearch }) => { const { locale } = useGlobal() - return
-

{locale.COMMON.NO_RESULTS_FOUND} {(currentSearch &&

{currentSearch}
)}

-
+ return ( +
+

+ {locale.COMMON.NO_RESULTS_FOUND}{' '} + {currentSearch &&

{currentSearch}
} +

+
+ ) } export default BlogListEmpty diff --git a/themes/fukasawa/components/BlogListPage.js b/themes/fukasawa/components/BlogListPage.js index 6d5e55b708d..a762095dd3a 100644 --- a/themes/fukasawa/components/BlogListPage.js +++ b/themes/fukasawa/components/BlogListPage.js @@ -18,9 +18,7 @@ import PaginationSimple from './PaginationSimple' const BlogListPage = ({ page = 1, posts = [], postCount, siteInfo }) => { const { NOTION_CONFIG } = useGlobal() const postsPerPage = siteConfig('POSTS_PER_PAGE', null, NOTION_CONFIG) - const totalPage = Math.ceil( - postCount / postsPerPage - ) + const totalPage = Math.ceil(postCount / postsPerPage) const showNext = page < totalPage const [columns, setColumns] = useState(calculateColumns()) @@ -34,27 +32,27 @@ const BlogListPage = ({ page = 1, posts = [], postCount, siteInfo }) => { return () => window.removeEventListener('resize', handleResize) }, []) - /** - * 文章重新布局,使纵向排列看起来是横向排列 - */ + /** + * 文章重新布局,使纵向排列看起来是横向排列 + */ useEffect(() => { - const count = posts?.length || 0; - const rows = Math.ceil(count / columns); - const newFilterPosts = new Array(count); + const count = posts?.length || 0 + const rows = Math.ceil(count / columns) + const newFilterPosts = new Array(count) - let index = 0; + let index = 0 for (let col = 0; col < columns; col++) { - for (let row = 0; row < rows; row++) { - const sourceIndex = row * columns + col; + for (let row = 0; row < rows; row++) { + const sourceIndex = row * columns + col if (sourceIndex < count) { - newFilterPosts[index] = deepClone(posts[sourceIndex]); - index++; - } + newFilterPosts[index] = deepClone(posts[sourceIndex]) + index++ } + } } - - setFilterPosts(newFilterPosts); - }, [columns, posts]); + + setFilterPosts(newFilterPosts) + }, [columns, posts]) if (!filterPosts || filterPosts.length === 0) { return diff --git a/themes/fukasawa/components/BlogListScroll.js b/themes/fukasawa/components/BlogListScroll.js index 489b22c8675..370e2f886ad 100644 --- a/themes/fukasawa/components/BlogListScroll.js +++ b/themes/fukasawa/components/BlogListScroll.js @@ -1,33 +1,31 @@ -import { siteConfig } from '@/lib/config'; -import { useGlobal } from '@/lib/global'; -import throttle from 'lodash.throttle'; -import { useCallback, useEffect, useRef, useState } from 'react'; -import BlogCard from './BlogCard'; -import BlogPostListEmpty from './BlogListEmpty'; +import { siteConfig } from '@/lib/config' +import { useGlobal } from '@/lib/global' +import throttle from 'lodash.throttle' +import { useCallback, useEffect, useRef, useState } from 'react' +import BlogCard from './BlogCard' +import BlogPostListEmpty from './BlogListEmpty' const BlogListScroll = ({ posts }) => { - const { locale, NOTION_CONFIG } = useGlobal(); - const [page, setPage] = useState(1); - const POSTS_PER_PAGE = siteConfig('POSTS_PER_PAGE', null, NOTION_CONFIG); - const [filterPostsGroups, setFilterPostsGroups] = useState([]); + const { locale, NOTION_CONFIG } = useGlobal() + const [page, setPage] = useState(1) + const POSTS_PER_PAGE = siteConfig('POSTS_PER_PAGE', null, NOTION_CONFIG) + const [filterPostsGroups, setFilterPostsGroups] = useState([]) // 每页显示的文章数量 - const postsPerPage = POSTS_PER_PAGE; + const postsPerPage = POSTS_PER_PAGE // 计算总页数 - const totalPages = Math.ceil(posts.length / postsPerPage); + const totalPages = Math.ceil(posts.length / postsPerPage) // 加载更多文章 const loadMorePosts = () => { if (page < totalPages) { - setPage(page + 1); + setPage(page + 1) } - }; - + } const targetRef = useRef(null) - // 监听滚动自动分页加载 const scrollTrigger = useCallback( throttle(() => { @@ -52,50 +50,56 @@ const BlogListScroll = ({ posts }) => { // 根据当前页和每页文章数截取应该显示的文章 useEffect(() => { - const startIndex = (page - 1) * postsPerPage; - const endIndex = startIndex + postsPerPage; - const postsToShow = posts.slice(startIndex, endIndex); - const columns = 3; // 假设有3列 + const startIndex = (page - 1) * postsPerPage + const endIndex = startIndex + postsPerPage + const postsToShow = posts.slice(startIndex, endIndex) + const columns = 3 // 假设有3列 // 重新排列文章,保证列优先顺序 - const newFilterPosts = []; + const newFilterPosts = [] for (let col = 0; col < columns; col++) { for (let i = col; i < postsToShow.length; i += columns) { - newFilterPosts.push(postsToShow[i]); + newFilterPosts.push(postsToShow[i]) } } - setFilterPostsGroups((prev) => [...prev, newFilterPosts]); - }, [posts, page]); + setFilterPostsGroups(prev => [...prev, newFilterPosts]) + }, [posts, page]) if (!posts || posts.length === 0) { - return ; + return } else { return (
{filterPostsGroups.map((group, groupIndex) => ( -
- {group.map((post) => ( +
+ {group.map(post => (
- 0}/> + className='grid-item justify-center flex' + style={{ breakInside: 'avoid' }}> + 0} + />
))}
))}
- {page < totalPages ? locale.COMMON.MORE : `${locale.COMMON.NO_MORE} 😰`} + className='w-full my-4 py-4 text-center cursor-pointer' + onClick={loadMorePosts}> + {page < totalPages + ? locale.COMMON.MORE + : `${locale.COMMON.NO_MORE} 😰`}
- ); + ) } -}; - -export default BlogListScroll; +} +export default BlogListScroll diff --git a/themes/fukasawa/components/Card.js b/themes/fukasawa/components/Card.js index e88dee68c95..d08d5735c78 100644 --- a/themes/fukasawa/components/Card.js +++ b/themes/fukasawa/components/Card.js @@ -1,9 +1,11 @@ const Card = ({ children, headerSlot, className }) => { - return
- <>{headerSlot} -
- {children} -
+ return ( +
+ <>{headerSlot} +
+ {children} +
+ ) } export default Card diff --git a/themes/fukasawa/components/GroupCategory.js b/themes/fukasawa/components/GroupCategory.js index 1753afd22da..c51a2896b01 100644 --- a/themes/fukasawa/components/GroupCategory.js +++ b/themes/fukasawa/components/GroupCategory.js @@ -1,30 +1,36 @@ import Link from 'next/link' -function GroupCategory ({ currentCategory, categories }) { +function GroupCategory({ currentCategory, categories }) { if (!categories) { return <> } - return <> -
- {categories.map(category => { - const selected = currentCategory === category.name - return ( - - - {category.name}({category.count}) - - ) - })} -
- + return ( + <> +
+ {categories.map(category => { + const selected = currentCategory === category.name + return ( + + + {category.name}({category.count}) + + ) + })} +
+ + ) } export default GroupCategory diff --git a/themes/fukasawa/components/GroupTag.js b/themes/fukasawa/components/GroupTag.js index fbeca088ccb..ae7e21501be 100644 --- a/themes/fukasawa/components/GroupTag.js +++ b/themes/fukasawa/components/GroupTag.js @@ -7,16 +7,14 @@ import TagItemMini from './TagItemMini' * @returns {JSX.Element} * @constructor */ -function GroupTag ({ tags, currentTag }) { +function GroupTag({ tags, currentTag }) { if (!tags) return <> return (
- { - tags?.slice(0, 20)?.map(tag => { - const selected = tag.name === currentTag - return - }) - } + {tags?.slice(0, 20)?.map(tag => { + const selected = tag.name === currentTag + return + })}
) } diff --git a/themes/fukasawa/components/LoadingCover.js b/themes/fukasawa/components/LoadingCover.js index 01a2036d59d..79c59247f38 100644 --- a/themes/fukasawa/components/LoadingCover.js +++ b/themes/fukasawa/components/LoadingCover.js @@ -2,10 +2,18 @@ * 加载过程的遮罩 * @returns */ -export default function LoadingCover () { - return
-
- +export default function LoadingCover() { + return ( +
+
+ + {' '} + +
-
+ ) } diff --git a/themes/fukasawa/components/MailChimpForm.js b/themes/fukasawa/components/MailChimpForm.js index 8e70c09d594..34fd1b8c914 100644 --- a/themes/fukasawa/components/MailChimpForm.js +++ b/themes/fukasawa/components/MailChimpForm.js @@ -15,14 +15,15 @@ export default function MailChimpForm() { useEffect(() => { const form = formRef.current - const handleSubmit = (e) => { + const handleSubmit = e => { e.preventDefault() const email = document.querySelector('#newsletter').value - subscribeToNewsletter(email).then(response => { - console.log('Subscription succeeded:', response) - // 在此处添加成功订阅后的操作 - setSuccess(true) - }) + subscribeToNewsletter(email) + .then(response => { + console.log('Subscription succeeded:', response) + // 在此处添加成功订阅后的操作 + setSuccess(true) + }) .catch(error => { console.error('Subscription failed:', error) // 在此处添加订阅失败后的操作 @@ -34,29 +35,59 @@ export default function MailChimpForm() { } }, [subscribeToNewsletter]) - return <> - {siteConfig('FUKASAWA_MAILCHIMP_FORM', null, CONFIG) &&
-
{locale.MAILCHIMP.SUBSCRIBE}
-

{locale.MAILCHIMP.MSG}

-
-
-
- -
- - -
- {/* Success message */} - {success &&

Thanks for subscribing!

} -
+ return ( + <> + {siteConfig('FUKASAWA_MAILCHIMP_FORM', null, CONFIG) && ( +
+
+ {locale.MAILCHIMP.SUBSCRIBE} +
+

{locale.MAILCHIMP.MSG}

+ +
+
+ +
+ +
- + {/* Success message */} + {success && ( +

+ Thanks for subscribing! +

+ )} +
+
+
- } + )} + ) } diff --git a/themes/fukasawa/components/PaginationSimple.js b/themes/fukasawa/components/PaginationSimple.js index 11c0d3f3faa..2da90183506 100644 --- a/themes/fukasawa/components/PaginationSimple.js +++ b/themes/fukasawa/components/PaginationSimple.js @@ -13,10 +13,13 @@ const PaginationSimple = ({ page, showNext }) => { const { locale } = useGlobal() const router = useRouter() const currentPage = +page - const pagePrefix = router.asPath.split('?')[0].replace(/\/page\/[1-9]\d*/, '').replace(/\/$/, '') + const pagePrefix = router.asPath + .split('?')[0] + .replace(/\/page\/[1-9]\d*/, '') + .replace(/\/$/, '') return ( -
+
{ query: router.query.s ? { s: router.query.s } : {} }} passHref - rel="prev" + rel='prev' className={`${ currentPage === 1 ? 'invisible' : 'visible' } text-center w-full duration-200 px-4 py-2 hover:border-black border-b-2 hover:font-bold`}> ←{locale.PAGINATION.PREV} - { query: router.query.s ? { s: router.query.s } : {} }} passHref - rel="next" + rel='next' className={`${ showNext ? 'visible' : 'invisible' } text-center w-full duration-200 px-4 py-2 hover:border-black border-b-2 hover:font-bold`}> - {locale.PAGINATION.NEXT}→
diff --git a/themes/fukasawa/components/SearchInput.js b/themes/fukasawa/components/SearchInput.js index bd7ea099c87..d879eff412c 100644 --- a/themes/fukasawa/components/SearchInput.js +++ b/themes/fukasawa/components/SearchInput.js @@ -4,7 +4,7 @@ import { useImperativeHandle, useRef, useState } from 'react' import { useFukasawaGlobal } from '@/themes/fukasawa' import { siteConfig } from '@/lib/config' -const SearchInput = (props) => { +const SearchInput = props => { const { keyword, cRef } = props const { searchModal } = useFukasawaGlobal() const [onLoading, setLoadingState] = useState(false) @@ -34,8 +34,7 @@ const SearchInput = (props) => { }) // location.href = '/search/' + key } else { - router.push({ pathname: '/' }).then(r => { - }) + router.push({ pathname: '/' }).then(r => {}) } } @@ -43,14 +42,16 @@ const SearchInput = (props) => { * 监听事件 * @param {*} e */ - const handleKeyUp = (e) => { + const handleKeyUp = e => { if (siteConfig('ALGOLIA_APP_ID')) { searchModal?.current?.openSearch() return } - if (e.keyCode === 13) { // 回车 + if (e.keyCode === 13) { + // 回车 handleSearch(searchInputRef.current.value) - } else if (e.keyCode === 27) { // ESC + } else if (e.keyCode === 27) { + // ESC cleanSearch() } } @@ -67,29 +68,39 @@ const SearchInput = (props) => { searchInputRef.current.value = '' } - return
- - -
- -
+ return ( +
+ - {(keyword && keyword.length && -
- +
+
- )} -
+ + {keyword && keyword.length && ( +
+ +
+ )} +
+ ) } export default SearchInput diff --git a/themes/fukasawa/components/TagItem.js b/themes/fukasawa/components/TagItem.js index 179da9db384..38b8085d7a9 100644 --- a/themes/fukasawa/components/TagItem.js +++ b/themes/fukasawa/components/TagItem.js @@ -4,7 +4,7 @@ import { useGlobal } from '@/lib/global' const TagItem = ({ tag, selected }) => { const { locale } = useGlobal() if (!tag) { -
{ locale.COMMON.NOTAG }
+ ;
{locale.COMMON.NOTAG}
} return ( { duration-200 mr-1 my-1 px-2 py-1 text-sm whitespace-nowrap hover:bg-gray-200 dark:hover:bg-gray-800 `}>
- {selected && } {`${tag.name} `} {tag.count ? `(${tag.count})` : ''} + {selected && } {`${tag.name} `}{' '} + {tag.count ? `(${tag.count})` : ''}
- ); + ) } export default TagItem diff --git a/themes/fukasawa/components/TagItemMini.js b/themes/fukasawa/components/TagItemMini.js index 26295088274..1919302ee86 100644 --- a/themes/fukasawa/components/TagItemMini.js +++ b/themes/fukasawa/components/TagItemMini.js @@ -8,14 +8,17 @@ const TagItemMini = ({ tag, selected = false }) => { passHref className={`cursor-pointer inline-block rounded hover:bg-gray-500 hover:text-white duration-200 mr-2 py-0.5 px-1 text-xs whitespace-nowrap dark:hover:text-white - ${selected - ? 'text-white dark:text-gray-300 bg-black dark:bg-black dark:hover:bg-gray-900' - : `text-gray-600 hover:shadow-xl dark:border-gray-400 notion-${tag.color}_background dark:bg-gray-800`}` }> - -
{selected && } {tag.name + (tag.count ? `(${tag.count})` : '')}
- + ${ + selected + ? 'text-white dark:text-gray-300 bg-black dark:bg-black dark:hover:bg-gray-900' + : `text-gray-600 hover:shadow-xl dark:border-gray-400 notion-${tag.color}_background dark:bg-gray-800` + }`}> +
+ {selected && }{' '} + {tag.name + (tag.count ? `(${tag.count})` : '')}{' '} +
- ); + ) } export default TagItemMini diff --git a/themes/fukasawa/index.js b/themes/fukasawa/index.js index 4176ed1110a..3501aba0a5b 100644 --- a/themes/fukasawa/index.js +++ b/themes/fukasawa/index.js @@ -120,7 +120,7 @@ const LayoutPostList = props => {
- { POST_LIST_STYLE=== 'page' ? ( + {POST_LIST_STYLE === 'page' ? ( ) : ( @@ -141,27 +141,26 @@ const LayoutSlug = props => { useEffect(() => { // 404 if (!post) { - setTimeout( - () => { - if (isBrowser) { - const article = document.querySelector('#article-wrapper #notion-article') - if (!article) { - router.push('/404').then(() => { - console.warn('找不到页面', router.asPath) - }) - } + setTimeout(() => { + if (isBrowser) { + const article = document.querySelector( + '#article-wrapper #notion-article' + ) + if (!article) { + router.push('/404').then(() => { + console.warn('找不到页面', router.asPath) + }) } - }, - waiting404 - ) + } + }, waiting404) } }, [post]) return ( <> {lock ? ( - ) : post && ( - + ) : ( + post && )} ) @@ -228,16 +227,21 @@ const Layout404 = props => { }, 3000) }, []) - return <> -
-
-

404

-
-

{locale.NAV.PAGE_NOT_FOUND_REDIRECT}

-
-
+ return ( + <> +
+
+

+ + 404 +

+
+

{locale.NAV.PAGE_NOT_FOUND_REDIRECT}

+
+
+ ) } /** diff --git a/themes/fukasawa/style.js b/themes/fukasawa/style.js index bfb8bde6a36..866c5a0d5fe 100644 --- a/themes/fukasawa/style.js +++ b/themes/fukasawa/style.js @@ -5,55 +5,55 @@ * @returns */ const Style = () => { - return + .container { + display: grid; + grid-template-columns: repeat(3, 1fr); + grid-gap: 10px; + padding: 10px; + } + `} + ) } export { Style } - diff --git a/themes/game/components/AdBlockerDetect.js b/themes/game/components/AdBlockerDetect.js index 81f24d3910b..f7f495544c2 100644 --- a/themes/game/components/AdBlockerDetect.js +++ b/themes/game/components/AdBlockerDetect.js @@ -75,28 +75,27 @@ export default function AdBlockerDetect() { return ( <> -
-
-
-

+
+
+
+

Please allow ads on our site

-
-
-

+


+
+

{ "Looks like you're using an ad blocker. We rely on advertising to help fund our site." }

-
+
diff --git a/themes/game/components/ArticleLock.js b/themes/game/components/ArticleLock.js index 3a5f4b4c39c..0a2fa58dca8 100644 --- a/themes/game/components/ArticleLock.js +++ b/themes/game/components/ArticleLock.js @@ -29,25 +29,36 @@ export const ArticleLock = props => { passwordInputRef.current.focus() }, []) - return
-
-
{locale.COMMON.ARTICLE_LOCK_TIPS}
-
- { - if (e.key === 'Enter') { - submitPassword() - } - }} - ref={passwordInputRef} // 绑定ref到passwordInputRef变量 - className='outline-none w-full text-sm pl-5 rounded-l transition focus:shadow-lg font-light leading-10 text-black dark:bg-gray-500 bg-gray-50' - > -
-  {locale.COMMON.SUBMIT} -
-
-
-
+ return ( +
+
+
{locale.COMMON.ARTICLE_LOCK_TIPS}
+
+ { + if (e.key === 'Enter') { + submitPassword() + } + }} + ref={passwordInputRef} // 绑定ref到passwordInputRef变量 + className='outline-none w-full text-sm pl-5 rounded-l transition focus:shadow-lg font-light leading-10 text-black dark:bg-gray-500 bg-gray-50'> +
+ +  {locale.COMMON.SUBMIT} + +
+
+
+ ) } diff --git a/themes/game/components/ExampleRecentComments.js b/themes/game/components/ExampleRecentComments.js index 9dbdfa7f561..8b75282417b 100644 --- a/themes/game/components/ExampleRecentComments.js +++ b/themes/game/components/ExampleRecentComments.js @@ -8,7 +8,7 @@ import { RecentComments } from '@waline/client' * @param {*} props * @returns */ -const ExampleRecentComments = (props) => { +const ExampleRecentComments = props => { const [comments, updateComments] = useState([]) const [onLoading, changeLoading] = useState(true) useEffect(() => { @@ -21,15 +21,40 @@ const ExampleRecentComments = (props) => { }) }, []) - return <> - {onLoading &&
Loading...
} - {!onLoading && comments && comments.length === 0 &&
No Comments
} - {!onLoading && comments && comments.length > 0 && comments.map((comment) =>
-
-
--{comment.nick}
-
)} - - + return ( + <> + {onLoading && ( +
+ Loading... + +
+ )} + {!onLoading && comments && comments.length === 0 && ( +
No Comments
+ )} + {!onLoading && + comments && + comments.length > 0 && + comments.map(comment => ( +
+
+
+ + --{comment.nick} + +
+
+ ))} + + ) } export default ExampleRecentComments diff --git a/themes/game/components/FullScreenButton.js b/themes/game/components/FullScreenButton.js index d6374631b80..da588f06d63 100644 --- a/themes/game/components/FullScreenButton.js +++ b/themes/game/components/FullScreenButton.js @@ -13,7 +13,9 @@ export default function FullScreenButton() { inline: 'nearest' }) document?.getElementById('game-wrapper')?.contentWindow?.toggleFullScreen && - document?.getElementById('game-wrapper')?.contentWindow?.toggleFullScreen() + document + ?.getElementById('game-wrapper') + ?.contentWindow?.toggleFullScreen() } return ( @@ -25,7 +27,9 @@ export default function FullScreenButton() { title='full screen' className='cursor-pointer fas fa-expand group-hover:scale-125 transition-all duration-150 ' /> - FullScreen + + FullScreen +
) } diff --git a/themes/game/components/JumpToTopButton.js b/themes/game/components/JumpToTopButton.js index f5e22b61efc..85157ad84fb 100644 --- a/themes/game/components/JumpToTopButton.js +++ b/themes/game/components/JumpToTopButton.js @@ -10,9 +10,14 @@ import { useGlobal } from '@/lib/global' */ const JumpToTopButton = () => { const { locale } = useGlobal() - return
window.scrollTo({ top: 0, behavior: 'smooth' })} - > + return ( +
window.scrollTo({ top: 0, behavior: 'smooth' })}> +
+ ) } export default JumpToTopButton diff --git a/themes/game/components/LogoMini.js b/themes/game/components/LogoMini.js index b540e6e6fcb..809cd25f03a 100644 --- a/themes/game/components/LogoMini.js +++ b/themes/game/components/LogoMini.js @@ -4,7 +4,9 @@ import Link from 'next/link' /* eslint-disable @next/next/no-html-link-for-pages */ export default function LogoMini() { return ( - + {siteConfig('TITLE')?.charAt(0)} ) diff --git a/themes/game/components/PostInfo.js b/themes/game/components/PostInfo.js index 0e430765a06..e3b955c9696 100644 --- a/themes/game/components/PostInfo.js +++ b/themes/game/components/PostInfo.js @@ -26,7 +26,9 @@ export default function PostInfo(props) {

- {siteConfig('POST_TITLE_ICON') && } + {siteConfig('POST_TITLE_ICON') && ( + + )} {post?.title}

diff --git a/themes/game/components/RandomPostButton.js b/themes/game/components/RandomPostButton.js index a791f0f8354..cedf01867b2 100644 --- a/themes/game/components/RandomPostButton.js +++ b/themes/game/components/RandomPostButton.js @@ -19,8 +19,11 @@ export default function RandomPostButton(props) { } return ( -
- -
+
+ +
) } diff --git a/themes/game/components/SearchInput.js b/themes/game/components/SearchInput.js index 9f1ffdbe00e..1eaf354f9cf 100644 --- a/themes/game/components/SearchInput.js +++ b/themes/game/components/SearchInput.js @@ -23,14 +23,15 @@ const SearchInput = props => { // console.log('搜索', key) }) } else { - router.push({ pathname: '/' }).then(r => { - }) + router.push({ pathname: '/' }).then(r => {}) } } - const handleKeyUp = (e) => { - if (e.keyCode === 13) { // 回车 + const handleKeyUp = e => { + if (e.keyCode === 13) { + // 回车 handleSearch(searchInputRef.current.value) - } else if (e.keyCode === 27) { // ESC + } else if (e.keyCode === 27) { + // ESC cleanSearch() } } @@ -38,15 +39,15 @@ const SearchInput = props => { searchInputRef.current.value = '' setShowClean(false) } - function lockSearchInput () { + function lockSearchInput() { lock = true } - function unLockSearchInput () { + function unLockSearchInput() { lock = false } const [showClean, setShowClean] = useState(false) - const updateSearchKey = (val) => { + const updateSearchKey = val => { if (lock) { return } @@ -58,31 +59,45 @@ const SearchInput = props => { } } - return
- updateSearchKey(e.target.value)} - defaultValue={keyword || ''} - /> + return ( +
+ updateSearchKey(e.target.value)} + defaultValue={keyword || ''} + /> -
- -
+
+ +
- {(showClean && -
- -
- )} -
+ {showClean && ( +
+ +
+ )} +
+ ) } export default SearchInput diff --git a/themes/game/components/SideBar.js b/themes/game/components/SideBar.js index a4d1e060b65..51b7dc7b715 100644 --- a/themes/game/components/SideBar.js +++ b/themes/game/components/SideBar.js @@ -5,61 +5,77 @@ import Link from 'next/link' import dynamic from 'next/dynamic' const ExampleRecentComments = dynamic(() => import('./ExampleRecentComments')) -export const SideBar = (props) => { +export const SideBar = props => { const { locale } = useGlobal() const { latestPosts, categories } = props return ( -
+
+ + } + {siteConfig('COMMENT_WALINE_SERVER_URL') && + JSON.parse(siteConfig('COMMENT_WALINE_RECENT')) && ( + + )} -
- ); + +
+ ) } diff --git a/themes/game/components/SvgIcon.js b/themes/game/components/SvgIcon.js index 1ae326ca792..e7ff63b0037 100644 --- a/themes/game/components/SvgIcon.js +++ b/themes/game/components/SvgIcon.js @@ -1,29 +1,29 @@ export const SvgIcon = () => { - return - - - - - - - - + return ( + + + + + + + + + + ) } diff --git a/themes/game/components/Tags.js b/themes/game/components/Tags.js index bdab3ee585c..684793c3063 100644 --- a/themes/game/components/Tags.js +++ b/themes/game/components/Tags.js @@ -5,8 +5,8 @@ const Tags = props => { const currentTag = tag if (!tagOptions) return null return ( -
-
    +
    +
      {Object.keys(tagOptions).map(key => { const tag = tagOptions[key] const selected = tag.name === currentTag @@ -17,15 +17,14 @@ const Tags = props => { selected ? 'text-white bg-black border-black dark:bg-gray-600 dark:border-gray-600' : 'bg-gray-100 border-gray-100 text-gray-400 dark:bg-night dark:border-gray-800' - }`} - > + }`}> - + href={ + selected ? '/search' : `/tag/${encodeURIComponent(tag.name)}` + } + className='px-4 py-2 block'> {`${tag.name} (${tag.count})`} - ) diff --git a/themes/game/components/Title.js b/themes/game/components/Title.js index 151d736e4a3..4b2088f362c 100644 --- a/themes/game/components/Title.js +++ b/themes/game/components/Title.js @@ -5,15 +5,15 @@ import { siteConfig } from '@/lib/config' * @param {*} props * @returns */ -export const Title = (props) => { +export const Title = props => { const { post } = props const title = post?.title || siteConfig('DESCRIPTION') const description = post?.description || siteConfig('AUTHOR') - return
      -

      {title}

      -

      - {description} -

      + return ( +
      +

      {title}

      +

      {description}

      + ) } diff --git a/themes/gitbook/components/Announcement.js b/themes/gitbook/components/Announcement.js index 62df1ec2614..8a22fd28b1e 100755 --- a/themes/gitbook/components/Announcement.js +++ b/themes/gitbook/components/Announcement.js @@ -4,16 +4,22 @@ import dynamic from 'next/dynamic' const NotionPage = dynamic(() => import('@/components/NotionPage')) const Announcement = ({ notice, className }) => { -// const { locale } = useGlobal() + // const { locale } = useGlobal() if (notice?.blockMap) { - return
      -
      - {/*
      {locale.COMMON.ANNOUNCEMENT}
      */} - {notice && (
      - -
      )} + return ( +
      +
      + {/*
      {locale.COMMON.ANNOUNCEMENT}
      */} + {notice && ( +
      + +
      + )}
      -
      +
      + ) } else { return <> } diff --git a/themes/gitbook/components/Card.js b/themes/gitbook/components/Card.js index d24c046e476..8af8a70e570 100644 --- a/themes/gitbook/components/Card.js +++ b/themes/gitbook/components/Card.js @@ -1,9 +1,11 @@ const Card = ({ children, headerSlot, className }) => { - return
      - <>{headerSlot} -
      + return ( +
      + <>{headerSlot} +
      {children} -
      -
      +
      +
      + ) } export default Card diff --git a/themes/gitbook/components/CategoryGroup.js b/themes/gitbook/components/CategoryGroup.js index 71f40a0d566..1f89b8b726d 100644 --- a/themes/gitbook/components/CategoryGroup.js +++ b/themes/gitbook/components/CategoryGroup.js @@ -1,19 +1,30 @@ - import CategoryItem from './CategoryItem' const CategoryGroup = ({ currentCategory, categoryOptions }) => { if (!categoryOptions) { return <> } - return
      -
      分类
      -
      - {categoryOptions?.map(category => { - const selected = currentCategory === category.name - return - })} + return ( +
      +
      + + 分类 +
      +
      + {categoryOptions?.map(category => { + const selected = currentCategory === category.name + return ( + + ) + })} +
      -
      + ) } export default CategoryGroup diff --git a/themes/gitbook/components/CategoryItem.js b/themes/gitbook/components/CategoryItem.js index 779488debc3..001db456a07 100644 --- a/themes/gitbook/components/CategoryItem.js +++ b/themes/gitbook/components/CategoryItem.js @@ -1,18 +1,22 @@ import Link from 'next/link' -export default function CategoryItem ({ selected, category, categoryCount }) { +export default function CategoryItem({ selected, category, categoryCount }) { return ( - -
      {category} {categoryCount && `(${categoryCount})`} + className={ + (selected + ? 'hover:text-white dark:hover:text-white bg-green-600 text-white ' + : 'dark:text-green-400 text-gray-500 hover:text-white dark:hover:text-white hover:bg-green-600') + + ' flex text-sm items-center duration-300 cursor-pointer py-1 font-light px-2 whitespace-nowrap' + }> +
      + + {category} {categoryCount && `(${categoryCount})`}
      - - ); + ) } diff --git a/themes/gitbook/components/InfoCard.js b/themes/gitbook/components/InfoCard.js index 4b6e5cfe74e..88369e89e68 100644 --- a/themes/gitbook/components/InfoCard.js +++ b/themes/gitbook/components/InfoCard.js @@ -3,18 +3,33 @@ import Router from 'next/router' import SocialButton from './SocialButton' import { siteConfig } from '@/lib/config' -const InfoCard = (props) => { +const InfoCard = props => { const { siteInfo } = props - return
      -
      -
      { Router.push('/about') }}> - -
      -
      {siteConfig('AUTHOR')}
      -
      {siteConfig('BIO')}
      - + return ( +
      +
      +
      { + Router.push('/about') + }}> + +
      +
      + {siteConfig('AUTHOR')} +
      +
      + {siteConfig('BIO')} +
      + +
      -
      + ) } export default InfoCard diff --git a/themes/gitbook/components/LeftMenuBar.js b/themes/gitbook/components/LeftMenuBar.js index 6bde6c51b85..ce5183ef04a 100644 --- a/themes/gitbook/components/LeftMenuBar.js +++ b/themes/gitbook/components/LeftMenuBar.js @@ -1,15 +1,15 @@ import Link from 'next/link' -export default function LeftMenuBar () { +export default function LeftMenuBar() { return (
      - +
      - ); + ) } diff --git a/themes/gitbook/components/PaginationSimple.js b/themes/gitbook/components/PaginationSimple.js index b48259ea6a8..4f66a3673a7 100644 --- a/themes/gitbook/components/PaginationSimple.js +++ b/themes/gitbook/components/PaginationSimple.js @@ -14,10 +14,12 @@ const PaginationSimple = ({ page, totalPage }) => { const router = useRouter() const currentPage = +page const showNext = currentPage < totalPage - const pagePrefix = router.asPath.replace(/\/page\/[1-9]\d*/, '').replace(/\/$/, '') + const pagePrefix = router.asPath + .replace(/\/page\/[1-9]\d*/, '') + .replace(/\/$/, '') return ( -
      +
      { query: router.query.s ? { s: router.query.s } : {} }} passHref - rel="prev" + rel='prev' className={`${ currentPage === 1 ? 'invisible' : 'block' } text-center w-full duration-200 px-4 py-2 hover:border-green-500 border-b-2 hover:font-bold`}> ←{locale.PAGINATION.PREV} - { query: router.query.s ? { s: router.query.s } : {} }} passHref - rel="next" + rel='next' className={`${ +showNext ? 'block' : 'invisible' } text-center w-full duration-200 px-4 py-2 hover:border-green-500 border-b-2 hover:font-bold`}> - {locale.PAGINATION.NEXT}→
      diff --git a/themes/gitbook/components/Progress.js b/themes/gitbook/components/Progress.js index 29feef49738..9517e60f5d4 100644 --- a/themes/gitbook/components/Progress.js +++ b/themes/gitbook/components/Progress.js @@ -10,7 +10,8 @@ const Progress = ({ targetRef, showPercent = true }) => { const currentRef = targetRef?.current || targetRef const [percent, changePercent] = useState(0) const scrollListener = () => { - const target = currentRef || (isBrowser && document.getElementById('posts-wrapper')) + const target = + currentRef || (isBrowser && document.getElementById('posts-wrapper')) if (target) { const clientHeight = target.clientHeight const scrollY = window.pageYOffset @@ -28,13 +29,12 @@ const Progress = ({ targetRef, showPercent = true }) => { }, []) return ( -
      +
      + className='h-4 bg-gray-600 duration-200' + style={{ width: `${percent}%` }}> {showPercent && ( -
      {percent}%
      +
      {percent}%
      )}
      diff --git a/themes/gitbook/components/RevolverMaps.js b/themes/gitbook/components/RevolverMaps.js index c6eb62528ae..138e3243f3d 100644 --- a/themes/gitbook/components/RevolverMaps.js +++ b/themes/gitbook/components/RevolverMaps.js @@ -1,6 +1,6 @@ import { useEffect, useState } from 'react' -export default function RevolverMaps () { +export default function RevolverMaps() { const [load, changeLoad] = useState(false) useEffect(() => { if (!load) { @@ -8,13 +8,15 @@ export default function RevolverMaps () { changeLoad(true) } }, []) - return
      + return
      } -function initRevolverMaps () { +function initRevolverMaps() { if (screen.width >= 768) { Promise.all([ - loadExternalResource('https://rf.revolvermaps.com/0/0/8.js?i=5jnp1havmh9&m=0&c=ff0000&cr1=ffffff&f=arial&l=33') + loadExternalResource( + 'https://rf.revolvermaps.com/0/0/8.js?i=5jnp1havmh9&m=0&c=ff0000&cr1=ffffff&f=arial&l=33' + ) ]).then(() => { console.log('地图加载完成') }) @@ -22,7 +24,7 @@ function initRevolverMaps () { } // 封装异步加载资源的方法 -function loadExternalResource (url) { +function loadExternalResource(url) { return new Promise((resolve, reject) => { const container = document.getElementById('revolvermaps') const tag = document.createElement('script') diff --git a/themes/gitbook/components/TagGroups.js b/themes/gitbook/components/TagGroups.js index 390a6306f3a..041f01371b9 100644 --- a/themes/gitbook/components/TagGroups.js +++ b/themes/gitbook/components/TagGroups.js @@ -11,14 +11,15 @@ const TagGroups = ({ tagOptions, currentTag }) => { if (!tagOptions) return <> return (
      -
      标签
      +
      + + 标签 +
      - { - tagOptions?.map(tag => { - const selected = tag.name === currentTag - return - }) - } + {tagOptions?.map(tag => { + const selected = tag.name === currentTag + return + })}
      ) diff --git a/themes/gitbook/components/TagItemMini.js b/themes/gitbook/components/TagItemMini.js index 9922a069327..e1a44e4fb8b 100644 --- a/themes/gitbook/components/TagItemMini.js +++ b/themes/gitbook/components/TagItemMini.js @@ -8,12 +8,15 @@ const TagItemMini = ({ tag, selected = false }) => { passHref className={`cursor-pointer inline-block rounded hover:bg-gray-500 hover:text-white duration-200 mr-2 py-1 px-2 text-xs whitespace-nowrap dark:hover:text-white - ${selected - ? 'text-white dark:text-gray-300 bg-black dark:bg-black dark:hover:bg-gray-900' - : `text-gray-600 hover:shadow-xl dark:border-gray-400 notion-${tag.color}_background dark:bg-gray-800`}` }> - -
      {selected && } {tag.name + (tag.count ? `(${tag.count})` : '')}
      - + ${ + selected + ? 'text-white dark:text-gray-300 bg-black dark:bg-black dark:hover:bg-gray-900' + : `text-gray-600 hover:shadow-xl dark:border-gray-400 notion-${tag.color}_background dark:bg-gray-800` + }`}> +
      + {selected && }{' '} + {tag.name + (tag.count ? `(${tag.count})` : '')}{' '} +
      ) } diff --git a/themes/gitbook/index.js b/themes/gitbook/index.js index 13014b72830..a074c560843 100644 --- a/themes/gitbook/index.js +++ b/themes/gitbook/index.js @@ -320,21 +320,18 @@ const LayoutSlug = props => { useEffect(() => { // 404 if (!post) { - setTimeout( - () => { - if (isBrowser) { - const article = document.querySelector( - '#article-wrapper #notion-article' - ) - if (!article) { - router.push('/404').then(() => { - console.warn('找不到页面', router.asPath) - }) - } + setTimeout(() => { + if (isBrowser) { + const article = document.querySelector( + '#article-wrapper #notion-article' + ) + if (!article) { + router.push('/404').then(() => { + console.warn('找不到页面', router.asPath) + }) } - }, - waiting404 - ) + } + }, waiting404) } }, [post]) return ( @@ -451,16 +448,21 @@ const Layout404 = props => { }, 3000) }, []) - return <> -
      -
      -

      404

      -
      -

      {locale.NAV.PAGE_NOT_FOUND_REDIRECT}

      -
      -
      + return ( + <> +
      +
      +

      + + 404 +

      +
      +

      {locale.NAV.PAGE_NOT_FOUND_REDIRECT}

      +
      +
      + ) } /** @@ -609,18 +611,17 @@ const LayoutDashboard = props => { } export { - Layout404, - LayoutArchive, - LayoutBase, - LayoutCategoryIndex, - LayoutDashboard, - LayoutIndex, - LayoutPostList, - LayoutSearch, - LayoutSignIn, - LayoutSignUp, - LayoutSlug, - LayoutTagIndex, - CONFIG as THEME_CONFIG + Layout404, + LayoutArchive, + LayoutBase, + LayoutCategoryIndex, + LayoutDashboard, + LayoutIndex, + LayoutPostList, + LayoutSearch, + LayoutSignIn, + LayoutSignUp, + LayoutSlug, + LayoutTagIndex, + CONFIG as THEME_CONFIG } - diff --git a/themes/heo/components/AnalyticsCard.js b/themes/heo/components/AnalyticsCard.js index a6c17e8816d..a9c916fdb2a 100644 --- a/themes/heo/components/AnalyticsCard.js +++ b/themes/heo/components/AnalyticsCard.js @@ -17,32 +17,34 @@ export function AnalyticsCard(props) { const siteVisitorTitle = siteConfig('HEO_SITE_VISITOR_TITLE', null, CONFIG) const { postCount } = props - return <> -
      -
      -
      -
      {postCountTitle}
      -
      {postCount}
      -
      -
      -
      -
      -
      {siteTimeTitle}
      -
      {diffDays} 天
      -
      -
      -
      -
      -
      {siteVisitTitle}
      -
      -
      -
      -
      -
      -
      {siteVisitorTitle}
      -
      -
      -
      + return ( + <> +
      +
      +
      +
      {postCountTitle}
      +
      {postCount}
      +
      - +
      +
      +
      {siteTimeTitle}
      +
      {diffDays} 天
      +
      +
      +
      +
      +
      {siteVisitTitle}
      +
      +
      +
      +
      +
      +
      {siteVisitorTitle}
      +
      +
      +
      +
      + + ) } diff --git a/themes/heo/components/BlogPostCard.js b/themes/heo/components/BlogPostCard.js index c6e09f4a537..fb00edb3f62 100644 --- a/themes/heo/components/BlogPostCard.js +++ b/themes/heo/components/BlogPostCard.js @@ -83,9 +83,9 @@ const BlogPostCard = ({ index, post, showSummary, siteInfo }) => { }> {siteConfig('POST_TITLE_ICON') && ( + icon={post.pageIcon} + className='heo-icon w-6 h-6 mr-1 align-middle transform translate-y-[-8%]' // 专门为 Heo 主题的图标设置样式 + /> )} {post.title} diff --git a/themes/heo/components/BlogPostListEmpty.js b/themes/heo/components/BlogPostListEmpty.js index 5f75c3e7d0b..dc2a9c17ef3 100644 --- a/themes/heo/components/BlogPostListEmpty.js +++ b/themes/heo/components/BlogPostListEmpty.js @@ -7,8 +7,12 @@ import { useGlobal } from '@/lib/global' */ const BlogPostListEmpty = ({ currentSearch }) => { const { locale } = useGlobal() - return
      -
      {locale.COMMON.NO_MORE} {(currentSearch &&
      {currentSearch}
      )}
      -
      + return ( +
      +
      + {locale.COMMON.NO_MORE} {currentSearch &&
      {currentSearch}
      } +
      +
      + ) } export default BlogPostListEmpty diff --git a/themes/heo/components/Card.js b/themes/heo/components/Card.js index 0859dec0159..759248450e3 100644 --- a/themes/heo/components/Card.js +++ b/themes/heo/components/Card.js @@ -1,9 +1,10 @@ const Card = ({ children, headerSlot, className }) => { - return
      - <>{headerSlot} -
      - {children} -
      -
      + return ( +
      + <>{headerSlot} +
      {children}
      +
      + ) } export default Card diff --git a/themes/heo/components/CategoryGroup.js b/themes/heo/components/CategoryGroup.js index 21915d720bb..2e1cfd48b2e 100644 --- a/themes/heo/components/CategoryGroup.js +++ b/themes/heo/components/CategoryGroup.js @@ -4,27 +4,37 @@ const CategoryGroup = ({ currentCategory, categories }) => { if (!categories) { return <> } - return <> -
      - {categories.map(category => { - const selected = currentCategory === category.name - return ( - - -
      {category.name}({category.count})
      - - - ) - })} -
      - + return ( + <> +
      + {categories.map(category => { + const selected = currentCategory === category.name + return ( + +
      + {' '} + + {category.name}({category.count}) +
      + + ) + })} +
      + + ) } export default CategoryGroup diff --git a/themes/heo/components/DarkModeButton.js b/themes/heo/components/DarkModeButton.js index bef62962a0c..63403f50afd 100644 --- a/themes/heo/components/DarkModeButton.js +++ b/themes/heo/components/DarkModeButton.js @@ -6,7 +6,7 @@ import { useImperativeHandle } from 'react' /** * 深色模式按钮 */ -const DarkModeButton = (props) => { +const DarkModeButton = props => { const { cRef, className } = props const { isDarkMode, updateDarkMode } = useGlobal() @@ -31,8 +31,17 @@ const DarkModeButton = (props) => { htmlElement.classList?.add(newStatus ? 'dark' : 'light') } - return
      -
      {isDarkMode ? : }
      -
      + return ( +
      +
      + {' '} + {isDarkMode ? : } +
      +
      + ) } export default DarkModeButton diff --git a/themes/heo/components/FloatDarkModeButton.js b/themes/heo/components/FloatDarkModeButton.js index 0918093bee5..b9c7609e83d 100644 --- a/themes/heo/components/FloatDarkModeButton.js +++ b/themes/heo/components/FloatDarkModeButton.js @@ -3,7 +3,7 @@ import { saveDarkModeToLocalStorage } from '@/themes/theme' import CONFIG from '../config' import { siteConfig } from '@/lib/config' -export default function FloatDarkModeButton () { +export default function FloatDarkModeButton() { const { isDarkMode, updateDarkMode } = useGlobal() if (!siteConfig('HEO_WIDGET_DARK_MODE', null, CONFIG)) { @@ -23,10 +23,13 @@ export default function FloatDarkModeButton () { return (
      - + className={ + 'justify-center items-center w-7 h-7 text-center transform hover:scale-105 duration-200' + }> +
      ) } diff --git a/themes/heo/components/FloatTocButton.js b/themes/heo/components/FloatTocButton.js index 7ce1eda0743..1c567d9b8e4 100644 --- a/themes/heo/components/FloatTocButton.js +++ b/themes/heo/components/FloatTocButton.js @@ -18,27 +18,40 @@ export default function FloatTocButton(props) { return <> } - return (
      - {/* 按钮 */} -
      -
      + return ( +
      + {/* 按钮 */} +
      +
      - {/* 目录Modal */} -
      - {/* 侧边菜单 */} -
      - {post && <> -
      - -
      - - } -
      + {/* 目录Modal */} +
      + {/* 侧边菜单 */} +
      + {post && ( + <> +
      + +
      + + )}
      - {/* 背景蒙版 */} -
      -
      ) +
      + {/* 背景蒙版 */} +
      +
      + ) } diff --git a/themes/heo/components/JumpToCommentButton.js b/themes/heo/components/JumpToCommentButton.js index 3fa53a36edc..ec52d61543d 100644 --- a/themes/heo/components/JumpToCommentButton.js +++ b/themes/heo/components/JumpToCommentButton.js @@ -13,7 +13,10 @@ const JumpToCommentButton = () => { function navToComment() { if (document.getElementById('comment')) { - window.scrollTo({ top: document.getElementById('comment').offsetTop, behavior: 'smooth' }) + window.scrollTo({ + top: document.getElementById('comment').offsetTop, + behavior: 'smooth' + }) } // 兼容性不好 // const commentElement = document.getElementById('comment') @@ -21,9 +24,13 @@ const JumpToCommentButton = () => { // commentElement?.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'nearest' }) } - return (
      - -
      ) + return ( +
      + +
      + ) } export default JumpToCommentButton diff --git a/themes/heo/components/JumpToTopButton.js b/themes/heo/components/JumpToTopButton.js index 0c775dac178..538b0cd3891 100644 --- a/themes/heo/components/JumpToTopButton.js +++ b/themes/heo/components/JumpToTopButton.js @@ -16,10 +16,16 @@ const JumpToTopButton = ({ showPercent = true, percent }) => { if (!siteConfig('HEO_WIDGET_TO_TOP', null, CONFIG)) { return <> } - return (
      window.scrollTo({ top: 0, behavior: 'smooth' })} > -
      - {showPercent && (
      {percent}
      )} -
      ) + return ( +
      window.scrollTo({ top: 0, behavior: 'smooth' })}> +
      + +
      + {showPercent &&
      {percent}
      } +
      + ) } export default JumpToTopButton diff --git a/themes/heo/components/LatestPostsGroupMini.js b/themes/heo/components/LatestPostsGroupMini.js index 32094157bc9..f5df1abf761 100644 --- a/themes/heo/components/LatestPostsGroupMini.js +++ b/themes/heo/components/LatestPostsGroupMini.js @@ -26,8 +26,7 @@ export default function LatestPostsGroupMini({ latestPosts, siteInfo }) {
      {latestPosts.map(post => { - const selected = - currentPath === `${SUB_PATH}/${post.slug}` + const selected = currentPath === `${SUB_PATH}/${post.slug}` const headerImage = post?.pageCoverThumbnail ? post.pageCoverThumbnail : siteInfo?.pageCover diff --git a/themes/heo/components/NavButtonGroup.js b/themes/heo/components/NavButtonGroup.js index 823318524f2..156bd91c745 100644 --- a/themes/heo/components/NavButtonGroup.js +++ b/themes/heo/components/NavButtonGroup.js @@ -5,14 +5,18 @@ import Link from 'next/link' * @param {*} props * @returns */ -const NavButtonGroup = (props) => { +const NavButtonGroup = props => { const { categoryOptions } = props if (!categoryOptions || categoryOptions.length === 0) { return <> } return ( -

-
@@ -103,4 +117,4 @@ export const Blog = ({ posts }) => { {/* */} ) -} \ No newline at end of file +} diff --git a/themes/proxio/components/Brand.js b/themes/proxio/components/Brand.js index 032c3d1bd36..226209af1bb 100644 --- a/themes/proxio/components/Brand.js +++ b/themes/proxio/components/Brand.js @@ -42,14 +42,12 @@ export const Brand = () => {
+ ref={scrollContainerRef}>
{brands?.map((item, index) => ( + className='mx-8 text-lg font-semibold text-gray-700 dark:text-gray-300'> {item} ))} @@ -57,8 +55,7 @@ export const Brand = () => { {brands.map((item, index) => ( + className='mx-8 text-lg font-semibold text-gray-700 dark:text-gray-300'> {item} ))} @@ -68,4 +65,4 @@ export const Brand = () => { {/* */} ) -} \ No newline at end of file +} diff --git a/themes/proxio/components/CTA.js b/themes/proxio/components/CTA.js index ce9803295af..f0e2020cee3 100644 --- a/themes/proxio/components/CTA.js +++ b/themes/proxio/components/CTA.js @@ -19,14 +19,15 @@ export const CTA = () => {
-
+
{siteConfig('PROXIO_CTA_TITLE')}

- {siteConfig('PROXIO_CTA_TITLE_2')} @@ -48,7 +49,6 @@ export const CTA = () => {

-
{/* */} diff --git a/themes/proxio/components/Career.js b/themes/proxio/components/Career.js index 162abb40173..49db548626b 100644 --- a/themes/proxio/components/Career.js +++ b/themes/proxio/components/Career.js @@ -22,9 +22,9 @@ export const Career = () => { {siteConfig('PROXIO_CAREER_TITLE')} -

{siteConfig('PROXIO_CAREER_TEXT')}

+

+ {siteConfig('PROXIO_CAREER_TEXT')} +

@@ -41,22 +41,21 @@ export const Career = () => { ) } - // 生涯内容 const CareerItem = ({ title, bio, text }) => { - return
-
-

- {title} - {bio} -

- -
-
-

- {text} -

+ return ( +
+
+

+ {title} + {bio} +

+
+
+

{text}

+
-
- -} \ No newline at end of file + ) +} diff --git a/themes/proxio/components/DarkModeButton.js b/themes/proxio/components/DarkModeButton.js index 9d4ceef1713..aab76b243db 100644 --- a/themes/proxio/components/DarkModeButton.js +++ b/themes/proxio/components/DarkModeButton.js @@ -1,84 +1,64 @@ -import { useGlobal } from '@/lib/global'; -import { useRouter } from 'next/router'; +import { useGlobal } from '@/lib/global' +import { useRouter } from 'next/router' export const DarkModeButton = () => { const { toggleDarkMode } = useGlobal() const router = useRouter() - return <> - + ) } diff --git a/themes/proxio/components/FAQ.js b/themes/proxio/components/FAQ.js index eb26b91f32d..0d65d9c56af 100644 --- a/themes/proxio/components/FAQ.js +++ b/themes/proxio/components/FAQ.js @@ -11,27 +11,27 @@ export const FAQ = () => { const [openIndex, setOpenIndex] = useState(null) - const toggleFAQ = (index) => { + const toggleFAQ = index => { setOpenIndex(openIndex === index ? null : index) } return ( <> {/* */} -
+
-
-
-
+
+
+
{siteConfig('PROXIO_FAQ_TITLE')}
-

+

{siteConfig('PROXIO_FAQ_TEXT_1')}

-

+

{siteConfig('PROXIO_FAQ_TEXT_2')}

@@ -39,30 +39,32 @@ export const FAQ = () => {
{/* FAQ 列表 */} -
+
{FAQS?.map((faq, index) => (
toggleFAQ(index)} - > -
+ className='w-full px-4 cursor-pointer' + onClick={() => toggleFAQ(index)}> +
{/* 问题部分 */} -
-

+
+

{faq.q}

{/* 答案部分 */}
+ className={`mt-4 text-base text-body-color dark:text-dark-6 transition-all duration-300 overflow-hidden ${ + openIndex === index ? 'max-h-screen' : 'max-h-0' + }`} + dangerouslySetInnerHTML={{ __html: faq.a }}>

))} @@ -71,10 +73,10 @@ export const FAQ = () => { {/* 背景图案 */}
- + - +
@@ -82,4 +84,4 @@ export const FAQ = () => { {/* */} ) -} \ No newline at end of file +} diff --git a/themes/proxio/components/Features.js b/themes/proxio/components/Features.js index 6f932fd654e..a0b10acf87c 100644 --- a/themes/proxio/components/Features.js +++ b/themes/proxio/components/Features.js @@ -15,8 +15,9 @@ export const Features = () => { {/* */}
- -
+
@@ -33,13 +34,20 @@ export const Features = () => {
{/* 支持三个特性 */}
-
-
+
- - + +

@@ -52,11 +60,16 @@ export const Features = () => {

-
+
- +

@@ -69,11 +82,16 @@ export const Features = () => {

-
+
- +

@@ -84,7 +102,6 @@ export const Features = () => {

-
@@ -92,7 +109,7 @@ export const Features = () => { href={siteConfig('PROXIO_FEATURE_BUTTON_URL', '')} className='px-4 py-2 rounded-3xl border dark:border-gray-200 border-[#333333] text-base font-medium text-dark hover:bg-gray-100 dark:text-white dark:hover:bg-white dark:hover:text-black duration-200'> {siteConfig('PROXIO_FEATURE_BUTTON_TEXT')} - +
diff --git a/themes/proxio/components/Footer.js b/themes/proxio/components/Footer.js index 383d7894d3b..113e6114075 100644 --- a/themes/proxio/components/Footer.js +++ b/themes/proxio/components/Footer.js @@ -34,8 +34,7 @@ export const Footer = ({ title }) => { alt={siteConfig('AUTHOR')} />

{title}

- + {siteConfig('AUTHOR')}
@@ -55,7 +54,9 @@ export const Footer = ({ title }) => { {group?.menus?.map((menu, index) => { return (
- + {menu.title}
@@ -93,4 +94,4 @@ export const Footer = ({ title }) => {
) -} \ No newline at end of file +} diff --git a/themes/proxio/components/Header.js b/themes/proxio/components/Header.js index ed8ca5b4578..ee8f24657bc 100644 --- a/themes/proxio/components/Header.js +++ b/themes/proxio/components/Header.js @@ -15,57 +15,57 @@ import { MenuList } from './MenuList' * 顶部导航栏 */ export const Header = props => { - const router = useRouter() - const { isDarkMode } = useGlobal() - const [buttonTextColor, setColor] = useState( - router.route === '/' ? 'text-white' : '' - ) + const router = useRouter() + const { isDarkMode } = useGlobal() + const [buttonTextColor, setColor] = useState( + router.route === '/' ? 'text-white' : '' + ) - useEffect(() => { - if (isDarkMode || router.route === '/') { - setColor('text-white') - } else { - setColor('') - } - // ======= Sticky - // window.addEventListener('scroll', navBarScollListener) - // return () => { - // window.removeEventListener('scroll', navBarScollListener) - // } - }, [isDarkMode]) + useEffect(() => { + if (isDarkMode || router.route === '/') { + setColor('text-white') + } else { + setColor('') + } + // ======= Sticky + // window.addEventListener('scroll', navBarScollListener) + // return () => { + // window.removeEventListener('scroll', navBarScollListener) + // } + }, [isDarkMode]) - // 滚动监听 - const throttleMs = 200 - // const navBarScollListener = useCallback( - // throttle(() => { - // // eslint-disable-next-line camelcase - // const ud_header = document.querySelector('.ud-header') - // const scrollY = window.scrollY - // // 控制台输出当前滚动位置和 sticky 值 - // if (scrollY > 0) { - // ud_header?.classList?.add('sticky') - // } else { - // ud_header?.classList?.remove('sticky') - // } - // }, throttleMs) - // ) + // 滚动监听 + const throttleMs = 200 + // const navBarScollListener = useCallback( + // throttle(() => { + // // eslint-disable-next-line camelcase + // const ud_header = document.querySelector('.ud-header') + // const scrollY = window.scrollY + // // 控制台输出当前滚动位置和 sticky 值 + // if (scrollY > 0) { + // ud_header?.classList?.add('sticky') + // } else { + // ud_header?.classList?.remove('sticky') + // } + // }, throttleMs) + // ) - return ( - <> - {/* */} -
-
-
- {/* Logo */} - - {/* 右侧菜单 */} -
- -
-
-
+ return ( + <> + {/* */} +
+
+
+ {/* Logo */} + + {/* 右侧菜单 */} +
+
- {/* */} - - ) +
+
+
+ {/* */} + + ) } diff --git a/themes/proxio/components/Hero.js b/themes/proxio/components/Hero.js index 580ca70ac6e..7d72b5270ae 100644 --- a/themes/proxio/components/Hero.js +++ b/themes/proxio/components/Hero.js @@ -8,65 +8,67 @@ import Link from 'next/link' * 英雄大图区块 */ export const Hero = props => { - const config = props?.NOTION_CONFIG || CONFIG - const pageCover = props?.siteInfo?.pageCover - const bannerImage = siteConfig('PROXIO_HERO_BANNER_IMAGE', null, config) || pageCover - const bannerIframe = siteConfig('PROXIO_HERO_BANNER_IFRAME_URL',null,config) - return ( - <> - {/* */} + const config = props?.NOTION_CONFIG || CONFIG + const pageCover = props?.siteInfo?.pageCover + const bannerImage = + siteConfig('PROXIO_HERO_BANNER_IMAGE', null, config) || pageCover + const bannerIframe = siteConfig('PROXIO_HERO_BANNER_IFRAME_URL', null, config) + return ( + <> + {/* */} +
+ {/* 横幅图片 */} + {!bannerIframe && bannerImage && ( + + )} +