diff --git a/components/GoogleAdsense.js b/components/GoogleAdsense.js index 5f17f6ae..f102847b 100644 --- a/components/GoogleAdsense.js +++ b/components/GoogleAdsense.js @@ -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 且内容为 '' 的 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') diff --git a/components/NotionPage.js b/components/NotionPage.js index 0ac8c1c0..a3f1a085 100644 --- a/components/NotionPage.js +++ b/components/NotionPage.js @@ -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) } diff --git a/components/SEO.js b/components/SEO.js index b82087f3..b102ed11 100644 --- a/components/SEO.js +++ b/components/SEO.js @@ -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 (
@@ -154,7 +160,7 @@ const SEO = props => { {meta?.type === 'Post' && ( <> - + > @@ -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' diff --git a/lib/config.js b/lib/config.js index 2d46b6fb..bf03f95f 100644 --- a/lib/config.js +++ b/lib/config.js @@ -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) { diff --git a/themes/example/index.js b/themes/example/index.js index d78e20a4..412366e1 100644 --- a/themes/example/index.js +++ b/themes/example/index.js @@ -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]) diff --git a/themes/fukasawa/index.js b/themes/fukasawa/index.js index 0e2cf9d3..d184f1f9 100644 --- a/themes/fukasawa/index.js +++ b/themes/fukasawa/index.js @@ -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]) diff --git a/themes/gitbook/index.js b/themes/gitbook/index.js index b737e9f8..47598cf1 100644 --- a/themes/gitbook/index.js +++ b/themes/gitbook/index.js @@ -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]) diff --git a/themes/heo/components/Footer.js b/themes/heo/components/Footer.js index 2d189ee7..22255468 100644 --- a/themes/heo/components/Footer.js +++ b/themes/heo/components/Footer.js @@ -8,6 +8,7 @@ import SocialButton from './SocialButton' * @returns */ const Footer = () => { + const BEI_AN = siteConfig('BEI_AN') return (