import { sql } from '@/lib/db'
import { notFound } from 'next/navigation'
export const dynamic = 'force-dynamic'
import Link from 'next/link'
import Image from 'next/image'
async function getArticle(slug: string) {
try {
const { rows } = await sql`
SELECT
a.*,
c.name as category_name,
c.name_burmese as category_name_burmese,
c.slug as category_slug
FROM articles a
JOIN categories c ON a.category_id = c.id
WHERE a.slug = ${slug} AND a.status = 'published'
`
if (rows.length === 0) return null
// Increment view count
await sql`SELECT increment_view_count(${slug})`
return rows[0]
} catch (error) {
console.error('Error fetching article:', error)
return null
}
}
async function getRelatedArticles(articleId: number) {
try {
const { rows } = await sql`SELECT * FROM get_related_articles(${articleId}, 5)`
return rows
} catch (error) {
return []
}
}
export default async function ArticlePage({ params }: { params: { slug: string } }) {
const article = await getArticle(params.slug)
if (!article) {
notFound()
}
const relatedArticles = await getRelatedArticles(article.id)
const publishedDate = new Date(article.published_at).toLocaleDateString('my-MM', {
year: 'numeric',
month: 'long',
day: 'numeric'
})
return (
{/* Breadcrumb */}
ပင်မစာမျက်နှာ
/
{article.category_name_burmese}
/
{article.title_burmese}
{/* Article Header */}
{/* Category Badge */}
{article.category_name_burmese}
{/* Featured Image */}
{article.featured_image && (
)}
{/* Article Content */}
{/* Title */}
{article.title_burmese}
{/* Meta Info */}
{publishedDate}
•
{article.reading_time} မိနစ်
•
{article.view_count} ကြည့်ရှုမှု
{/* Article Body */}
{/* 🔥 Additional Images Gallery */}
{article.images && article.images.length > 1 && (
ဓာတ်ပုံများ
{article.images.slice(1).map((img: string, idx: number) => (
))}
)}
{/* 🔥 Videos */}
{article.videos && article.videos.length > 0 && (
ဗီဒီယိုများ
{article.videos.map((video: string, idx: number) => (
{renderVideo(video)}
))}
)}
{/* ⭐ SOURCE ATTRIBUTION - THIS IS THE KEY PART! */}
{article.source_articles && article.source_articles.length > 0 && (
မူရင်းသတင်းရင်းမြစ်များ
ဤဆောင်းပါးကို အောက်ပါမူရင်းသတင်းများမှ စုစည်း၍ မြန်မာဘာသာသို့ ပြန်ဆိုထားခြင်း ဖြစ်ပါသည်။ အားလုံးသော အကြွေးအရ မူရင်းစာရေးသူများနှင့် ထုတ်ပြန်သူများကို သက်ဆိုင်ပါသည်။
{article.source_articles.map((source: any, index: number) => (
{index + 1}
{source.title}
{source.author && source.author !== 'Unknown' && (
စာရေးသူ: {source.author}
)}
{source.url}
))}
မှတ်ချက်: ဤဆောင်းပါးသည် သတင်းမျာ လုံးစုစည်းကာ ပြန်ဆိုထားခြင်း ဖြစ်ပါသည်။ အသေးစိတ် အချက်အလက်များနှင့် မူရင်းအကြောင်းအရာများအတွက် အထက်ပါမူရင်းသတင်းရင်းမြစ်များကို ကြည့်ရှုပါ။
)}
{/* Disclaimer */}
ပြန်ဆိုသူမှတ်ချက်: ဤဆောင်းပါးကို AI နည်းပညာဖြင့် အင်္ဂလိပ်ဘာသာမှ မြန်မာဘာသာသို့ ပြန်ဆိုထားပါသည်။ နည်းပညာဝေါဟာရများကို တတ်နိုင်သမျှ အင်္ဂလိပ်ဘာသာဖြင့် ထားရှိထားပါသည်။
{/* Related Articles */}
{relatedArticles.length > 0 && (
ဆက်စပ်ဆောင်းပါးများ
{relatedArticles.map((related: any) => (
{related.featured_image && (
)}
{related.title_burmese}
{related.excerpt_burmese}
))}
)}
)
}
function formatContent(content: string): string {
// Convert markdown-like formatting to HTML
// This is a simple implementation - you might want to use a proper markdown parser
let formatted = content
.replace(/\n\n/g, '')
.replace(/## (.*?)\n/g, '
$1 ')
.replace(/### (.*?)\n/g, '$1 ')
.replace(/\*\*(.*?)\*\*/g, '$1 ')
.replace(/\*(.*?)\*/g, '$1 ')
return `${formatted}
`
}
function renderVideo(videoUrl: string) {
// Extract YouTube video ID
let videoId = null
// Handle different YouTube URL formats
if (videoUrl.includes('youtube.com/watch')) {
const match = videoUrl.match(/v=([^&]+)/)
videoId = match ? match[1] : null
} else if (videoUrl.includes('youtu.be/')) {
const match = videoUrl.match(/youtu\.be\/([^?]+)/)
videoId = match ? match[1] : null
} else if (videoUrl.includes('youtube.com/embed/')) {
const match = videoUrl.match(/embed\/([^?]+)/)
videoId = match ? match[1] : null
}
if (videoId) {
return (
VIDEO
)
}
// For other video formats, try generic iframe embed
return (
)
}
export async function generateMetadata({ params }: { params: { slug: string } }) {
const article = await getArticle(params.slug)
if (!article) {
return {
title: 'Article Not Found',
}
}
return {
title: `${article.title_burmese} - Burmddit`,
description: article.excerpt_burmese,
openGraph: {
title: article.title_burmese,
description: article.excerpt_burmese,
images: article.featured_image ? [article.featured_image] : [],
},
}
}