@@ -4,6 +4,7 @@ import BaseLayout from "@/layouts/base.astro";
44import ContentLayout from " @/layouts/content.astro" ;
55import ArticleHeader from " ../../../_components/article-header.astro" ;
66import Giscus from " @/components/elements/giscus.astro" ;
7+ import AdUnit from " @/components/elements/AdUnit.astro" ;
78import NewsCard from " @/components/cards/newsCard.astro" ;
89import { SITE } from " @/lib/config" ;
910
@@ -98,8 +99,9 @@ if (recommended.length < 3) {
9899 </details >
99100 </div >
100101 </div >
101- <ContentLayout >
102+ <ContentLayout showAds = { true } >
102103 <Content />
104+ <AdUnit adSlot =" 2308296961" adLayout =" in-article" adFormat =" fluid" />
103105 </ContentLayout >
104106
105107 {
@@ -261,4 +263,37 @@ if (recommended.length < 3) {
261263 }
262264 document.addEventListener("astro:page-load", initTOC);
263265 document.addEventListener("astro:after-swap", initTOC);
266+
267+ // Position the ad after the 3rd paragraph
268+ function positionArticleAd() {
269+ const articleContent = document.getElementById("article-content");
270+ const adContainer = document.querySelector(".ad-container");
271+
272+ if (!articleContent || !adContainer) return;
273+
274+ // Get all paragraphs in the article
275+ const paragraphs = articleContent.querySelectorAll("p");
276+
277+ // Move ad after the 3rd paragraph (if it exists)
278+ if (paragraphs.length >= 3) {
279+ const targetParagraph = paragraphs[2];
280+ targetParagraph.parentNode.insertBefore(
281+ adContainer,
282+ targetParagraph.nextSibling
283+ );
284+ }
285+ }
286+
287+ // Run ad positioning after TOC is initialized
288+ const initAds = () => {
289+ setTimeout(positionArticleAd, 100); // Small delay to ensure content is rendered
290+ };
291+
292+ if (document.readyState === "loading") {
293+ document.addEventListener("DOMContentLoaded", initAds, { once: true });
294+ } else {
295+ initAds();
296+ }
297+ document.addEventListener("astro:page-load", initAds);
298+ document.addEventListener("astro:after-swap", initAds);
264299</script >
0 commit comments