File tree Expand file tree Collapse file tree 3 files changed +52
-40
lines changed Expand file tree Collapse file tree 3 files changed +52
-40
lines changed Original file line number Diff line number Diff line change 1- "use client" ;
2-
31import Script from "next/script" ;
42import {
53 Card ,
64 CardContent ,
75 CardHeader ,
86 CardTitle ,
97} from "@workspace/ui/components/card" ;
8+ import { AdsenseAd } from "@/components/adsense-ad" ;
109
1110export default function HookAside ( ) {
1211 return (
@@ -32,24 +31,7 @@ export default function HookAside() {
3231 </ CardContent >
3332 </ Card >
3433
35- < div className = "mt-4" >
36- < ins
37- className = "adsbygoogle"
38- style = { { display : "block" } }
39- data-ad-client = "ca-pub-1640905025052378"
40- data-ad-slot = "9540285659"
41- data-ad-format = "auto"
42- data-full-width-responsive = "true"
43- />
44-
45- < Script
46- id = "adsense-docs-aside"
47- strategy = "afterInteractive"
48- dangerouslySetInnerHTML = { {
49- __html : "(adsbygoogle = window.adsbygoogle || []).push({});" ,
50- } }
51- />
52- </ div >
34+ < AdsenseAd adSlot = "9540285659" className = "mt-4" />
5335 </ aside >
5436 ) ;
5537}
Original file line number Diff line number Diff line change 1- "use client" ;
2-
31import Script from "next/script" ;
42import {
53 Card ,
64 CardHeader ,
75 CardTitle ,
86 CardContent ,
97} from "@workspace/ui/components/card" ;
8+ import { AdsenseAd } from "@/components/adsense-ad" ;
109
1110export default function DocsAside ( ) {
1211 return (
@@ -32,24 +31,7 @@ export default function DocsAside() {
3231 </ CardContent >
3332 </ Card >
3433
35- < div className = "mt-4" >
36- < ins
37- className = "adsbygoogle"
38- style = { { display : "block" } }
39- data-ad-client = "ca-pub-1640905025052378"
40- data-ad-slot = "9540285659"
41- data-ad-format = "auto"
42- data-full-width-responsive = "true"
43- />
44-
45- < Script
46- id = "adsense-docs-aside"
47- strategy = "afterInteractive"
48- dangerouslySetInnerHTML = { {
49- __html : "(adsbygoogle = window.adsbygoogle || []).push({});" ,
50- } }
51- />
52- </ div >
34+ < AdsenseAd adSlot = "9540285659" className = "mt-4" />
5335 </ aside >
5436 ) ;
5537}
Original file line number Diff line number Diff line change 1+ import Script from "next/script" ;
2+ import type { CSSProperties } from "react" ;
3+
4+ type AdsenseAdProps = {
5+ adSlot : string ;
6+ adClient ?: string ;
7+ adFormat ?: string ;
8+ fullWidthResponsive ?: boolean ;
9+ className ?: string ;
10+ style ?: CSSProperties ;
11+ scriptId ?: string ;
12+ } ;
13+
14+ export function AdsenseAd ( {
15+ adSlot,
16+ adClient = process . env . NEXT_PUBLIC_AD_CLIENT_ID ,
17+ adFormat = "auto" ,
18+ fullWidthResponsive = true ,
19+ className,
20+ style = { display : "block" } ,
21+ scriptId,
22+ } : AdsenseAdProps ) {
23+ // If client ID is missing, avoid rendering to prevent runtime errors
24+ if ( ! adClient ) {
25+ return null ;
26+ }
27+
28+ return (
29+ < div className = { className } >
30+ < ins
31+ className = "adsbygoogle"
32+ style = { style }
33+ data-ad-client = { adClient }
34+ data-ad-slot = { adSlot }
35+ data-ad-format = { adFormat }
36+ data-full-width-responsive = { fullWidthResponsive ? "true" : "false" }
37+ />
38+
39+ < Script
40+ id = { scriptId ?? `adsense-${ adSlot } ` }
41+ strategy = "afterInteractive"
42+ dangerouslySetInnerHTML = { {
43+ __html : "(adsbygoogle = window.adsbygoogle || []).push({});" ,
44+ } }
45+ />
46+ </ div >
47+ ) ;
48+ }
You can’t perform that action at this time.
0 commit comments