import { sql } from '@/lib/db' export const dynamic = "force-dynamic" import Image from 'next/image' import Link from 'next/link' async function getArticlesWithTags() { try { const { rows } = await sql` SELECT * FROM articles_with_tags ORDER BY published_at DESC LIMIT 20 ` return rows } catch (error) { console.error('Error fetching articles:', error) return [] } } async function getFeaturedArticle() { try { const { rows } = await sql` SELECT * FROM articles_with_tags ORDER BY view_count DESC LIMIT 1 ` return rows[0] || null } catch (error) { return null } } async function getTrendingTags() { try { const { rows } = await sql` SELECT t.name_burmese, t.slug, COUNT(at.article_id) as count FROM tags t JOIN article_tags at ON t.id = at.tag_id JOIN articles a ON at.article_id = a.id WHERE a.status = 'published' GROUP BY t.id ORDER BY count DESC LIMIT 15 ` return rows } catch (error) { return [] } } export default async function ImprovedHome() { const [articles, featured, trendingTags] = await Promise.all([ getArticlesWithTags(), getFeaturedArticle(), getTrendingTags() ]) return (
{/* Hero Section with Featured Article */} {featured && (
{featured.title_burmese}
{/* Category Badge */} {featured.category_name_burmese} {/* Title */}

{featured.title_burmese}

{/* Excerpt */}

{featured.excerpt_burmese}

{/* Tags */} {featured.tags_burmese && featured.tags_burmese.length > 0 && (
{featured.tags_burmese.slice(0, 5).map((tag: string, idx: number) => ( #{tag} ))}
)} {/* Read More Button */} ဖတ်ရန် →
)} {/* Main Content */}
{/* Trending Tags */} {trendingTags.length > 0 && (

🔥 လူကြိုက်များသော အကြောင်းအရာများ

{trendingTags.map((tag: any) => ( #{tag.name_burmese} ({tag.count}) ))}
)} {/* Article Grid */}

နောက်ဆုံးရ သတင်းများ

{articles.length === 0 ? (
📰

သတင်းမရှိသေးပါ။ မကြာမီ ပြန်စစ်ကြည့်ပါ။

) : (
{articles.map((article: any) => (
{/* Cover Image */} {article.featured_image && (
{article.title_burmese}
)}
{/* Category Badge */} {article.category_name_burmese} {/* Title */}

{article.title_burmese}

{/* Excerpt */}

{article.excerpt_burmese}

{/* Tags */} {article.tags_burmese && article.tags_burmese.length > 0 && (
{article.tags_burmese.slice(0, 3).map((tag: string, idx: number) => ( #{tag} ))}
)} {/* Meta */}
{article.reading_time} မိနစ် {article.view_count} views
))}
)}
{/* Load More Button */} {articles.length >= 20 && (
)}
) }