Skip to content

Commit d72229f

Browse files
committed
feat: add Google AdSense block below related posts section
1 parent 4119ddb commit d72229f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pages/post/[id].tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ import { ArrowDownCircle } from 'lucide-react';
1616
import { Tabs, Tab } from "../../components/Tabs";
1717
import {serialize} from "next-mdx-remote/serialize";
1818

19+
declare global {
20+
interface Window {
21+
adsbygoogle: unknown[];
22+
}
23+
}
24+
1925
type PostData = {
2026
id: string;
2127
title: string;
@@ -63,6 +69,14 @@ export default function Post({ postData, relatedPosts }: InferGetStaticPropsType
6369
const visibleRelatedPosts = relatedPosts.slice(0, visibleRelatedCount);
6470
const hasMoreRelated = visibleRelatedCount < relatedPosts.length;
6571

72+
useEffect(() => {
73+
try {
74+
(window.adsbygoogle = window.adsbygoogle || []).push({});
75+
} catch (e) {
76+
console.error("Adsbygoogle push error:", e);
77+
}
78+
}, []);
79+
6680
useEffect(() => {
6781
const el = scrollRef.current;
6882
if (el && el.scrollHeight > el.clientHeight) {

0 commit comments

Comments
 (0)