Skip to content

Commit

Permalink
Merge pull request tangly1024#2702 from tangly1024/release/4.7.0
Browse files Browse the repository at this point in the history
openwrite白名单
  • Loading branch information
tangly1024 authored Sep 5, 2024
2 parents 1ea503e + b06cd19 commit 9561567
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 53 deletions.
41 changes: 41 additions & 0 deletions components/OpenWrite.js
Original file line number Diff line number Diff line change
@@ -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公众号导流插件
Expand All @@ -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', '请配置公众号名')
Expand All @@ -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',
Expand Down Expand Up @@ -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
114 changes: 61 additions & 53 deletions themes/fukasawa/components/ArticleDetail.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import TagItemMini from './TagItemMini'
import Comment from '@/components/Comment'
import { AdSlot } from '@/components/GoogleAdsense'
import LazyImage from '@/components/LazyImage'
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 { 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 { siteConfig } from '@/lib/config'
import TagItemMini from './TagItemMini'

/**
*
Expand All @@ -25,66 +25,75 @@ export default function ArticleDetail(props) {
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 && (
<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' />
<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'
/>
</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>

{/* 文章Title */}
<div className="font-bold text-4xl text-black dark:text-white">
{siteConfig('POST_TITLE_ICON') && <NotionIcon icon={post?.pageIcon} />}{post.title}
<div className='font-bold text-4xl text-black dark:text-white'>
{siteConfig('POST_TITLE_ICON') && (
<NotionIcon icon={post?.pageIcon} />
)}
{post.title}
</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>
{post?.category && (<>
{post?.category && (
<>
<Link
href={`/category/${post.category}`}
passHref
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" />
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' />
{post.category}

</Link>
<span className='mr-2'>|</span>
</>)}

{post?.type !== 'Page' && (<>
<Link
href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`}
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>
</>)}
<span className='mr-2'>|</span>
</>
)}

<div className='my-2'>
{post?.type !== 'Page' && (
<>
<Link
href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`}
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>
</>
)}

<div className='my-2'>
{post.tagItems && (
<div className="flex flex-nowrap overflow-x-auto">
{post.tagItems.map(tag => (
<TagItemMini key={tag.name} tag={tag} />
))}
</div>
<div className='flex flex-nowrap overflow-x-auto'>
{post.tagItems.map(tag => (
<TagItemMini key={tag.name} tag={tag} />
))}
</div>
)}
</div>
</div>
</div>

</section>

<WWAds className='w-full' orientation='horizontal'/>
<WWAds className='w-full' orientation='horizontal' />
</header>

{/* Notion文章主体 */}
Expand All @@ -93,17 +102,16 @@ export default function ArticleDetail(props) {
</section>

<section>
<AdSlot type='in-article'/>
{/* 分享 */}
<ShareBar post={post} />
<AdSlot type='in-article' />
{/* 分享 */}
<ShareBar post={post} />
</section>

</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} />
</div>
</div>
Expand Down

0 comments on commit 9561567

Please sign in to comment.