Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gitbook-adsense #1214

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions blog.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ const BLOG = {

// 谷歌广告
ADSENSE_GOOGLE_ID: process.env.NEXT_PUBLIC_ADSENSE_GOOGLE_ID || '', // 谷歌广告ID e.g ca-pub-xxxxxxxxxxxxxxxx
ADSENSE_GOOGLE_TEST: process.env.NEXT_PUBLIC_ADSENSE_GOOGLE_TEST || false, // 谷歌广告ID测试模式,这种模式获取假的测试广告,用于开发 https://www.tangly1024.com/article/local-dev-google-adsense

// 自定义配置notion数据库字段名
NOTION_PROPERTY_NAME: {
Expand Down
6 changes: 5 additions & 1 deletion components/GoogleAdsense.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,18 @@ const AdSlot = ({ type = 'show' }) => {
style={{ display: 'block', textAlign: 'center' }}
data-ad-layout="in-article"
data-ad-format="fluid"
data-adtest={BLOG.ADSENSE_GOOGLE_TEST ? 'on' : 'off'}
data-ad-client={BLOG.ADSENSE_GOOGLE_ID}
data-ad-slot="3806269138"></ins>
}

// 信息流广告
// 信息流广告
if (type === 'flow') {
return <ins className="adsbygoogle"
data-ad-format="fluid"
data-ad-layout-key="-5j+cz+30-f7+bf"
style={{ display: 'block' }}
data-adtest={BLOG.ADSENSE_GOOGLE_TEST ? 'on' : 'off'}
data-ad-client={BLOG.ADSENSE_GOOGLE_ID}
data-ad-slot="1510444138"></ins>
}
Expand All @@ -67,6 +69,7 @@ const AdSlot = ({ type = 'show' }) => {
return <ins className="adsbygoogle"
style={{ display: 'block', textAlign: 'center' }}
data-ad-format="autorelaxed"
data-adtest={BLOG.ADSENSE_GOOGLE_TEST ? 'on' : 'off'}
data-ad-client={BLOG.ADSENSE_GOOGLE_ID}
data-ad-slot="4980048999"></ins>
}
Expand All @@ -75,6 +78,7 @@ const AdSlot = ({ type = 'show' }) => {
return <ins className="adsbygoogle"
style={{ display: 'block' }}
data-ad-client={BLOG.ADSENSE_GOOGLE_ID}
data-adtest={BLOG.ADSENSE_GOOGLE_TEST ? 'on' : 'off'}
data-ad-slot="8807314373"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
Expand Down
19 changes: 16 additions & 3 deletions themes/gitbook/LayoutBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useRouter } from 'next/router'
import Announcement from './components/Announcement'
import PageNavDrawer from './components/PageNavDrawer'
import FloatTocButton from './components/FloatTocButton'
import { AdSlot } from '@/components/GoogleAdsense'
const ThemeGlobalMedium = createContext()

/**
Expand Down Expand Up @@ -65,6 +66,8 @@ const LayoutBase = (props) => {
{/* 所有文章列表 */}
<BlogPostListScroll posts={filterPosts} />

<AdSlot />

</div>
</div>

Expand All @@ -73,8 +76,12 @@ const LayoutBase = (props) => {
<div id='container-inner' className='w-full px-7 max-w-3xl justify-center mx-auto'>
{slotTop}

<AdSlot type='in-article' />

{onLoading ? LoadingCover : children}

<AdSlot type='in-article' />

{/* 回顶按钮 */}
<div
data-aos="fade-up"
Expand All @@ -88,14 +95,18 @@ const LayoutBase = (props) => {

{/* 底部 */}
<Footer title={siteInfo?.title} />

<div className='text-center'>
<AdSlot type='native' />
</div>
</div>

{/* 右侧侧推拉抽屉 */}
<div style={{ width: '32rem' }} className={'hidden xl:block dark:border-transparent relative z-10 '}>
<div className='py-14 px-6 sticky top-0'>
<ArticleInfo post={props?.post ? props?.post : props.notice} />

<div className='pt-6'>
<div className='py-6'>
<Catalog {...props} />
{slotRight}
{router.route === '/' && <>
Expand All @@ -107,16 +118,18 @@ const LayoutBase = (props) => {
<Announcement {...props} />
</div>

<AdSlot />

</div>
</div>

</main>

{showTocButton && !tocVisible && <div className='md:hidden fixed right-0 bottom-52 z-30 bg-white border-l border-t border-b dark:border-gray-800 rounded'>
<FloatTocButton {...props}/>
<FloatTocButton {...props} />
</div>}

<PageNavDrawer {...props}/>
<PageNavDrawer {...props} />

{/* 移动端底部导航栏 */}
<BottomMenuBar {...props} className='block md:hidden' />
Expand Down
4 changes: 4 additions & 0 deletions themes/gitbook/LayoutSlug.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import TocDrawer from './components/TocDrawer'
import CategoryItem from './components/CategoryItem'
import TagItemMini from './components/TagItemMini'
import ShareBar from '@/components/ShareBar'
import { AdSlot } from '@/components/GoogleAdsense'

export const LayoutSlug = (props) => {
const { post, prev, next, lock, validPassword } = props
Expand Down Expand Up @@ -41,6 +42,9 @@ export const LayoutSlug = (props) => {
</div>

{post?.type === 'Post' && <ArticleAround prev={prev} next={next} />}

<AdSlot/>

<Comment frontMatter={post} />
</section>

Expand Down