Improve ad loading and video title formatting for better user experience
Add a delay and width check for AdSense ad initialization in `adsense-ad.tsx` and clean video titles by removing `.mp4` extensions in `bunny.ts`. Replit-Commit-Author: Agent Replit-Commit-Session-Id: c5d5630c-85af-4c2b-bf4e-7e8006d34256 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/60d372ff-2c10-46c7-b01b-10c3435136b0/c5d5630c-85af-4c2b-bf4e-7e8006d34256/HcYyIPk
This commit is contained in:
parent
2a67922121
commit
04999a38cd
@ -18,15 +18,25 @@ export default function AdSenseAd({
|
||||
const adRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
// Ensure adsbygoogle is loaded
|
||||
if (typeof window !== 'undefined') {
|
||||
// @ts-ignore
|
||||
(window.adsbygoogle = window.adsbygoogle || []).push({});
|
||||
const timer = setTimeout(() => {
|
||||
try {
|
||||
// Ensure adsbygoogle is loaded
|
||||
if (typeof window !== 'undefined' && adRef.current) {
|
||||
// Check if element has width before initializing ad
|
||||
const elementWidth = adRef.current.offsetWidth;
|
||||
if (elementWidth > 0) {
|
||||
// @ts-ignore
|
||||
(window.adsbygoogle = window.adsbygoogle || []).push({});
|
||||
} else {
|
||||
console.warn('AdSense element has no width, skipping initialization');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('AdSense initialization error:', error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('AdSense initialization error:', error);
|
||||
}
|
||||
}, 100); // Small delay to ensure DOM is rendered
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}, []);
|
||||
|
||||
const adStyle: React.CSSProperties = {
|
||||
@ -42,7 +52,7 @@ export default function AdSenseAd({
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`adsense-wrapper ${className}`} ref={adRef}>
|
||||
<div className={`adsense-wrapper ${className}`} ref={adRef} style={{ minWidth: '300px', minHeight: '250px' }}>
|
||||
<ins
|
||||
className="adsbygoogle"
|
||||
style={adStyle}
|
||||
|
||||
@ -100,9 +100,15 @@ export class BunnyService {
|
||||
// No tags from Bunny.net - keeping tags empty
|
||||
const tags: string[] = [];
|
||||
|
||||
// Clean up title by removing .mp4 extension if present
|
||||
let cleanTitle = bunnyVideo.title || 'Untitled Video';
|
||||
if (cleanTitle.toLowerCase().endsWith('.mp4')) {
|
||||
cleanTitle = cleanTitle.slice(0, -4);
|
||||
}
|
||||
|
||||
return {
|
||||
id: bunnyVideo.guid,
|
||||
title: bunnyVideo.title || 'Untitled Video',
|
||||
title: cleanTitle,
|
||||
artist: null, // No artist data from Bunny.net
|
||||
description: description,
|
||||
filename: null, // No filename data from Bunny.net
|
||||
|
||||
Loading…
Reference in New Issue
Block a user