diff --git a/src/app/gallery/page.tsx b/src/app/gallery/page.tsx index a07d9fa..14b11a8 100644 --- a/src/app/gallery/page.tsx +++ b/src/app/gallery/page.tsx @@ -8,13 +8,61 @@ export const metadata: Metadata = { description: "Watch YouTube commentary and analysis on Chelsea Smallwood, The Other Woman and the Wife, and the ongoing controversy.", }; -const videos = [ - { id: 'R35g0-dG6Xw', title: 'Life Coach CHELSEA SMALLWOOD Is SUING Her HUSBANDS Ex Wife... It Gets WORSE' }, - { id: 'vV_uImy858s', title: 'The Infidelity "Coach" Who Monetizes Affairs Is Now Suing The Betrayed Wife' }, - { id: 'JmUaAAbA9wU', title: 'Affair Coach Chelsea Smallwood Is SUING The Ex-Wife... Allegedly' }, +interface Video { + id: string; + title: string; +} + +// Just list the YouTube Video IDs here +const videoIds = [ + 'R35g0-dG6Xw', + 'vV_uImy858s', + 'JmUaAAbA9wU', ]; -export default function GalleryPage() { +// Fallback data in case the YouTube API call fails or the key is not provided. +const fallbackData: Video[] = [ + { id: 'R35g0-dG6Xw', title: 'Life Coach CHELSEA SMALLWOOD Is SUING Her HUSBANDS Ex Wife... It Gets WORSE' }, + { id: 'vV_uImy858s', title: 'The Infidelity "Coach" Who Monetizes Affairs Is Now Suing The Betrayed Wife' }, + { id: 'JmUaAAbA9wU', title: 'Affair Coach Chelsea Smallwood Is SUING The Ex-Wife... Allegedly' }, +]; + +async function getYouTubeVideos(ids: string[]): Promise { + const apiKey = process.env.YOUTUBE_API_KEY; + + if (!apiKey) { + console.warn("YOUTUBE_API_KEY environment variable not set. Using hardcoded video titles as fallback."); + return fallbackData.filter(video => ids.includes(video.id)); + } + + const url = `https://www.googleapis.com/youtube/v3/videos?part=snippet&id=${ids.join(',')}&key=${apiKey}`; + + try { + const response = await fetch(url, { next: { revalidate: 3600 } }); // Revalidate every hour + if (!response.ok) { + const errorData = await response.json(); + console.error("YouTube API Error:", errorData.error.message); + return fallbackData.filter(video => ids.includes(video.id)); + } + + const data = await response.json(); + if (!data.items || data.items.length === 0) { + return fallbackData.filter(video => ids.includes(video.id)); + } + + return data.items.map((item: any) => ({ + id: item.id, + title: item.snippet.title, + })); + } catch (error) { + console.error("Failed to fetch from YouTube API:", error); + return fallbackData.filter(video => ids.includes(video.id)); + } +} + +export default async function GalleryPage() { + const videos = await getYouTubeVideos(videoIds); + return (
@@ -29,7 +77,7 @@ export default function GalleryPage() {
- {videos.map((video) => ( + {videos.length > 0 ? videos.map((video) => (