From c1bf6a432158e6e20b5e95ae7690ed8cf9b48b67 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Wed, 26 Apr 2023 14:20:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E4=BA=AB=E5=8A=9F=E8=83=BD=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E6=89=80=E6=9C=89=E4=B8=BB=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog.config.js | 2 ++ .../components => components}/ShareBar.js | 23 +++++++++---------- .../components => components}/ShareButton.js | 0 lib/notion/getNotionData.js | 2 +- lib/notion/getPostBlocks.js | 2 +- themes/example/LayoutSlug.js | 3 ++- themes/fukasawa/components/ArticleDetail.js | 6 +++++ themes/hexo/LayoutSlug.js | 4 ++++ themes/matery/LayoutSlug.js | 4 +++- themes/medium/LayoutSlug.js | 3 +++ themes/next/components/ArticleDetail.js | 6 +++-- themes/next/config_next.js | 1 - themes/nobelium/LayoutSlug.js | 2 ++ themes/simple/LayoutSlug.js | 3 +++ 14 files changed, 42 insertions(+), 19 deletions(-) rename {themes/next/components => components}/ShareBar.js (86%) rename {themes/next/components => components}/ShareButton.js (100%) diff --git a/blog.config.js b/blog.config.js index 1b6755f8..1b01e9dc 100644 --- a/blog.config.js +++ b/blog.config.js @@ -96,6 +96,8 @@ 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_URL_PREFIX: process.env.NEXT_PUBLIC_POST_URL_PREFIX || 'article', // POST类型文章的默认路径前缀,例如默认POST类型的路径是 /article/[slug] // 如果此项配置为 '' 空, 则文章将没有前缀路径,使用场景: 希望文章前缀路径为 /post 的情况 支持多级 diff --git a/themes/next/components/ShareBar.js b/components/ShareBar.js similarity index 86% rename from themes/next/components/ShareBar.js rename to components/ShareBar.js index c595da13..97f46395 100644 --- a/themes/next/components/ShareBar.js +++ b/components/ShareBar.js @@ -5,15 +5,16 @@ import { createPopper } from '@popperjs/core' import copy from 'copy-to-clipboard' import QRCode from 'qrcode.react' import { useGlobal } from '@/lib/global' -import CONFIG_NEXT from '../config_next' const ShareBar = ({ post }) => { const router = useRouter() const [qrCodeShow, setQrCodeShow] = React.useState(false) const { locale } = useGlobal() - if (!CONFIG_NEXT.ARTICLE_SHARE) { + + if (!JSON.parse(BLOG.POST_SHARE_BAR_ENABLE) || !post || post?.type !== 'Post') { return <> } + const shareUrl = BLOG.LINK + router.asPath // 二维码悬浮 @@ -35,26 +36,25 @@ const ShareBar = ({ post }) => { alert(locale.COMMON.URL_COPIED) } - return <> -
{locale.COMMON.SHARE}:
-
+
-
+ -
+ -
+ -
+ -
+ -
+
- } export default ShareBar diff --git a/themes/next/components/ShareButton.js b/components/ShareButton.js similarity index 100% rename from themes/next/components/ShareButton.js rename to components/ShareButton.js diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index e723a83d..9b586e65 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -65,7 +65,7 @@ export async function getNotionPageData({ pageId, from }) { const cacheKey = 'page_block_' + pageId const data = await getDataFromCache(cacheKey) if (data && data.pageIds?.length > 0) { - console.log('[命中缓存]:', `from:${from}`, `root-page-id:${pageId}`) + console.log('[缓存]:', `from:${from}`, `root-page-id:${pageId}`) return data } const pageRecordMap = await getDataBaseInfoByNotionAPI({ pageId, from }) diff --git a/lib/notion/getPostBlocks.js b/lib/notion/getPostBlocks.js index 5fe2af84..8e764f7b 100644 --- a/lib/notion/getPostBlocks.js +++ b/lib/notion/getPostBlocks.js @@ -14,7 +14,7 @@ export async function getPostBlocks(id, from, slice) { const cacheKey = 'page_block_' + id let pageBlock = await getDataFromCache(cacheKey) if (pageBlock) { - console.log('[命中缓存]:', `from:${from}`, cacheKey) + console.log('[缓存]:', `from:${from}`, cacheKey) return filterPostBlocks(id, pageBlock, slice) } diff --git a/themes/example/LayoutSlug.js b/themes/example/LayoutSlug.js index b16892b7..b19f51ff 100644 --- a/themes/example/LayoutSlug.js +++ b/themes/example/LayoutSlug.js @@ -3,6 +3,7 @@ import { ArticleLock } from './components/ArticleLock' import NotionPage from '@/components/NotionPage' import { ArticleInfo } from './components/ArticleInfo' import Comment from '@/components/Comment' +import ShareBar from '@/components/ShareBar' export const LayoutSlug = props => { const { post, lock, validPassword } = props @@ -17,10 +18,10 @@ export const LayoutSlug = props => { {lock && } {!lock &&
- {post && <> + }
} diff --git a/themes/fukasawa/components/ArticleDetail.js b/themes/fukasawa/components/ArticleDetail.js index 65af8400..e9e82b0f 100644 --- a/themes/fukasawa/components/ArticleDetail.js +++ b/themes/fukasawa/components/ArticleDetail.js @@ -1,5 +1,6 @@ import Comment from '@/components/Comment' import NotionPage from '@/components/NotionPage' +import ShareBar from '@/components/ShareBar' import formatDate from '@/lib/formatDate' import { useGlobal } from '@/lib/global' import Link from 'next/link' @@ -84,6 +85,11 @@ export default function ArticleDetail(props) { {post && } +
+ {/* 分享 */} + +
+
{/* 文章内嵌广告 */} { const { post, lock, validPassword } = props @@ -76,6 +77,9 @@ export const LayoutSlug = props => {
+ {/* 分享 */} + + {/* 评论互动 */}
diff --git a/themes/matery/LayoutSlug.js b/themes/matery/LayoutSlug.js index 12fefce4..e938942b 100644 --- a/themes/matery/LayoutSlug.js +++ b/themes/matery/LayoutSlug.js @@ -10,6 +10,7 @@ import { ArticleInfo } from './components/ArticleInfo' import Catalog from './components/Catalog' import JumpToCommentButton from './components/JumpToCommentButton' import throttle from 'lodash.throttle' +import ShareBar from '@/components/ShareBar' export const LayoutSlug = props => { const { post, lock, validPassword } = props @@ -87,7 +88,8 @@ export const LayoutSlug = props => {
- + {/* 分享 */} + {/* 评论互动 */}
diff --git a/themes/medium/LayoutSlug.js b/themes/medium/LayoutSlug.js index 6000c3f3..b6d54077 100644 --- a/themes/medium/LayoutSlug.js +++ b/themes/medium/LayoutSlug.js @@ -13,6 +13,7 @@ import ArticleAround from './components/ArticleAround' import TocDrawer from './components/TocDrawer' import CategoryItem from './components/CategoryItem' import TagItemMini from './components/TagItemMini' +import ShareBar from '@/components/ShareBar' export const LayoutSlug = props => { const { post, prev, next, siteInfo, lock, validPassword } = props @@ -92,6 +93,8 @@ export const LayoutSlug = props => {
{post.type === 'Post' && } + {/* 分享 */} +
diff --git a/themes/next/components/ArticleDetail.js b/themes/next/components/ArticleDetail.js index e5b8dba2..75fc7f7d 100644 --- a/themes/next/components/ArticleDetail.js +++ b/themes/next/components/ArticleDetail.js @@ -2,7 +2,7 @@ import BLOG from '@/blog.config' import BlogAround from './BlogAround' import Comment from '@/components/Comment' import RecommendPosts from './RecommendPosts' -import ShareBar from './ShareBar' +import ShareBar from '@/components/ShareBar' import TagItem from './TagItem' import formatDate from '@/lib/formatDate' import { useGlobal } from '@/lib/global' @@ -100,6 +100,9 @@ export default function ArticleDetail(props) { {/* 推荐文章 */} {post.type === 'Post' && } + {/* 分享 */} + +
{/* 分类 */} {post.category && <> @@ -124,7 +127,6 @@ export default function ArticleDetail(props) { ))}
)} - )} diff --git a/themes/next/config_next.js b/themes/next/config_next.js index 5504b8df..d341cee0 100644 --- a/themes/next/config_next.js +++ b/themes/next/config_next.js @@ -30,7 +30,6 @@ const CONFIG_NEXT = { WIDGET_DARK_MODE: false, // 显示日间/夜间模式切换 WIDGET_TOC: true, // 移动端显示悬浮目录 - ARTICLE_SHARE: process.env.NEXT_PUBLIC_ARTICLE_SHARE || false, // 文章分享功能 ARTICLE_RELATE_POSTS: true, // 相关文章推荐 ARTICLE_COPYRIGHT: true // 文章版权声明 diff --git a/themes/nobelium/LayoutSlug.js b/themes/nobelium/LayoutSlug.js index d60062a0..d27628af 100644 --- a/themes/nobelium/LayoutSlug.js +++ b/themes/nobelium/LayoutSlug.js @@ -4,6 +4,7 @@ import NotionPage from '@/components/NotionPage' import { ArticleInfo } from './components/ArticleInfo' import Comment from '@/components/Comment' import { ArticleFooter } from './components/ArticleFooter' +import ShareBar from '@/components/ShareBar' export const LayoutSlug = props => { const { post, lock, validPassword } = props @@ -21,6 +22,7 @@ export const LayoutSlug = props => { {post && <> + } diff --git a/themes/simple/LayoutSlug.js b/themes/simple/LayoutSlug.js index 6cf7c82b..d0cd2a1d 100644 --- a/themes/simple/LayoutSlug.js +++ b/themes/simple/LayoutSlug.js @@ -4,6 +4,7 @@ import NotionPage from '@/components/NotionPage' import { ArticleInfo } from './components/ArticleInfo' import Comment from '@/components/Comment' import ArticleAround from './components/ArticleAround' +import ShareBar from '@/components/ShareBar' export const LayoutSlug = props => { const { post, lock, validPassword, prev, next } = props @@ -23,6 +24,8 @@ export const LayoutSlug = props => { {post.type === 'Post' && } + {/* 分享 */} + }
}