diff --git a/.gitignore b/.gitignore index eee2a30..805424b 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ coverage/ # Misc *.tar.gz *.zip +.playwright-mcp/ diff --git a/frontend/app/article/[slug]/page.tsx b/frontend/app/article/[slug]/page.tsx index cac87cc..d4634f5 100644 --- a/frontend/app/article/[slug]/page.tsx +++ b/frontend/app/article/[slug]/page.tsx @@ -3,11 +3,12 @@ export const dynamic = "force-dynamic" import { notFound } from 'next/navigation' import Link from 'next/link' import Image from 'next/image' +import ShareButtons from '@/components/ShareButtons' async function getArticleWithTags(slug: string) { try { const { rows } = await sql` - SELECT + SELECT a.*, c.name as category_name, c.name_burmese as category_name_burmese, @@ -27,12 +28,9 @@ async function getArticleWithTags(slug: string) { WHERE a.slug = ${slug} AND a.status = 'published' GROUP BY a.id, c.id ` - if (rows.length === 0) return null - - // Increment view count + // Increment view count only here (not in generateMetadata) await sql`SELECT increment_view_count(${slug})` - return rows[0] } catch (error) { console.error('Error fetching article:', error) @@ -40,34 +38,46 @@ async function getArticleWithTags(slug: string) { } } +// Separate metadata fetch — no view count increment +async function getArticleMeta(slug: string) { + try { + const { rows } = await sql` + SELECT title_burmese, excerpt_burmese, featured_image + FROM articles + WHERE slug = ${slug} AND status = 'published' + LIMIT 1 + ` + return rows[0] || null + } catch { + return null + } +} + async function getRelatedArticles(articleId: number) { try { const { rows } = await sql`SELECT * FROM get_related_articles(${articleId}, 6)` return rows - } catch (error) { + } catch { return [] } } -export default async function ImprovedArticlePage({ params }: { params: { slug: string } }) { +export default async function ArticlePage({ params }: { params: { slug: string } }) { const article = await getArticleWithTags(params.slug) - - if (!article) { - notFound() - } - + 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' + day: 'numeric', }) return (