diff --git a/client/index.html b/client/index.html index 8818917..9421193 100644 --- a/client/index.html +++ b/client/index.html @@ -9,6 +9,7 @@ + diff --git a/client/src/components/adsense.tsx b/client/src/components/adsense.tsx new file mode 100644 index 0000000..a92eec0 --- /dev/null +++ b/client/src/components/adsense.tsx @@ -0,0 +1,89 @@ +import { useEffect, useRef } from "react"; + +type AdFormat = "auto" | "fluid" | "rectangle" | "horizontal" | "vertical"; + +interface AdSenseProps { + slot: string; + format?: AdFormat; + responsive?: boolean; + className?: string; + style?: Record; + layout?: string; + layoutKey?: string; +} + +export default function AdSense({ + slot, + format = "auto", + responsive = true, + className = "", + style, + layout, + layoutKey, +}: AdSenseProps) { + const adRef = useRef(null); + const pushed = useRef(false); + + useEffect(() => { + if (pushed.current) return; + try { + const adsbygoogle = (window as any).adsbygoogle || []; + adsbygoogle.push({}); + pushed.current = true; + } catch (e) { + } + }, []); + + return ( +
+ +
+ ); +} + +export function ArticleCardAd() { + return ( +
+ +
+ ); +} + +export function InArticleAd() { + return ( + + ); +} + +export function SidebarAd() { + return ( +
+ +
+ ); +} diff --git a/client/src/pages/article.tsx b/client/src/pages/article.tsx index 7c88e1f..0b25826 100644 --- a/client/src/pages/article.tsx +++ b/client/src/pages/article.tsx @@ -8,6 +8,7 @@ import { Button } from "@/components/ui/button"; import { Skeleton } from "@/components/ui/skeleton"; import Header from "@/components/header"; import Footer from "@/components/footer"; +import { InArticleAd } from "@/components/adsense"; import DOMPurify from "dompurify"; import { useEffect } from "react"; @@ -214,6 +215,8 @@ export default function ArticlePage() { data-testid="article-content" /> + +