Skip to content

Commit c1bf6a4

Browse files
committed
分享功能加入所有主题
1 parent 27f45c9 commit c1bf6a4

File tree

14 files changed

+42
-19
lines changed

14 files changed

+42
-19
lines changed

blog.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ const BLOG = {
9696
BACKGROUND_DARK: '#000000', // use hex value, don't forget '#'
9797
SUB_PATH: '', // leave this empty unless you want to deploy in a folder
9898

99+
POST_SHARE_BAR_ENABLE: process.env.NEXT_PUBLIC_POST_SHARE_BAR || 'false', // 文章分享功能 ,将在底部显示一个分享条
100+
99101
POST_URL_PREFIX: process.env.NEXT_PUBLIC_POST_URL_PREFIX || 'article',
100102
// POST类型文章的默认路径前缀,例如默认POST类型的路径是 /article/[slug]
101103
// 如果此项配置为 '' 空, 则文章将没有前缀路径,使用场景: 希望文章前缀路径为 /post 的情况 支持多级

themes/next/components/ShareBar.js components/ShareBar.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import { createPopper } from '@popperjs/core'
55
import copy from 'copy-to-clipboard'
66
import QRCode from 'qrcode.react'
77
import { useGlobal } from '@/lib/global'
8-
import CONFIG_NEXT from '../config_next'
98

109
const ShareBar = ({ post }) => {
1110
const router = useRouter()
1211
const [qrCodeShow, setQrCodeShow] = React.useState(false)
1312
const { locale } = useGlobal()
14-
if (!CONFIG_NEXT.ARTICLE_SHARE) {
13+
14+
if (!JSON.parse(BLOG.POST_SHARE_BAR_ENABLE) || !post || post?.type !== 'Post') {
1515
return <></>
1616
}
17+
1718
const shareUrl = BLOG.LINK + router.asPath
1819

1920
// 二维码悬浮
@@ -35,26 +36,25 @@ const ShareBar = ({ post }) => {
3536
alert(locale.COMMON.URL_COPIED)
3637
}
3738

38-
return <>
39-
<div
39+
return <div id='share-bar'
4040
className='py-2 text-gray-500 text-center space-x-2 flex my-1 dark:text-gray-200 overflow-visible'>
4141
<div className='hidden md:block text-gray-800 dark:text-gray-300 mr-2 my-2 whitespace-nowrap'>{locale.COMMON.SHARE}:</div>
42-
<div className='text-3xl cursor-pointer'>
42+
<div className='text-3xl cursor-pointer w-6'>
4343
<a className='text-blue-700' href={`https://www.facebook.com/sharer.php?u=${shareUrl}`} >
4444
<i className='fab fa-facebook-square'/>
4545
</a>
4646
</div>
47-
<div className='text-3xl cursor-pointer'>
47+
<div className='text-3xl cursor-pointer w-6'>
4848
<a className='text-blue-400' target='_blank' rel='noreferrer' href={`https://twitter.com/intent/tweet?title=${post.title}&url${shareUrl}`} >
4949
<i className='fab fa-twitter-square'/>
5050
</a>
5151
</div>
52-
<div className='text-3xl cursor-pointer'>
52+
<div className='text-3xl cursor-pointer w-6'>
5353
<a className='text-blue-500' href={`https://telegram.me/share/url?url=${shareUrl}&text=${post.title}`} >
5454
<i className='fab fa-telegram'/>
5555
</a>
5656
</div>
57-
<div className='cursor-pointer text-2xl'>
57+
<div className='cursor-pointer text-2xl w-6'>
5858
<a className='text-green-600' ref={btnRef} onMouseEnter={openPopover} onMouseLeave={closePopover}>
5959
<i className='fab fa-weixin'/>
6060
<div ref={popoverRef} className={(qrCodeShow ? 'opacity-100 ' : 'invisible opacity-0') + ' transition-all duration-200 text-center py-2'}>
@@ -67,22 +67,21 @@ const ShareBar = ({ post }) => {
6767
</div>
6868
</a>
6969
</div>
70-
<div className='cursor-pointer text-2xl'>
70+
<div className='cursor-pointer text-2xl w-6'>
7171
<a className='text-red-600' target='_blank' rel='noreferrer' href={`https://service.weibo.com/share/share.php?url=${shareUrl}&title=${post.title}`} >
7272
<i className='fab fa-weibo'/>
7373
</a>
7474
</div>
75-
<div className='cursor-pointer text-2xl'>
75+
<div className='cursor-pointer text-2xl w-6'>
7676
<a className='text-blue-400' target='_blank' rel='noreferrer' href={`http://connect.qq.com/widget/shareqq/index.html?url=${shareUrl}&sharesource=qzone&title=${post.title}&desc=${post.summary}`} >
7777
<i className='fab fa-qq'/>
7878
</a>
7979
</div>
80-
<div className='cursor-pointer text-2xl'>
80+
<div className='cursor-pointer text-2xl w-6'>
8181
<a className='text-yellow-600' onClick={copyUrl} >
8282
<i className='fas fa-link'/>
8383
</a>
8484
</div>
8585
</div>
86-
</>
8786
}
8887
export default ShareBar
File renamed without changes.

lib/notion/getNotionData.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export async function getNotionPageData({ pageId, from }) {
6565
const cacheKey = 'page_block_' + pageId
6666
const data = await getDataFromCache(cacheKey)
6767
if (data && data.pageIds?.length > 0) {
68-
console.log('[命中缓存]:', `from:${from}`, `root-page-id:${pageId}`)
68+
console.log('[缓存]:', `from:${from}`, `root-page-id:${pageId}`)
6969
return data
7070
}
7171
const pageRecordMap = await getDataBaseInfoByNotionAPI({ pageId, from })

lib/notion/getPostBlocks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export async function getPostBlocks(id, from, slice) {
1414
const cacheKey = 'page_block_' + id
1515
let pageBlock = await getDataFromCache(cacheKey)
1616
if (pageBlock) {
17-
console.log('[命中缓存]:', `from:${from}`, cacheKey)
17+
console.log('[缓存]:', `from:${from}`, cacheKey)
1818
return filterPostBlocks(id, pageBlock, slice)
1919
}
2020

themes/example/LayoutSlug.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ArticleLock } from './components/ArticleLock'
33
import NotionPage from '@/components/NotionPage'
44
import { ArticleInfo } from './components/ArticleInfo'
55
import Comment from '@/components/Comment'
6+
import ShareBar from '@/components/ShareBar'
67

78
export const LayoutSlug = props => {
89
const { post, lock, validPassword } = props
@@ -17,10 +18,10 @@ export const LayoutSlug = props => {
1718
{lock && <ArticleLock validPassword={validPassword} />}
1819

1920
{!lock && <div id="notion-article" className="px-2">
20-
2121
{post && <>
2222
<ArticleInfo post={post} />
2323
<NotionPage post={post} />
24+
<ShareBar post={post} />
2425
<Comment frontMatter={post}/>
2526
</>}
2627
</div>}

themes/fukasawa/components/ArticleDetail.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Comment from '@/components/Comment'
22
import NotionPage from '@/components/NotionPage'
3+
import ShareBar from '@/components/ShareBar'
34
import formatDate from '@/lib/formatDate'
45
import { useGlobal } from '@/lib/global'
56
import Link from 'next/link'
@@ -84,6 +85,11 @@ export default function ArticleDetail(props) {
8485
{post && <NotionPage post={post} />}
8586
</section>
8687

88+
<section>
89+
{/* 分享 */}
90+
<ShareBar post={post} />
91+
</section>
92+
8793
<section className="px-1 py-2 my-1 text-sm font-light overflow-auto text-gray-600 dark:text-gray-400">
8894
{/* 文章内嵌广告 */}
8995
<ins className="adsbygoogle"

themes/hexo/LayoutSlug.js

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import ArticleAdjacent from './components/ArticleAdjacent'
1111
import ArticleCopyright from './components/ArticleCopyright'
1212
import ArticleRecommend from './components/ArticleRecommend'
1313
import { isBrowser } from '@/lib/utils'
14+
import ShareBar from '@/components/ShareBar'
1415

1516
export const LayoutSlug = props => {
1617
const { post, lock, validPassword } = props
@@ -76,6 +77,9 @@ export const LayoutSlug = props => {
7677

7778
<hr className='border-dashed' />
7879

80+
{/* 分享 */}
81+
<ShareBar post={post} />
82+
7983
{/* 评论互动 */}
8084
<div className="duration-200 overflow-x-auto bg-white dark:bg-hexo-black-gray px-3">
8185
<Comment frontMatter={post} />

themes/matery/LayoutSlug.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ArticleInfo } from './components/ArticleInfo'
1010
import Catalog from './components/Catalog'
1111
import JumpToCommentButton from './components/JumpToCommentButton'
1212
import throttle from 'lodash.throttle'
13+
import ShareBar from '@/components/ShareBar'
1314

1415
export const LayoutSlug = props => {
1516
const { post, lock, validPassword } = props
@@ -87,7 +88,8 @@ export const LayoutSlug = props => {
8788
</article>
8889

8990
<hr className='border-dashed' />
90-
91+
{/* 分享 */}
92+
<ShareBar post={post} />
9193
{/* 评论互动 */}
9294
<div className="overflow-x-auto dark:bg-hexo-black-gray px-3">
9395
<Comment frontMatter={post} />

themes/medium/LayoutSlug.js

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import ArticleAround from './components/ArticleAround'
1313
import TocDrawer from './components/TocDrawer'
1414
import CategoryItem from './components/CategoryItem'
1515
import TagItemMini from './components/TagItemMini'
16+
import ShareBar from '@/components/ShareBar'
1617

1718
export const LayoutSlug = props => {
1819
const { post, prev, next, siteInfo, lock, validPassword } = props
@@ -92,6 +93,8 @@ export const LayoutSlug = props => {
9293
</div>
9394
</div>
9495
{post.type === 'Post' && <ArticleAround prev={prev} next={next} />}
96+
{/* 分享 */}
97+
<ShareBar post={post} />
9598
<Comment frontMatter={post} />
9699
</section>
97100

themes/next/components/ArticleDetail.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import BLOG from '@/blog.config'
22
import BlogAround from './BlogAround'
33
import Comment from '@/components/Comment'
44
import RecommendPosts from './RecommendPosts'
5-
import ShareBar from './ShareBar'
5+
import ShareBar from '@/components/ShareBar'
66
import TagItem from './TagItem'
77
import formatDate from '@/lib/formatDate'
88
import { useGlobal } from '@/lib/global'
@@ -100,6 +100,9 @@ export default function ArticleDetail(props) {
100100
{/* 推荐文章 */}
101101
{post.type === 'Post' && <RecommendPosts currentPost={post} recommendPosts={recommendPosts} />}
102102

103+
{/* 分享 */}
104+
<ShareBar post={post} />
105+
103106
<section className="flex justify-between">
104107
{/* 分类 */}
105108
{post.category && <>
@@ -124,7 +127,6 @@ export default function ArticleDetail(props) {
124127
))}
125128
</div>
126129
)}
127-
<ShareBar post={post} />
128130
</>
129131
)}
130132
</section>

themes/next/config_next.js

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const CONFIG_NEXT = {
3030
WIDGET_DARK_MODE: false, // 显示日间/夜间模式切换
3131
WIDGET_TOC: true, // 移动端显示悬浮目录
3232

33-
ARTICLE_SHARE: process.env.NEXT_PUBLIC_ARTICLE_SHARE || false, // 文章分享功能
3433
ARTICLE_RELATE_POSTS: true, // 相关文章推荐
3534
ARTICLE_COPYRIGHT: true // 文章版权声明
3635

themes/nobelium/LayoutSlug.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import NotionPage from '@/components/NotionPage'
44
import { ArticleInfo } from './components/ArticleInfo'
55
import Comment from '@/components/Comment'
66
import { ArticleFooter } from './components/ArticleFooter'
7+
import ShareBar from '@/components/ShareBar'
78

89
export const LayoutSlug = props => {
910
const { post, lock, validPassword } = props
@@ -21,6 +22,7 @@ export const LayoutSlug = props => {
2122
{post && <>
2223
<ArticleInfo post={post} />
2324
<NotionPage post={post} />
25+
<ShareBar post={post} />
2426
<Comment frontMatter={post}/>
2527
<ArticleFooter />
2628
</>}

themes/simple/LayoutSlug.js

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import NotionPage from '@/components/NotionPage'
44
import { ArticleInfo } from './components/ArticleInfo'
55
import Comment from '@/components/Comment'
66
import ArticleAround from './components/ArticleAround'
7+
import ShareBar from '@/components/ShareBar'
78

89
export const LayoutSlug = props => {
910
const { post, lock, validPassword, prev, next } = props
@@ -23,6 +24,8 @@ export const LayoutSlug = props => {
2324
<ArticleInfo post={post} />
2425
<NotionPage post={post} />
2526
{post.type === 'Post' && <ArticleAround prev={prev} next={next} />}
27+
{/* 分享 */}
28+
<ShareBar post={post} />
2629
<Comment frontMatter={post}/>
2730
</>}
2831
</div>}

0 commit comments

Comments
 (0)