Adjust ad frequency based on screen size for better readability
Update the article page component to conditionally render in-article ads based on screen size, adjusting the ad interval to 2 paragraphs on mobile and 3 paragraphs on desktop. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 23852c00-4779-460a-9e0c-d09fee4b6c92 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 71dd7028-e240-41df-840f-276a7aa7cd8d Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/23852c00-4779-460a-9e0c-d09fee4b6c92/OPD8Ro3 Replit-Helium-Checkpoint-Created: true
This commit is contained in:
parent
82aa204b2c
commit
2544e9d2e2
@ -10,6 +10,7 @@ import { Skeleton } from "@/components/ui/skeleton";
|
||||
import Header from "@/components/header";
|
||||
import Footer from "@/components/footer";
|
||||
import AdSense, { InArticleAd, PageSideAds } from "@/components/adsense";
|
||||
import { useIsMobile } from "@/hooks/use-mobile";
|
||||
import DOMPurify from "dompurify";
|
||||
import ShareButtons from "@/components/share-buttons";
|
||||
import InterstitialAd from "@/components/interstitial-ad";
|
||||
@ -98,6 +99,7 @@ function RelatedArticles({ currentSlug }: { currentSlug: string }) {
|
||||
|
||||
export default function ArticlePage() {
|
||||
const { slug } = useParams<{ slug: string }>();
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
const { data: article, isLoading, error } = useQuery<Article>({
|
||||
queryKey: ["/api/articles", slug],
|
||||
@ -298,7 +300,7 @@ export default function ArticlePage() {
|
||||
{(() => {
|
||||
const sanitized = sanitizeContent(article.content);
|
||||
const blocks = sanitized.split(/(?=<(?:p|h[2-4]|div)[\s>])/i).filter(Boolean);
|
||||
const AD_INTERVAL = 3;
|
||||
const AD_INTERVAL = isMobile ? 2 : 3;
|
||||
const segments: string[] = [];
|
||||
for (let i = 0; i < blocks.length; i += AD_INTERVAL) {
|
||||
segments.push(blocks.slice(i, i + AD_INTERVAL).join(""));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user