export const dynamic = 'force-dynamic'; import React from 'react'; import PostCard from '@/components/PostCard'; import Sidebar from '@/components/Sidebar'; import { getSortedPostsData } from '@/lib/posts'; import { PostMetadata } from '@/types'; import Image from 'next/image'; // This function runs on the server during build time async function getHomeData() { const posts = await getSortedPostsData(); // Create tag data const allTags = posts.flatMap(post => post.tags); const tagCounts: Record = {}; allTags.forEach(tag => { tagCounts[tag] = (tagCounts[tag] || 0) + 1; }); const tags = Object.entries(tagCounts).map(([tag, count]) => ({ tag, count })); return { posts, recentPosts: posts.slice(0, 5).map(post => ({ id: post.id, title: post.title, date: post.date })), tags }; } // Make the component async export default async function Home() { // Fetch data directly in the component const { posts, recentPosts, tags } = await getHomeData(); return (
{posts.length > 0 && (
{posts[0].coverImage ? ( {posts[0].title} ) : (
CG
)}
Latest Post
{posts[0].title}

{posts[0].excerpt}

)}

Recent Posts

{posts.slice(1).map((post) => ( ))}
View All Posts
); }