feat: use doc description for og heading

This commit is contained in:
shadcn 2022-11-28 12:14:54 +04:00
parent 4a9b412fd9
commit 0629b9edad
2 changed files with 12 additions and 3 deletions

View file

@ -1,5 +1,14 @@
import { allDocs } from "contentlayer/generated"
import MdxHead from "@/components/docs/mdx-head"
export default function Head({ params }) {
return <MdxHead params={params} og={{ type: "Documentation" }} />
const slug = params?.slug?.join("/") || ""
const doc = allDocs.find((doc) => doc.slugAsParams === slug)
return (
<MdxHead
params={params}
og={{ heading: doc.description, type: "Documentation" }}
/>
)
}

View file

@ -22,8 +22,8 @@ export default function MdxHead({ params, og }: MdxHeadProps) {
let ogUrl = new URL(`${url}/og.jpg`)
if (og.type) {
ogUrl = new URL(url)
ogUrl.searchParams.set("heading", mdxDoc.title)
ogUrl = new URL(`${url}/api/og`)
ogUrl.searchParams.set("heading", og.heading || mdxDoc.title)
ogUrl.searchParams.set("type", og.type)
}