diff --git a/components/OpenWrite.js b/components/OpenWrite.js index c5fd4a7a..a782af3d 100644 --- a/components/OpenWrite.js +++ b/components/OpenWrite.js @@ -1,5 +1,6 @@ import { siteConfig } from '@/lib/config' import { isBrowser, loadExternalResource } from '@/lib/utils' +import { useRouter } from 'next/router' import { useEffect } from 'react' /** * OpenWrite公众号导流插件 @@ -8,6 +9,7 @@ import { useEffect } from 'react' * @returns */ const OpenWrite = () => { + const router = useRouter() const qrcode = siteConfig('OPEN_WRITE_QRCODE', '请配置公众号二维码') const blogId = siteConfig('OPEN_WRITE_BLOG_ID') const name = siteConfig('OPEN_WRITE_NAME', '请配置公众号名') @@ -17,8 +19,16 @@ const OpenWrite = () => { 'OPEN_WRITE_BTN_TEXT', '原创不易,完成人机检测,阅读全文' ) + // 白名单 + const whiteList = siteConfig('OPEN_WRITE_WHITE_LIST', '') const loadOpenWrite = async () => { + const existWhite = existedWhiteList(router.asPath, whiteList) + // 如果当前页面在白名单中,则屏蔽加锁 + if (existWhite) { + return + } + try { await loadExternalResource( 'https://readmore.openwrite.cn/js/readmore-2.0.js', @@ -58,4 +68,35 @@ const OpenWrite = () => { return <> } +/** + * 检查白名单 + * @param {*} path 当前url的字符串 + * @param {*} whiteListStr 白名单字符串 + */ +function existedWhiteList(path, whiteListStr) { + // 参数检查 + if (!path || !whiteListStr) { + return true + } + + // 提取 path 最后一个斜杠后的内容,去掉前面的斜杆 + // 移除查询参数(从 '?' 开始的部分)和 `.html` 后缀 + const processedPath = path + .replace(/\?.*$/, '') // 移除查询参数 + .replace(/.*\/([^\/]+)(?:\.html)?$/, '$1') // 去掉前面的路径和 .html + + // 严格检查白名单字符串中是否包含处理后的 path + // const whiteListArray = whiteListStr.split(',') + // return whiteListArray.includes(processedPath) + + // 放宽判断 + const isWhite = whiteListStr.includes(processedPath) + + if (isWhite) { + console.log('OpenWrite白名单', processedPath) + } + + return isWhite +} + export default OpenWrite diff --git a/themes/fukasawa/components/ArticleDetail.js b/themes/fukasawa/components/ArticleDetail.js index 6883d8e0..62a0a0d8 100644 --- a/themes/fukasawa/components/ArticleDetail.js +++ b/themes/fukasawa/components/ArticleDetail.js @@ -1,16 +1,16 @@ -import TagItemMini from './TagItemMini' import Comment from '@/components/Comment' -import NotionPage from '@/components/NotionPage' -import ShareBar from '@/components/ShareBar' -import { useGlobal } from '@/lib/global' -import Link from 'next/link' -import ArticleAround from './ArticleAround' import { AdSlot } from '@/components/GoogleAdsense' import LazyImage from '@/components/LazyImage' -import { formatDateFmt } from '@/lib/utils/formatDate' -import WWAds from '@/components/WWAds' import NotionIcon from '@/components/NotionIcon' +import NotionPage from '@/components/NotionPage' +import ShareBar from '@/components/ShareBar' +import WWAds from '@/components/WWAds' import { siteConfig } from '@/lib/config' +import { useGlobal } from '@/lib/global' +import { formatDateFmt } from '@/lib/utils/formatDate' +import Link from 'next/link' +import ArticleAround from './ArticleAround' +import TagItemMini from './TagItemMini' /** * @@ -25,66 +25,75 @@ export default function ArticleDetail(props) { return <> } return ( -
+
{post?.type && !post?.type !== 'Page' && post?.pageCover && ( -
- +
+
)} -
- +
- {/* 文章Title */} -
- {siteConfig('POST_TITLE_ICON') && }{post.title} +
+ {siteConfig('POST_TITLE_ICON') && ( + + )} + {post.title}
-
+
- {post?.category && (<> + {post?.category && ( + <> - - + className='cursor-pointer text-md mr-2 hover:text-black dark:hover:text-white border-b dark:border-gray-500 border-dashed'> + {post.category} - - | - )} + | + + )} - {post?.type !== 'Page' && (<> - + {post?.type !== 'Page' && ( + <> + + {post?.publishDay} + + | + + {locale.COMMON.LAST_EDITED_TIME}: {post.lastEditedDay} + + + )} - {post?.publishDay} - - - | - - {locale.COMMON.LAST_EDITED_TIME}: {post.lastEditedDay} - - )} - -
+
{post.tagItems && ( -
- {post.tagItems.map(tag => ( - - ))} -
+
+ {post.tagItems.map(tag => ( + + ))} +
)} +
-
-
- +
{/* Notion文章主体 */} @@ -93,17 +102,16 @@ export default function ArticleDetail(props) {
- - {/* 分享 */} - + + {/* 分享 */} +
-
- {post?.type === 'Post' && } + {post?.type === 'Post' && } {/* 评论互动 */} -
+