Skip to content

Commit 7b1af84

Browse files
AnnatarHegithub-actions[bot]claude
authored
feat: add Google AdSense to post detail pages (#47)
* feat: add Google AdSense to post detail pages - Created AdSense component with responsive ad unit - Integrated AdSense script in post page head - Positioned ad at the end of article content - Added TODO comments for AdSense client ID and slot ID configuration Co-authored-by: Le He <AnnatarHe@users.noreply.github.com> * refactor(ads): consolidate AdSense script loading in main layout Move AdSense initialization script from post detail page to the main Layout component for centralized management. Update AdSense client ID from placeholder to production value. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor(ads): remove unnecessary frontmatter comments from AdSense component Remove TODO comments and frontmatter section that are no longer needed after AdSense integration is complete. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Le He <AnnatarHe@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent ff4bdeb commit 7b1af84

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/components/AdSense.astro

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<div class="adsense-container my-8">
2+
<ins
3+
class="adsbygoogle"
4+
style="display:block; text-align:center;"
5+
data-ad-client="ca-pub-4489403687940405"
6+
data-ad-slot="XXXXXXXXXX"
7+
data-ad-format="auto"
8+
data-full-width-responsive="true"
9+
></ins>
10+
</div>
11+
12+
<script is:inline>
13+
(adsbygoogle = window.adsbygoogle || []).push({});
14+
</script>
15+
16+
<style>
17+
.adsense-container {
18+
max-width: 100%;
19+
margin-left: auto;
20+
margin-right: auto;
21+
}
22+
</style>

src/layouts/Layout.astro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ const { title } = Astro.props;
2727
href={`${Astro.site}rss.xml`}
2828
/>
2929
<slot name="seo" />
30+
<script
31+
is:inline
32+
async
33+
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4489403687940405"
34+
crossorigin="anonymous"
35+
/>
3036
<title>{title}</title>
3137
</head>
3238
<body>

src/pages/posts/[...slug].astro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import A from "../../components/markdown/A.astro";
1818
import P from "../../components/markdown/P.astro";
1919
import type { InferGetStaticPropsType } from "astro";
2020
import Player from "../../components/Player.astro";
21+
import AdSense from "../../components/AdSense.astro";
2122
2223
export async function getStaticPaths() {
2324
const posts = await getCollection("posts");
@@ -161,6 +162,7 @@ const imgUrl = `${Astro.site?.origin}${post.slug}-og.png`;
161162
}}
162163
/>
163164
<Hr className="my-10" />
165+
<AdSense />
164166
</article>
165167
</div>
166168
</PageLayout>
@@ -175,4 +177,4 @@ const imgUrl = `${Astro.site?.origin}${post.slug}-og.png`;
175177
-webkit-background-clip: text;
176178
-webkit-text-fill-color: transparent;
177179
}
178-
</style>
180+
</style>

0 commit comments

Comments
 (0)