Skip to content

Commit e353171

Browse files
committed
feat(blog): add optional keywords field to blog post schema and enhance metadata generation
1 parent 2cdc5fe commit e353171

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

source.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const blogPosts = defineCollections({
2626
schema: frontmatterSchema.extend({
2727
author: z.string(),
2828
category: z.enum(["devlog", "updates", "other"]),
29+
keywords: z.string().array().optional(),
2930
}),
3031
})
3132

src/app/(home)/blog/[slug]/page.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,24 @@ import { lastEdit } from "@/lib/api"
22
import { blog } from "@/lib/source"
33
import { getMDXComponents } from "@/mdx-components"
44
import { PathUtils } from "fumadocs-core/source"
5+
import type { Metadata, ResolvingMetadata } from "next"
56
import Link from "next/link"
67
import { notFound } from "next/navigation"
78

9+
export async function generateMetadata(
10+
{ params }: PageProps<"/blog/[slug]">,
11+
parent: ResolvingMetadata,
12+
): Promise<Metadata> {
13+
const { slug } = await params
14+
const page = blog.getPage([slug])
15+
16+
return {
17+
title: page?.data.title,
18+
description: page?.data.description,
19+
keywords: page?.data.keywords,
20+
}
21+
}
22+
823
export default async function Page(props: PageProps<"/blog/[slug]">) {
924
const params = await props.params
1025
const page = blog.getPage([params.slug])

src/lib/rss.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export async function getRSS() {
2626
date: await lastEdit(page),
2727
author: [
2828
{
29-
name: page.data.author
29+
name: page.data.author,
3030
},
3131
],
3232
})

0 commit comments

Comments
 (0)