From 1e7b9e260a27b750aba2d1514d2a503e565ce823 Mon Sep 17 00:00:00 2001 From: txs Date: Mon, 18 Apr 2022 23:57:41 +0800 Subject: [PATCH] Add Facebook fanpage sidebar --- blog.config.js | 6 +++- components/FacebookPage.js | 27 ++++++++++++++++ package.json | 2 ++ themes/hexo/LayoutBase.js | 63 +++++++++++++++++++++++--------------- 4 files changed, 72 insertions(+), 26 deletions(-) create mode 100644 components/FacebookPage.js diff --git a/blog.config.js b/blog.config.js index c19986fe..3a4a12b3 100644 --- a/blog.config.js +++ b/blog.config.js @@ -12,7 +12,11 @@ const BLOG = { FACEBOOK_PAGE_ID: process.env.NEXT_PUBLIC_FACEBOOK_PAGE_ID || '', // Facebook Page ID 來啟用 messenger 聊天功能 FACEBOOK_APP_ID: process.env.NEXT_PUBLIC_FACEBOOK_APP_ID || '', // Facebook App ID 來啟用 messenger 聊天功能 - FACEBOOK_PAGE: process.env.NEXT_PUBLIC_FACEBOOK_PAGE || 'https://www.facebook.com/tw.andys.pro', // Facebook Page 的連結 + FACEBOOK_PAGE_TITLE: + process.env.NEXT_PUBLIC_FACEBOOK_PAGE_TITLE || 'FACEBOOK 粉絲團', // 邊欄 Facebook Page widget 的標題欄,填''則無標題欄 + FACEBOOK_PAGE: + process.env.NEXT_PUBLIC_FACEBOOK_PAGE || + 'https://www.facebook.com/tw.andys.pro', // Facebook Page 的連結 THEME: process.env.NEXT_PUBLIC_THEME || 'next', // 主题, 支持 ['next','hexo',"fukasawa','medium'] THEME_SWITCH: process.env.NEXT_PUBLIC_THEME_SWITCH || false, // 是否显示切换主题按钮 diff --git a/components/FacebookPage.js b/components/FacebookPage.js new file mode 100644 index 00000000..eda8a7df --- /dev/null +++ b/components/FacebookPage.js @@ -0,0 +1,27 @@ +import BLOG from '@/blog.config' +import { FacebookProvider, Page } from 'react-facebook' +import { FacebookIcon } from 'react-share' + +const FacebookPage = () => ( +
+ {BLOG.FACEBOOK_PAGE_TITLE && ( +
+ + + + + {BLOG.FACEBOOK_PAGE_TITLE} + +
+ )} + + + +
+) +export default FacebookPage diff --git a/package.json b/package.json index 8099bf59..4b43b284 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,10 @@ "react-cookies": "^0.1.1", "react-cusdis": "^2.1.3", "react-dom": "17.0.2", + "react-facebook": "^8.1.4", "react-messenger-customer-chat": "^0.8.0", "react-notion-x": "6.6.2", + "react-share": "^4.4.0", "smoothscroll-polyfill": "^0.4.4", "typed.js": "^2.0.12", "use-ackee": "^3.0.0" diff --git a/themes/hexo/LayoutBase.js b/themes/hexo/LayoutBase.js index 7b12a3f4..6d78abee 100644 --- a/themes/hexo/LayoutBase.js +++ b/themes/hexo/LayoutBase.js @@ -11,6 +11,7 @@ import Live2D from '@/components/Live2D' import LoadingCover from './components/LoadingCover' import { useGlobal } from '@/lib/global' import BLOG from '@/blog.config' +import FacebookPage from '@/components/FacebookPage' /** * 基础布局 采用左右两侧布局,移动端使用顶部导航栏 @@ -18,11 +19,16 @@ import BLOG from '@/blog.config' * @returns {JSX.Element} * @constructor */ -const LayoutBase = (props) => { +const LayoutBase = props => { const { children, headerSlot, floatSlot, meta, siteInfo } = props const [show, switchShow] = useState(false) // const [percent, changePercent] = useState(0) // 页面阅读百分比 - const rightAreaSlot = + const rightAreaSlot = ( + <> + + + + ) const { onLoading } = useGlobal() const scrollListener = () => { @@ -30,7 +36,7 @@ const LayoutBase = (props) => { const clientHeight = targetRef?.clientHeight const scrollY = window.pageYOffset const fullHeight = clientHeight - window.outerHeight - let per = parseFloat(((scrollY / fullHeight * 100)).toFixed(0)) + let per = parseFloat(((scrollY / fullHeight) * 100).toFixed(0)) if (per > 100) per = 100 const shouldShow = scrollY > 100 && per > 0 @@ -45,37 +51,44 @@ const LayoutBase = (props) => { return () => document.removeEventListener('scroll', scrollListener) }, [show]) - return (
- + return ( +
+ - + - {headerSlot} + {headerSlot} -
+
+
+
+ {onLoading ? : children} +
-
-
- {onLoading ? : children} +
+
- + {/* 右下角悬浮 */} +
+
+ + {floatSlot} + +
-
- - {/* 右下角悬浮 */} -
-
- - {floatSlot} - -
+
- -
) + ) } export default LayoutBase