web-humas-fe/app/news/detail/[id]/page.tsx

52 lines
1.2 KiB
TypeScript

import HumasLayout from "@/components/layout/humas-layout";
import DetailPage from "@/components/main/detail/new-detail";
import { getArticleById } from "@/services/article";
import { Metadata } from "next";
type Props = {
params: { id: string };
};
export async function generateMetadata({ params }: any): Promise<Metadata> {
// const params = await props.params;
const { id } = await params;
const res = await getArticleById(id?.split("-")[0]);
const article = res?.data?.data;
if (article) {
return {
title: article.title,
description: article.description,
openGraph: {
title: article.title,
description: article.description,
images: [`${article.thumbnailUrl}`],
},
};
} else {
return {
title: "",
description: "",
openGraph: {
title: "",
description: "",
images: [``],
},
};
}
}
export default async function NewsPage({ params }: any) {
// const params = await props.params;
const { id } = await params;
const articleId = id?.split("-")[0];
const res = await getArticleById(articleId);
const article = res?.data?.data;
return (
<HumasLayout>
<DetailPage datas={article} />
</HumasLayout>
);
}