From 0629b9edada7aa46c26b6493dd5b4a6969989eb9 Mon Sep 17 00:00:00 2001 From: shadcn Date: Mon, 28 Nov 2022 12:14:54 +0400 Subject: [PATCH] feat: use doc description for og heading --- app/(docs)/docs/[[...slug]]/head.tsx | 11 ++++++++++- components/docs/mdx-head.tsx | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/(docs)/docs/[[...slug]]/head.tsx b/app/(docs)/docs/[[...slug]]/head.tsx index c54e4f5..f566c33 100644 --- a/app/(docs)/docs/[[...slug]]/head.tsx +++ b/app/(docs)/docs/[[...slug]]/head.tsx @@ -1,5 +1,14 @@ +import { allDocs } from "contentlayer/generated" + import MdxHead from "@/components/docs/mdx-head" export default function Head({ params }) { - return + const slug = params?.slug?.join("/") || "" + const doc = allDocs.find((doc) => doc.slugAsParams === slug) + return ( + + ) } diff --git a/components/docs/mdx-head.tsx b/components/docs/mdx-head.tsx index 8d12bbd..6801b24 100644 --- a/components/docs/mdx-head.tsx +++ b/components/docs/mdx-head.tsx @@ -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) }