Merge pull request #2702 from tangly1024/release/4.7.0

openwrite白名单
This commit is contained in:
tangly1024
2024-09-05 15:57:37 +08:00
committed by GitHub
2 changed files with 102 additions and 53 deletions

View File

@@ -1,5 +1,6 @@
import { siteConfig } from '@/lib/config' import { siteConfig } from '@/lib/config'
import { isBrowser, loadExternalResource } from '@/lib/utils' import { isBrowser, loadExternalResource } from '@/lib/utils'
import { useRouter } from 'next/router'
import { useEffect } from 'react' import { useEffect } from 'react'
/** /**
* OpenWrite公众号导流插件 * OpenWrite公众号导流插件
@@ -8,6 +9,7 @@ import { useEffect } from 'react'
* @returns * @returns
*/ */
const OpenWrite = () => { const OpenWrite = () => {
const router = useRouter()
const qrcode = siteConfig('OPEN_WRITE_QRCODE', '请配置公众号二维码') const qrcode = siteConfig('OPEN_WRITE_QRCODE', '请配置公众号二维码')
const blogId = siteConfig('OPEN_WRITE_BLOG_ID') const blogId = siteConfig('OPEN_WRITE_BLOG_ID')
const name = siteConfig('OPEN_WRITE_NAME', '请配置公众号名') const name = siteConfig('OPEN_WRITE_NAME', '请配置公众号名')
@@ -17,8 +19,16 @@ const OpenWrite = () => {
'OPEN_WRITE_BTN_TEXT', 'OPEN_WRITE_BTN_TEXT',
'原创不易,完成人机检测,阅读全文' '原创不易,完成人机检测,阅读全文'
) )
// 白名单
const whiteList = siteConfig('OPEN_WRITE_WHITE_LIST', '')
const loadOpenWrite = async () => { const loadOpenWrite = async () => {
const existWhite = existedWhiteList(router.asPath, whiteList)
// 如果当前页面在白名单中,则屏蔽加锁
if (existWhite) {
return
}
try { try {
await loadExternalResource( await loadExternalResource(
'https://readmore.openwrite.cn/js/readmore-2.0.js', 'https://readmore.openwrite.cn/js/readmore-2.0.js',
@@ -58,4 +68,35 @@ const OpenWrite = () => {
return <></> 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 export default OpenWrite

View File

@@ -1,16 +1,16 @@
import TagItemMini from './TagItemMini'
import Comment from '@/components/Comment' 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 { AdSlot } from '@/components/GoogleAdsense'
import LazyImage from '@/components/LazyImage' import LazyImage from '@/components/LazyImage'
import { formatDateFmt } from '@/lib/utils/formatDate'
import WWAds from '@/components/WWAds'
import NotionIcon from '@/components/NotionIcon' 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 { 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 <></>
} }
return ( return (
<div id="container" className={`${fullWidth ? 'px-10' : 'max-w-5xl '} overflow-x-auto flex-grow mx-auto w-screen md:w-full`}> <div
id='container'
className={`${fullWidth ? 'px-10' : 'max-w-5xl '} overflow-x-auto flex-grow mx-auto w-screen md:w-full`}>
{post?.type && !post?.type !== 'Page' && post?.pageCover && ( {post?.type && !post?.type !== 'Page' && post?.pageCover && (
<div className="w-full relative md:flex-shrink-0 overflow-hidden"> <div className='w-full relative md:flex-shrink-0 overflow-hidden'>
<LazyImage alt={post.title} src={post?.pageCover} className='object-cover max-h-[60vh] w-full' /> <LazyImage
alt={post.title}
src={post?.pageCover}
className='object-cover max-h-[60vh] w-full'
/>
</div> </div>
)} )}
<article itemScope itemType="https://schema.org/Movie" className="subpixel-antialiased overflow-y-hidden py-10 px-5 lg:pt-24 md:px-32 dark:border-gray-700 bg-white dark:bg-hexo-black-gray" > <article
itemScope
itemType='https://schema.org/Movie'
className='subpixel-antialiased overflow-y-hidden py-10 px-5 lg:pt-24 md:px-32 dark:border-gray-700 bg-white dark:bg-hexo-black-gray'>
<header> <header>
{/* 文章Title */} {/* 文章Title */}
<div className="font-bold text-4xl text-black dark:text-white"> <div className='font-bold text-4xl text-black dark:text-white'>
{siteConfig('POST_TITLE_ICON') && <NotionIcon icon={post?.pageIcon} />}{post.title} {siteConfig('POST_TITLE_ICON') && (
<NotionIcon icon={post?.pageIcon} />
)}
{post.title}
</div> </div>
<section className="flex-wrap flex mt-2 text-gray-400 dark:text-gray-400 font-light leading-8"> <section className='flex-wrap flex mt-2 text-gray-400 dark:text-gray-400 font-light leading-8'>
<div> <div>
{post?.category && (<> {post?.category && (
<>
<Link <Link
href={`/category/${post.category}`} href={`/category/${post.category}`}
passHref passHref
className="cursor-pointer text-md mr-2 hover:text-black dark:hover:text-white border-b dark:border-gray-500 border-dashed"> className='cursor-pointer text-md mr-2 hover:text-black dark:hover:text-white border-b dark:border-gray-500 border-dashed'>
<i className='mr-1 fas fa-folder-open' />
<i className="mr-1 fas fa-folder-open" />
{post.category} {post.category}
</Link> </Link>
<span className='mr-2'>|</span> <span className='mr-2'>|</span>
</>)} </>
)}
{post?.type !== 'Page' && (<> {post?.type !== 'Page' && (
<Link <>
href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`} <Link
passHref href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`}
className="pl-1 mr-2 cursor-pointer hover:text-gray-700 dark:hover:text-gray-200 border-b dark:border-gray-500 border-dashed"> passHref
className='pl-1 mr-2 cursor-pointer hover:text-gray-700 dark:hover:text-gray-200 border-b dark:border-gray-500 border-dashed'>
{post?.publishDay}
</Link>
<span className='mr-2'>|</span>
<span className='mx-2 text-gray-400 dark:text-gray-500'>
{locale.COMMON.LAST_EDITED_TIME}: {post.lastEditedDay}
</span>
</>
)}
{post?.publishDay} <div className='my-2'>
</Link>
<span className='mr-2'>|</span>
<span className='mx-2 text-gray-400 dark:text-gray-500'>
{locale.COMMON.LAST_EDITED_TIME}: {post.lastEditedDay}
</span>
</>)}
<div className='my-2'>
{post.tagItems && ( {post.tagItems && (
<div className="flex flex-nowrap overflow-x-auto"> <div className='flex flex-nowrap overflow-x-auto'>
{post.tagItems.map(tag => ( {post.tagItems.map(tag => (
<TagItemMini key={tag.name} tag={tag} /> <TagItemMini key={tag.name} tag={tag} />
))} ))}
</div> </div>
)} )}
</div>
</div> </div>
</div>
</section> </section>
<WWAds className='w-full' orientation='horizontal'/> <WWAds className='w-full' orientation='horizontal' />
</header> </header>
{/* Notion文章主体 */} {/* Notion文章主体 */}
@@ -93,17 +102,16 @@ export default function ArticleDetail(props) {
</section> </section>
<section> <section>
<AdSlot type='in-article'/> <AdSlot type='in-article' />
{/* 分享 */} {/* 分享 */}
<ShareBar post={post} /> <ShareBar post={post} />
</section> </section>
</article> </article>
{post?.type === 'Post' && <ArticleAround prev={prev} next={next} /> } {post?.type === 'Post' && <ArticleAround prev={prev} next={next} />}
{/* 评论互动 */} {/* 评论互动 */}
<div className="duration-200 shadow py-6 px-12 w-screen md:w-full overflow-x-auto dark:border-gray-700 bg-white dark:bg-hexo-black-gray"> <div className='duration-200 shadow py-6 px-12 w-screen md:w-full overflow-x-auto dark:border-gray-700 bg-white dark:bg-hexo-black-gray'>
<Comment frontMatter={post} /> <Comment frontMatter={post} />
</div> </div>
</div> </div>