diff --git a/blog.config.js b/blog.config.js
index 1b01e9dc..fa0fad99 100644
--- a/blog.config.js
+++ b/blog.config.js
@@ -96,7 +96,9 @@ const BLOG = {
BACKGROUND_DARK: '#000000', // use hex value, don't forget '#'
SUB_PATH: '', // leave this empty unless you want to deploy in a folder
- POST_SHARE_BAR_ENABLE: process.env.NEXT_PUBLIC_POST_SHARE_BAR || 'false', // 文章分享功能 ,将在底部显示一个分享条
+ POST_SHARE_BAR_ENABLE: process.env.NEXT_PUBLIC_POST_SHARE_BAR || 'true', // 文章分享功能 ,将在底部显示一个分享条
+ POSTS_SHARE_SERVICES: process.env.NEXT_PUBLIC_POST_SHARE_SERVICES || 'link,wechat,qq,weibo,email,facebook,twitter,telegram,messenger,line,reddit,whatsapp,linkedin', // 分享的服務,选填逗号隔开
+ // 所有支持的分享服务:link(复制链接),wechat(微信),qq,weibo(微博),email(邮件),facebook,twitter,telegram,messenger,line,reddit,whatsapp,linkedin,vkshare,okshare,tumblr,livejournal,mailru,viber,workplace,pocket,instapaper,hatena
POST_URL_PREFIX: process.env.NEXT_PUBLIC_POST_URL_PREFIX || 'article',
// POST类型文章的默认路径前缀,例如默认POST类型的路径是 /article/[slug]
diff --git a/components/ShareBar.js b/components/ShareBar.js
index 97f46395..1cf57776 100644
--- a/components/ShareBar.js
+++ b/components/ShareBar.js
@@ -1,15 +1,10 @@
import BLOG from '@/blog.config'
import { useRouter } from 'next/router'
import React from 'react'
-import { createPopper } from '@popperjs/core'
-import copy from 'copy-to-clipboard'
-import QRCode from 'qrcode.react'
-import { useGlobal } from '@/lib/global'
+import ShareButtons from './ShareButtons'
const ShareBar = ({ post }) => {
const router = useRouter()
- const [qrCodeShow, setQrCodeShow] = React.useState(false)
- const { locale } = useGlobal()
if (!JSON.parse(BLOG.POST_SHARE_BAR_ENABLE) || !post || post?.type !== 'Post') {
return <>>
@@ -17,71 +12,16 @@ const ShareBar = ({ post }) => {
const shareUrl = BLOG.LINK + router.asPath
- // 二维码悬浮
- const btnRef = React.createRef()
- const popoverRef = React.createRef()
-
- const openPopover = () => {
- createPopper(btnRef.current, popoverRef.current, {
- placement: 'top'
- })
- setQrCodeShow(true)
- }
- const closePopover = () => {
- setQrCodeShow(false)
- }
-
- const copyUrl = () => {
- copy(shareUrl)
- alert(locale.COMMON.URL_COPIED)
- }
-
- return
-
{locale.COMMON.SHARE}:
-
-
-
-
-
-
-
+ return
+
}
export default ShareBar
diff --git a/components/ShareButton.js b/components/ShareButton.js
deleted file mode 100644
index 39fea1f2..00000000
--- a/components/ShareButton.js
+++ /dev/null
@@ -1,34 +0,0 @@
-import React from 'react'
-import ShareBar from './ShareBar'
-
-/**
- * 悬浮在屏幕右下角,分享按钮
- * @returns {JSX.Element}
- * @constructor
- */
-const ShareButton = ({ post }) => {
- const [popoverShow, setPopoverShow] = React.useState(false)
- const btnRef = React.createRef()
-
- const openPopover = () => {
- setPopoverShow(true)
- }
- const closePopover = () => {
- setPopoverShow(false)
- }
- return (
-
{ openPopover() }}
- onMouseLeave={() => { closePopover() }}>
-
-
-
-
-
-
-
- )
-}
-
-export default ShareButton
diff --git a/components/ShareButtons.js b/components/ShareButtons.js
new file mode 100644
index 00000000..cc686d55
--- /dev/null
+++ b/components/ShareButtons.js
@@ -0,0 +1,370 @@
+import BLOG from '@/blog.config'
+import { useGlobal } from '@/lib/global'
+import copy from 'copy-to-clipboard'
+import QRCode from 'qrcode.react'
+import { useState } from 'react'
+
+import {
+ FacebookShareButton,
+ FacebookIcon,
+ FacebookMessengerShareButton,
+ FacebookMessengerIcon,
+ RedditShareButton,
+ RedditIcon,
+ LineShareButton,
+ LineIcon,
+ EmailShareButton,
+ EmailIcon,
+ TwitterShareButton,
+ TwitterIcon,
+ TelegramShareButton,
+ TelegramIcon,
+ WhatsappShareButton,
+ WhatsappIcon,
+ LinkedinShareButton,
+ LinkedinIcon,
+ PinterestShareButton,
+ PinterestIcon,
+ VKIcon,
+ VKShareButton,
+ OKShareButton,
+ OKIcon,
+ TumblrShareButton,
+ TumblrIcon,
+ LivejournalIcon,
+ LivejournalShareButton,
+ MailruShareButton,
+ MailruIcon,
+ ViberIcon,
+ ViberShareButton,
+ WorkplaceShareButton,
+ WorkplaceIcon,
+ WeiboShareButton,
+ WeiboIcon,
+ PocketShareButton,
+ PocketIcon,
+ InstapaperShareButton,
+ InstapaperIcon,
+ HatenaShareButton,
+ HatenaIcon
+} from 'react-share'
+
+/**
+ * @author https://github.com/txs
+ * @param {*} param0
+ * @returns
+ */
+const ShareButtons = ({ shareUrl, title, body, image }) => {
+ const services = BLOG.POSTS_SHARE_SERVICES.split(',')
+ const titleWithSiteInfo = title + ' | ' + BLOG.TITLE
+ const { locale } = useGlobal()
+ const [qrCodeShow, setQrCodeShow] = useState(false)
+
+ const copyUrl = () => {
+ copy(shareUrl)
+ alert(locale.COMMON.URL_COPIED)
+ }
+
+ const openPopover = () => {
+ setQrCodeShow(true)
+ }
+ const closePopover = () => {
+ setQrCodeShow(false)
+ }
+
+ return (
+ <>
+ {services.map(singleService => {
+ if (singleService === 'facebook') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'messenger') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'line') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'reddit') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'email') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'twitter') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'telegram') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'whatsapp') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'linkedin') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'pinterest') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'vkshare') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'okshare') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'tumblr') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'livejournal') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'mailru') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'viber') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'workplace') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'weibo') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'pocket') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'instapaper') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'hatena') {
+ return (
+
+
+
+ )
+ }
+ if (singleService === 'qq') {
+ return
+ }
+ if (singleService === 'wechat') {
+ return
+ }
+ if (singleService === 'link') {
+ return
+ }
+ return <>>
+ })}
+ >
+ )
+}
+
+export default ShareButtons
diff --git a/lib/lang/zh-CN.js b/lib/lang/zh-CN.js
index 1dddddb9..8379c75f 100644
--- a/lib/lang/zh-CN.js
+++ b/lib/lang/zh-CN.js
@@ -17,7 +17,7 @@ export default {
NO_TAG: 'NoTag',
CATEGORY: '分类',
SHARE: '分享',
- SCAN_QR_CODE: '扫一扫二维码',
+ SCAN_QR_CODE: '微信扫码分享',
URL_COPIED: '链接已复制!',
TABLE_OF_CONTENTS: '目录',
RELATE_POSTS: '相关文章',