Skip to content

Commit

Permalink
set translation to post metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
byandrev committed Aug 23, 2023
1 parent d371e4a commit 40c6217
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/app/[lang]/posts/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -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 };
Expand All @@ -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 (
<Container>
{post && (
{post ? (
<div>
<article>
<header>
Expand All @@ -36,22 +31,25 @@ export default async function PostPage({ params: { slug, lang } }: Props) {
<PostContent content={post.content} />
</article>
</div>
) : (
<div></div>
)}
</Container>
);
}

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,
};
}
}

0 comments on commit 40c6217

Please sign in to comment.