From 40c62178ab08d003d23a64df2f34ff2403bc3c5c Mon Sep 17 00:00:00 2001 From: Andres Parra Date: Tue, 22 Aug 2023 23:06:12 -0500 Subject: [PATCH] set translation to post metadata --- src/app/[lang]/posts/[slug]/page.tsx | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/app/[lang]/posts/[slug]/page.tsx b/src/app/[lang]/posts/[slug]/page.tsx index 4409e54..060f29f 100644 --- a/src/app/[lang]/posts/[slug]/page.tsx +++ b/src/app/[lang]/posts/[slug]/page.tsx @@ -1,9 +1,8 @@ -import { redirect } from "next/navigation"; - +import { useTranslation } from "@/app/i18n"; import Container from "@/components/Container"; +import PostContent from "@/components/PostContent"; import { Post } from "@/interfaces/Post"; import getPost from "./getPostService"; -import PostContent from "@/components/PostContent"; type Props = { params: { slug: string; lang: string }; @@ -12,13 +11,9 @@ type Props = { export default async function PostPage({ params: { slug, lang } }: Props) { const post: Post | null = await getPost(slug, lang); - if (!post) { - redirect("/not-found"); - } - return ( - {post && ( + {post ? (
@@ -36,6 +31,8 @@ export default async function PostPage({ params: { slug, lang } }: Props) {
+ ) : ( +
)}
); @@ -43,15 +40,16 @@ export default async function PostPage({ params: { slug, lang } }: Props) { export async function generateMetadata({ params: { slug, lang } }: Props) { const post: Post | null = await getPost(slug, lang); + const { t } = await useTranslation(lang); if (!post) { return { - title: "404 - Not found", + title: `404 | ${t("not_found")} - @byandrev`, }; } return { - title: post.title, + title: post.title + " - @byandrev", description: post.excerpt, }; -} \ No newline at end of file +}