Skip to content

Commit 6b72cfd

Browse files
Added: Blog metadata added.
1 parent 9a85207 commit 6b72cfd

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

app/blog/[slug]/page.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Metadata } from 'next'
12
import { MDXRemote } from 'next-mdx-remote/rsc'
23
import { Suspense } from 'react'
34
import rehypePrettyCode from 'rehype-pretty-code'
@@ -11,6 +12,22 @@ export async function generateStaticParams() {
1112
}))
1213
}
1314

15+
export async function generateMetadata({ params }: { params: { slug: string } }): Promise<Metadata> {
16+
const posts = getBlogs()
17+
const post = posts.find((post) => post.slug === params.slug)
18+
19+
if (!post) {
20+
return {
21+
title: 'Keep React - Supercharge Your Web Development',
22+
description:
23+
'Explore our library of 40+ open-source React UI components and interactive elements, empowering you to create stunning web projects effortlessly.',
24+
}
25+
}
26+
return {
27+
title: post?.title,
28+
}
29+
}
30+
1431
const page = async ({ params }: { params: { slug: string } }) => {
1532
const posts = getBlogs()
1633
const post = posts.find((post) => post.slug === params.slug)

app/blog/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import { Metadata } from 'next'
12
import { getBlogs } from '~/utils/getMdxContent'
23
import Blog from '../components/Blog'
34

5+
export const metadata: Metadata = {
6+
title: 'Blog || Keep React',
7+
}
8+
49
const page = () => {
510
const blogs = getBlogs()
611
return (

app/src/utils/keepTw.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

utils/getMdxContent.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ export const getBlogs = () => {
1616

1717
return {
1818
slug: fileName.replace(/\.mdx$/, ''),
19-
...data,
19+
title: data?.title,
20+
tag: data?.tag,
21+
date: data?.date,
22+
version: data?.version,
23+
author: data?.author,
2024
content,
2125
}
2226
})

0 commit comments

Comments
 (0)