From 6b72cfd9a51ad06ef347936ab7917ecd3dedf6bc Mon Sep 17 00:00:00 2001 From: Arifulislam5577 Date: Wed, 23 Oct 2024 12:04:39 +0600 Subject: [PATCH] Added: Blog metadata added. --- app/blog/[slug]/page.tsx | 17 +++++++++++++++++ app/blog/page.tsx | 5 +++++ app/src/utils/keepTw.ts | 1 - utils/getMdxContent.ts | 6 +++++- 4 files changed, 27 insertions(+), 2 deletions(-) delete mode 100644 app/src/utils/keepTw.ts diff --git a/app/blog/[slug]/page.tsx b/app/blog/[slug]/page.tsx index ec753a00..99084bc7 100644 --- a/app/blog/[slug]/page.tsx +++ b/app/blog/[slug]/page.tsx @@ -1,3 +1,4 @@ +import { Metadata } from 'next' import { MDXRemote } from 'next-mdx-remote/rsc' import { Suspense } from 'react' import rehypePrettyCode from 'rehype-pretty-code' @@ -11,6 +12,22 @@ export async function generateStaticParams() { })) } +export async function generateMetadata({ params }: { params: { slug: string } }): Promise { + const posts = getBlogs() + const post = posts.find((post) => post.slug === params.slug) + + if (!post) { + return { + title: 'Keep React - Supercharge Your Web Development', + description: + 'Explore our library of 40+ open-source React UI components and interactive elements, empowering you to create stunning web projects effortlessly.', + } + } + return { + title: post?.title, + } +} + const page = async ({ params }: { params: { slug: string } }) => { const posts = getBlogs() const post = posts.find((post) => post.slug === params.slug) diff --git a/app/blog/page.tsx b/app/blog/page.tsx index e743a69e..7816d5e1 100644 --- a/app/blog/page.tsx +++ b/app/blog/page.tsx @@ -1,6 +1,11 @@ +import { Metadata } from 'next' import { getBlogs } from '~/utils/getMdxContent' import Blog from '../components/Blog' +export const metadata: Metadata = { + title: 'Blog || Keep React', +} + const page = () => { const blogs = getBlogs() return ( diff --git a/app/src/utils/keepTw.ts b/app/src/utils/keepTw.ts deleted file mode 100644 index d1dddcb2..00000000 --- a/app/src/utils/keepTw.ts +++ /dev/null @@ -1 +0,0 @@ -export const keepTw = (value: any) => value diff --git a/utils/getMdxContent.ts b/utils/getMdxContent.ts index 5b1ebb3e..e4abda52 100644 --- a/utils/getMdxContent.ts +++ b/utils/getMdxContent.ts @@ -16,7 +16,11 @@ export const getBlogs = () => { return { slug: fileName.replace(/\.mdx$/, ''), - ...data, + title: data?.title, + tag: data?.tag, + date: data?.date, + version: data?.version, + author: data?.author, content, } })