Merge pull request #3040 from qixing-jk/fix-wrong-call-hook

Fix wrong call hook
This commit is contained in:
tangly1024
2024-12-21 21:22:26 +08:00
committed by GitHub
22 changed files with 93 additions and 61 deletions

View File

@@ -39,6 +39,7 @@ function requestAd(ads) {
// 获取节点或其子节点中包含 adsbygoogle 类的节点
function getNodesWithAdsByGoogleClass(node) {
const adsNodes = []
// 检查节点及其子节点是否包含 adsbygoogle 类
function checkNodeForAds(node) {
if (
@@ -53,6 +54,7 @@ function getNodesWithAdsByGoogleClass(node) {
}
}
}
checkNodeForAds(node)
return adsNodes
}
@@ -174,6 +176,9 @@ const AdSlot = ({ type = 'show' }) => {
* @param {*} props
*/
const AdEmbed = () => {
const ADSENSE_GOOGLE_ID = siteConfig('ADSENSE_GOOGLE_ID')
const ADSENSE_GOOGLE_TEST = siteConfig('ADSENSE_GOOGLE_TEST')
const ADSENSE_GOOGLE_SLOT_AUTO = siteConfig('ADSENSE_GOOGLE_SLOT_AUTO')
useEffect(() => {
setTimeout(() => {
// 找到所有 class 为 notion-text 且内容为 '<ins/>' 的 div 元素
@@ -187,18 +192,12 @@ const AdEmbed = () => {
const newInsElement = document.createElement('ins')
newInsElement.className = 'adsbygoogle w-full py-1'
newInsElement.style.display = 'block'
newInsElement.setAttribute(
'data-ad-client',
siteConfig('ADSENSE_GOOGLE_ID')
)
newInsElement.setAttribute('data-ad-client', ADSENSE_GOOGLE_ID)
newInsElement.setAttribute(
'data-adtest',
siteConfig('ADSENSE_GOOGLE_TEST') ? 'on' : 'off'
)
newInsElement.setAttribute(
'data-ad-slot',
siteConfig('ADSENSE_GOOGLE_SLOT_AUTO')
ADSENSE_GOOGLE_TEST ? 'on' : 'off'
)
newInsElement.setAttribute('data-ad-slot', ADSENSE_GOOGLE_SLOT_AUTO)
newInsElement.setAttribute('data-ad-format', 'auto')
newInsElement.setAttribute('data-full-width-responsive', 'true')

View File

@@ -27,7 +27,7 @@ const NotionPage = ({ post, className }) => {
})
const zoomRef = useRef(zoom ? zoom.clone() : null)
const IMAGE_ZOOM_IN_WIDTH = siteConfig('IMAGE_ZOOM_IN_WIDTH', 1200)
// 页面首次打开时执行的勾子
useEffect(() => {
// 检测当前的url并自动滚动到对应目标
@@ -64,7 +64,7 @@ const NotionPage = ({ post, className }) => {
// 替换为更高清的图像
mutation?.target?.setAttribute(
'src',
compressImage(src, siteConfig('IMAGE_ZOOM_IN_WIDTH', 1200))
compressImage(src, IMAGE_ZOOM_IN_WIDTH)
)
}, 800)
}

View File

@@ -12,9 +12,12 @@ import { useEffect } from 'react'
*/
const SEO = props => {
const { children, siteInfo, post, NOTION_CONFIG } = props
let url = siteConfig('PATH')?.length
? `${siteConfig('LINK')}/${siteConfig('SUB_PATH', '')}`
: siteConfig('LINK')
const PATH = siteConfig('PATH')
const LINK = siteConfig('LINK')
const SUB_PATH = siteConfig('SUB_PATH', '')
let url = PATH?.length
? `${LINK}/${SUB_PATH}`
: LINK
let image
const router = useRouter()
const meta = getSEOMeta(props, router, useGlobal()?.locale)
@@ -40,7 +43,8 @@ const SEO = props => {
}, [])
// SEO关键词
let keywords = meta?.tags || siteConfig('KEYWORDS')
const KEYWORDS = siteConfig('KEYWORDS')
let keywords = meta?.tags || KEYWORDS
if (post?.tags && post?.tags?.length > 0) {
keywords = post?.tags?.join(',')
}
@@ -48,11 +52,12 @@ const SEO = props => {
url = `${url}/${meta.slug}`
image = meta.image || '/bg_image.jpg'
}
const title = meta?.title || siteConfig('TITLE')
const TITLE = siteConfig('TITLE')
const title = meta?.title || TITLE
const description = meta?.description || `${siteInfo?.description}`
const type = meta?.type || 'website'
const lang = siteConfig('LANG').replace('-', '_') // Facebook OpenGraph 要 zh_CN 這樣的格式才抓得到語言
const category = meta?.category || siteConfig('KEYWORDS') // section 主要是像是 category 這樣的分類Facebook 用這個來抓連結的分類
const category = meta?.category || KEYWORDS // section 主要是像是 category 這樣的分類Facebook 用這個來抓連結的分類
const favicon = siteConfig('BLOG_FAVICON')
const BACKGROUND_DARK = siteConfig('BACKGROUND_DARK', '', NOTION_CONFIG)
@@ -94,6 +99,7 @@ const SEO = props => {
const FACEBOOK_PAGE = siteConfig('FACEBOOK_PAGE', null, NOTION_CONFIG)
const AUTHOR = siteConfig('AUTHOR')
return (
<Head>
<link rel='icon' href={favicon} />
@@ -154,7 +160,7 @@ const SEO = props => {
{meta?.type === 'Post' && (
<>
<meta property='article:published_time' content={meta.publishDay} />
<meta property='article:author' content={siteConfig('AUTHOR')} />
<meta property='article:author' content={AUTHOR} />
<meta property='article:section' content={category} />
<meta property='article:publisher' content={FACEBOOK_PAGE} />
</>
@@ -173,6 +179,7 @@ const getSEOMeta = (props, router, locale) => {
const { post, siteInfo, tag, category, page } = props
const keyword = router?.query?.s
const TITLE = siteConfig('TITLE')
switch (router.route) {
case '/':
return {
@@ -235,7 +242,7 @@ const getSEOMeta = (props, router, locale) => {
case '/search/[keyword]/page/[page]':
return {
title: `${keyword || ''}${keyword ? ' | ' : ''}${locale.NAV.SEARCH} | ${siteInfo?.title}`,
description: siteConfig('TITLE'),
description: TITLE,
image: `${siteInfo?.pageCover}`,
slug: 'search/' + (keyword || ''),
type: 'website'

View File

@@ -38,6 +38,9 @@ export const siteConfig = (key, defaultVal = null, extendConfig = {}) => {
case 'TAG_SORT_BY_COUNT':
case 'THEME':
case 'LINK':
case 'NPM_CDN_BASE':
case 'CDNJS_CDN_BASE':
case 'JSDELIVR_CDN_BASE':
// LINK比较特殊
if (key === 'LINK') {
if (!extendConfig || Object.keys(extendConfig).length === 0) {

View File

@@ -156,6 +156,7 @@ const LayoutPostList = props => {
const LayoutSlug = props => {
const { post, lock, validPassword } = props
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 404
if (!post) {
@@ -170,7 +171,7 @@ const LayoutSlug = props => {
}
}
},
siteConfig('POST_WAITING_TIME_FOR_404') * 1000
waiting404
)
}
}, [post])

View File

@@ -137,6 +137,7 @@ const LayoutPostList = props => {
const LayoutSlug = props => {
const { post, lock, validPassword } = props
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 404
if (!post) {
@@ -151,7 +152,7 @@ const LayoutSlug = props => {
}
}
},
siteConfig('POST_WAITING_TIME_FOR_404') * 1000
waiting404
)
}
}, [post])

View File

@@ -316,6 +316,7 @@ const LayoutSlug = props => {
? `${post?.title} | ${siteInfo?.description}`
: `${post?.title} | ${siteInfo?.title}`
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 404
if (!post) {
@@ -332,7 +333,7 @@ const LayoutSlug = props => {
}
}
},
siteConfig('POST_WAITING_TIME_FOR_404') * 1000
waiting404
)
}
}, [post])

View File

@@ -8,6 +8,7 @@ import SocialButton from './SocialButton'
* @returns
*/
const Footer = () => {
const BEI_AN = siteConfig('BEI_AN')
return (
<footer className='relative flex-shrink-0 bg-white dark:bg-[#1a191d] justify-center text-center m-auto w-full leading-6 text-gray-600 dark:text-gray-100 text-sm'>
{/* 颜色过度区 */}
@@ -33,7 +34,7 @@ const Footer = () => {
</div>
<div id='footer-bottom-right'>
{siteConfig('BEI_AN') && (
{BEI_AN && (
<>
<i className='fas fa-shield-alt' />{' '}
<a href='https://beian.miit.gov.cn/' className='mr-2'>

View File

@@ -15,12 +15,9 @@ export default function LatestPostsGroupMini({ latestPosts, siteInfo }) {
// 获取当前路径
const currentPath = useRouter().asPath
const { locale } = useGlobal()
const SUB_PATH = siteConfig('SUB_PATH', '')
if (!latestPosts) {
return <></>
}
return (
return latestPosts ? (
<>
<div className=' mb-2 px-1 flex flex-nowrap justify-between'>
<div>
@@ -30,7 +27,7 @@ export default function LatestPostsGroupMini({ latestPosts, siteInfo }) {
</div>
{latestPosts.map(post => {
const selected =
currentPath === `${siteConfig('SUB_PATH', '')}/${post.slug}`
currentPath === `${SUB_PATH}/${post.slug}`
const headerImage = post?.pageCoverThumbnail
? post.pageCoverThumbnail
: siteInfo?.pageCover
@@ -63,5 +60,5 @@ export default function LatestPostsGroupMini({ latestPosts, siteInfo }) {
)
})}
</>
)
) : null
}

View File

@@ -6,73 +6,83 @@ import { siteConfig } from '@/lib/config'
* @constructor
*/
const SocialButton = () => {
const CONTACT_GITHUB = siteConfig('CONTACT_GITHUB')
const CONTACT_TWITTER = siteConfig('CONTACT_TWITTER')
const CONTACT_TELEGRAM = siteConfig('CONTACT_TELEGRAM')
const CONTACT_LINKEDIN = siteConfig('CONTACT_LINKEDIN')
const CONTACT_WEIBO = siteConfig('CONTACT_WEIBO')
const CONTACT_INSTAGRAM = siteConfig('CONTACT_INSTAGRAM')
const CONTACT_EMAIL = siteConfig('CONTACT_EMAIL')
const ENABLE_RSS = siteConfig('ENABLE_RSS')
const CONTACT_BILIBILI = siteConfig('CONTACT_BILIBILI')
const CONTACT_YOUTUBE = siteConfig('CONTACT_YOUTUBE')
return (
<div className='w-full justify-center flex-wrap flex'>
<div className='space-x-12 text-3xl text-gray-600 dark:text-gray-300 '>
{siteConfig('CONTACT_GITHUB') && (
{CONTACT_GITHUB && (
<a
target='_blank'
rel='noreferrer'
title={'github'}
href={siteConfig('CONTACT_GITHUB')}>
href={CONTACT_GITHUB}>
<i className='transform hover:scale-125 duration-150 fab fa-github dark:hover:text-indigo-400 hover:text-indigo-600' />
</a>
)}
{siteConfig('CONTACT_TWITTER') && (
{CONTACT_TWITTER && (
<a
target='_blank'
rel='noreferrer'
title={'twitter'}
href={siteConfig('CONTACT_TWITTER')}>
href={CONTACT_TWITTER}>
<i className='transform hover:scale-125 duration-150 fab fa-twitter dark:hover:text-indigo-400 hover:text-indigo-600' />
</a>
)}
{siteConfig('CONTACT_TELEGRAM') && (
{CONTACT_TELEGRAM && (
<a
target='_blank'
rel='noreferrer'
href={siteConfig('CONTACT_TELEGRAM')}
href={CONTACT_TELEGRAM}
title={'telegram'}>
<i className='transform hover:scale-125 duration-150 fab fa-telegram dark:hover:text-indigo-400 hover:text-indigo-600' />
</a>
)}
{siteConfig('CONTACT_LINKEDIN') && (
{CONTACT_LINKEDIN && (
<a
target='_blank'
rel='noreferrer'
href={siteConfig('CONTACT_LINKEDIN')}
href={CONTACT_LINKEDIN}
title={'linkIn'}>
<i className='transform hover:scale-125 duration-150 fab fa-linkedin dark:hover:text-indigo-400 hover:text-indigo-600' />
</a>
)}
{siteConfig('CONTACT_WEIBO') && (
{CONTACT_WEIBO && (
<a
target='_blank'
rel='noreferrer'
title={'weibo'}
href={siteConfig('CONTACT_WEIBO')}>
href={CONTACT_WEIBO}>
<i className='transform hover:scale-125 duration-150 fab fa-weibo dark:hover:text-indigo-400 hover:text-indigo-600' />
</a>
)}
{siteConfig('CONTACT_INSTAGRAM') && (
{CONTACT_INSTAGRAM && (
<a
target='_blank'
rel='noreferrer'
title={'instagram'}
href={siteConfig('CONTACT_INSTAGRAM')}>
href={CONTACT_INSTAGRAM}>
<i className='transform hover:scale-125 duration-150 fab fa-instagram dark:hover:text-indigo-400 hover:text-indigo-600' />
</a>
)}
{siteConfig('CONTACT_EMAIL') && (
{CONTACT_EMAIL && (
<a
target='_blank'
rel='noreferrer'
title={'email'}
href={`mailto:${siteConfig('CONTACT_EMAIL')}`}>
href={`mailto:${CONTACT_EMAIL}`}>
<i className='transform hover:scale-125 duration-150 fas fa-envelope dark:hover:text-indigo-400 hover:text-indigo-600' />
</a>
)}
{JSON.parse(siteConfig('ENABLE_RSS')) && (
{JSON.parse(ENABLE_RSS) && (
<a
target='_blank'
rel='noreferrer'
@@ -81,21 +91,21 @@ const SocialButton = () => {
<i className='transform hover:scale-125 duration-150 fas fa-rss dark:hover:text-indigo-400 hover:text-indigo-600' />
</a>
)}
{siteConfig('CONTACT_BILIBILI') && (
{CONTACT_BILIBILI && (
<a
target='_blank'
rel='noreferrer'
title={'bilibili'}
href={siteConfig('CONTACT_BILIBILI')}>
href={CONTACT_BILIBILI}>
<i className='transform hover:scale-125 duration-150 fab fa-bilibili dark:hover:text-indigo-400 hover:text-indigo-600' />
</a>
)}
{siteConfig('CONTACT_YOUTUBE') && (
{CONTACT_YOUTUBE && (
<a
target='_blank'
rel='noreferrer'
title={'youtube'}
href={siteConfig('CONTACT_YOUTUBE')}>
href={CONTACT_YOUTUBE}>
<i className='transform hover:scale-125 duration-150 fab fa-youtube dark:hover:text-indigo-400 hover:text-indigo-600' />
</a>
)}

View File

@@ -267,6 +267,7 @@ const LayoutSlug = props => {
siteConfig('COMMENT_WEBMENTION_ENABLE')
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 404
if (!post) {
@@ -283,7 +284,7 @@ const LayoutSlug = props => {
}
}
},
siteConfig('POST_WAITING_TIME_FOR_404') * 1000
waiting404
)
}
}, [post])

View File

@@ -263,6 +263,7 @@ const LayoutArchive = props => {
const LayoutSlug = props => {
const { post, lock, validPassword } = props
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 404
if (!post) {
@@ -277,7 +278,7 @@ const LayoutSlug = props => {
}
}
},
siteConfig('POST_WAITING_TIME_FOR_404') * 1000
waiting404
)
}
}, [post])

View File

@@ -76,6 +76,7 @@ const LayoutSlug = props => {
// 如果 是 /article/[slug] 的文章路径则进行重定向到另一个域名
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 404
if (!post) {
@@ -90,7 +91,7 @@ const LayoutSlug = props => {
}
}
},
siteConfig('POST_WAITING_TIME_FOR_404') * 1000
waiting404
)
}
}, [post])

View File

@@ -225,6 +225,7 @@ const LayoutSlug = props => {
const { post, lock, validPassword } = props
const { fullWidth } = useGlobal()
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 404
if (!post) {
@@ -239,7 +240,7 @@ const LayoutSlug = props => {
}
}
},
siteConfig('POST_WAITING_TIME_FOR_404') * 1000
waiting404
)
}
}, [post])

View File

@@ -185,6 +185,7 @@ const LayoutSlug = props => {
)
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 404
if (!post) {
@@ -201,7 +202,7 @@ const LayoutSlug = props => {
}
}
},
siteConfig('POST_WAITING_TIME_FOR_404') * 1000
waiting404
)
}
}, [post])

View File

@@ -152,6 +152,7 @@ const LayoutPostList = props => {
const LayoutSlug = props => {
const { post, lock, validPassword } = props
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 用js 实现将页面中的多个视频聚合为一个分集的视频
function combineVideo() {
@@ -299,7 +300,7 @@ const LayoutSlug = props => {
}
}
},
siteConfig('POST_WAITING_TIME_FOR_404') * 1000
waiting404
)
}
return () => {

View File

@@ -255,6 +255,7 @@ const LayoutPostList = props => {
const LayoutSlug = props => {
const { post, lock, validPassword } = props
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 404
if (!post) {
@@ -269,7 +270,7 @@ const LayoutSlug = props => {
}
}
},
siteConfig('POST_WAITING_TIME_FOR_404') * 1000
waiting404
)
}
}, [post])

View File

@@ -322,6 +322,7 @@ const LayoutSlug = props => {
const { post, lock, validPassword } = props
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 404
if (!post) {
@@ -336,7 +337,7 @@ const LayoutSlug = props => {
}
}
},
siteConfig('POST_WAITING_TIME_FOR_404') * 1000
waiting404
)
}
}, [post])

View File

@@ -221,6 +221,7 @@ const LayoutArchive = props => {
const LayoutSlug = props => {
const { post, lock, validPassword } = props
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 404
if (!post) {
@@ -235,7 +236,7 @@ const LayoutSlug = props => {
}
}
},
siteConfig('POST_WAITING_TIME_FOR_404') * 1000
waiting404
)
}
}, [post])

View File

@@ -152,6 +152,7 @@ const LayoutPostList = props => {
const LayoutSlug = props => {
const { post, lock, validPassword } = props
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 用js 实现将页面中的多个视频聚合为一个分集的视频
function combineVideo() {
@@ -299,7 +300,7 @@ const LayoutSlug = props => {
}
}
},
siteConfig('POST_WAITING_TIME_FOR_404') * 1000
waiting404
)
}
return () => {

View File

@@ -176,6 +176,7 @@ const LayoutArchive = props => {
const LayoutSlug = props => {
const { post, lock, validPassword } = props
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 404
if (!post) {
@@ -190,7 +191,7 @@ const LayoutSlug = props => {
}
}
},
siteConfig('POST_WAITING_TIME_FOR_404') * 1000
waiting404
)
}
}, [post])

View File

@@ -267,6 +267,7 @@ const LayoutSlug = props => {
const Layout404 = props => {
const { post } = props
const router = useRouter()
const waiting404 = siteConfig('POST_WAITING_TIME_FOR_404') * 1000
useEffect(() => {
// 404
if (!post) {
@@ -281,7 +282,7 @@ const Layout404 = props => {
}
}
},
siteConfig('POST_WAITING_TIME_FOR_404') * 1000
waiting404
)
}
}, [post])