+ {youtubeVideos?.items
?.filter((video) => video.id.videoId)
?.map((video) => (
{
diff --git a/components/data/youtube.js b/components/data/youtube.js
new file mode 100644
index 00000000..4f284d68
--- /dev/null
+++ b/components/data/youtube.js
@@ -0,0 +1,26 @@
+const API_KEY = process.env.YOUTUBE_API_KEY;
+const CHANNEL_ID = process.env.YOUTUBE_CHANNEL_ID;
+
+export const fetchYouTubeStats = async () => {
+ try {
+ const response = await fetch(
+ `https://www.googleapis.com/youtube/v3/channels?part=statistics&id=${CHANNEL_ID}&key=${API_KEY}`
+ );
+ return await response.json();
+ } catch (error) {
+ console.error("Error fetching YouTube stats:", error);
+ return null;
+ }
+};
+
+export const fetchYouTubeVideos = async () => {
+ try {
+ const response = await fetch(
+ `https://www.googleapis.com/youtube/v3/search?key=${API_KEY}&channelId=${CHANNEL_ID}&part=snippet,id&order=date&maxResults=3`
+ );
+ return await response.json();
+ } catch (error) {
+ console.error("Error fetching YouTube videos:", error);
+ return null;
+ }
+};
diff --git a/next.config.js b/next.config.js
index 800514bd..a1cff71f 100644
--- a/next.config.js
+++ b/next.config.js
@@ -18,6 +18,11 @@ const nextConfig = {
images: {
domains: ["i.ytimg.com", "cdn.hashnode.com", "wsrv.nl"],
},
+ // Add environment variables configuration
+ env: {
+ YOUTUBE_API_KEY: process.env.YOUTUBE_API_KEY,
+ YOUTUBE_CHANNEL_ID: process.env.YOUTUBE_CHANNEL_ID,
+ },
};
module.exports = nextConfig;