diff --git a/components/ArticleDetail.js b/components/ArticleDetail.js index b8c6ddd3..56534a49 100644 --- a/components/ArticleDetail.js +++ b/components/ArticleDetail.js @@ -102,6 +102,7 @@ export default function ArticleDetail ({ post, blockMap, recommendPosts, prev, n
本文共0字,阅读需要约0分钟
+ {/* Notion文章主体 */} @@ -121,6 +122,17 @@ export default function ArticleDetail ({ post, blockMap, recommendPosts, prev, n )} +
+ {/* 文章内嵌广告 */} + +
+ {/* 推荐文章 */} @@ -165,10 +177,11 @@ export default function ArticleDetail ({ post, blockMap, recommendPosts, prev, n + {/* 评论互动 */} -
+
diff --git a/components/LatestPostsGroup.js b/components/LatestPostsGroup.js index 23dbe64e..c254b93b 100644 --- a/components/LatestPostsGroup.js +++ b/components/LatestPostsGroup.js @@ -31,14 +31,12 @@ const LatestPostsGroup = ({ posts, sliceCount = 5 }) => { const selected = currentPath === `${BLOG.path}/article/${post.slug}` return ( - +
+ 'hover:text-blue-500 dark:hover:text-blue-400 cursor-pointer hover:underline ' }> {post.title}
-
+
{formatDateFmt(post.lastEditedTime, 'yyyy/MM/dd')}
diff --git a/components/SideArea.js b/components/SideArea.js index ca3b0eda..8af1c25d 100644 --- a/components/SideArea.js +++ b/components/SideArea.js @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useEffect } from 'react' import MenuButtonGroup from '@/components/MenuButtonGroup' import InfoCard from '@/components/InfoCard' import TagGroups from '@/components/TagGroups' @@ -10,6 +10,7 @@ import { useGlobal } from '@/lib/global' import Toc from '@/components/Toc' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faAngleDoubleRight, faArchive, faTags, faThList } from '@fortawesome/free-solid-svg-icons' +const adsInit = false /** * 侧边平铺 @@ -25,6 +26,7 @@ import { faAngleDoubleRight, faArchive, faTags, faThList } from '@fortawesome/fr */ const SideArea = ({ title, tags, currentTag, post, posts, categories, currentCategory, currentSearch }) => { const { locale } = useGlobal() + return } diff --git a/components/ThirdPartyScript.js b/components/ThirdPartyScript.js index 2e994a5c..1b81d5d3 100644 --- a/components/ThirdPartyScript.js +++ b/components/ThirdPartyScript.js @@ -26,6 +26,10 @@ const ThirdPartyScript = () => { /> )} + {/* GoogleAdsense 广告植入 */} + {BLOG.googleAdsenseId && ( - {/* 信息流 */} - - {/* 展示广告 */} - - {/* 文章内嵌广告 */} - - - - )} )} ) } diff --git a/layouts/BaseLayout.js b/layouts/BaseLayout.js index f012986b..d13684c5 100644 --- a/layouts/BaseLayout.js +++ b/layouts/BaseLayout.js @@ -60,7 +60,7 @@ const BaseLayout = ({ return () => { window.removeEventListener('scroll', scrollTrigger) } - }) + }, []) const { onLoading, theme } = useGlobal() const targetRef = useRef(null) diff --git a/lib/global.js b/lib/global.js index d8c25e63..c37e5675 100644 --- a/lib/global.js +++ b/lib/global.js @@ -102,6 +102,31 @@ const initTheme = (theme, changeTheme) => { } } +export function handleRouteChange (url) { + console.log('路由变化', url) + initGoogleAdsense() +} + +/** + * 初始化谷歌广告 + */ +// let activeAdsCount = 0 +function initGoogleAdsense () { + const ads = document.getElementsByClassName('adsbygoogle').length + // const newAdsCount = ads - activeAdsCount + // console.log(`Start: 总广告${ads}, 已激活${activeAdsCount} 新广告${newAdsCount}`) + const newAdsCount = ads + if (newAdsCount > 0) { + for (let i = 0; i <= newAdsCount; i++) { + try { + (adsbygoogle = window.adsbygoogle || []).push({}) + } catch (e) { + + } + } + } +} + /** * 读取默认主题 * @returns {*} diff --git a/pages/_app.js b/pages/_app.js index 904096c8..3ddeecbf 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -1,12 +1,14 @@ +import BLOG from 'blog.config' import 'animate.css' import '@/styles/notion.css' import '@/styles/globals.css' import 'rc-dropdown/assets/index.css' import 'prismjs/themes/prism-okaidia.css' import 'katex/dist/katex.min.css' -import BLOG from 'blog.config' import dynamic from 'next/dynamic' -import { GlobalContextProvider } from '@/lib/global' +import { GlobalContextProvider, handleRouteChange } from '@/lib/global' +import { useEffect } from 'react' +import { useRouter } from 'next/router' import { config } from '@fortawesome/fontawesome-svg-core' import '@fortawesome/fontawesome-svg-core/styles.css' config.autoAddCss = false @@ -15,6 +17,18 @@ const Ackee = dynamic(() => import('@/components/Ackee'), { ssr: false }) const Gtag = dynamic(() => import('@/components/Gtag'), { ssr: false }) const MyApp = ({ Component, pageProps }) => { + // 全局监听路由变化 + const router = useRouter() + useEffect(() => { + handleRouteChange(router.pathname) + const routerListener = (url) => { + handleRouteChange(url) + } + router.events.on('routeChangeComplete', routerListener) + return () => { + router.events.off('routeChangeComplete', routerListener) + } + }) return ( {BLOG.isProd && BLOG?.analytics?.provider === 'ackee' && (