import { notFound } from "next/navigation"; import Image from "next/image"; import newsApi from "@/shared/services/news"; import { News } from "@/shared/types/news"; import { getFileUrl } from "@/shared/utils/file"; import type { Metadata } from "next"; import NewsContent from "./news-content"; export async function generateMetadata({ params, }: { params: Promise<{ id: string }>; }): Promise { const { id } = await params; try { const newsItem = await newsApi.getNewsById(id, { skipAuth: true }); if (!newsItem || !newsItem.is_active) return {}; const base = process.env.NEXT_PUBLIC_SITE_URL || "https://example.com"; const og = newsItem.thumbnail ? getFileUrl(newsItem.thumbnail) : "/og-image.png"; return { title: newsItem.name, description: newsItem.description?.replace(/<[^>]*>/g, " ").slice(0, 160), alternates: { canonical: `/news/${id}` }, openGraph: { type: "article", url: `${base}/news/${id}`, title: newsItem.name, description: newsItem.description ?.replace(/<[^>]*>/g, " ") .slice(0, 200), images: [og], }, twitter: { card: "summary_large_image", title: newsItem.name, description: newsItem.description ?.replace(/<[^>]*>/g, " ") .slice(0, 200), images: [og], }, }; } catch { return {}; } } // eslint-disable-next-line @typescript-eslint/no-explicit-any export default async function NewsPage({ params }: { params: any }) { let newsItem: News | null = null; try { newsItem = await newsApi.getNewsById(params.id); } catch (error) { console.error("Gagal mengambil data berita:", error); } if (!newsItem || !newsItem.is_active) { notFound(); } return (
{/* Judul Halaman */}
Berita dan Pengumuman
{/* Judul Berita */}

{newsItem.name}

{/* Gambar Thumbnail */} {newsItem.thumbnail && (
{newsItem.name}
)} {/* Konten */}
); }