Is there a way to have dynamic metadata in a client page?
Answered
Saltwater Crocodile posted this in #help-forum
Saltwater CrocodileOP
contentlayer requires that page to be a client and I want to have dynamic metadata, here is the metadata I want:
export async function generateMetadata({ params }: any): Promise<Metadata> {
const post = allPosts.find((post) => post.slug == params?.slug)
return {
title: post?.title,
openGraph: {
title: post?.title,
description: post?.description,
url: 'https://yusuf.fyi/posts/' + post?.slug,
locale: 'en-US',
authors: ['Yusuf Bouzekri'],
images: [
{
url: 'https://yusuf.fyi/api/og?title=' + post?.title,
alt: "The article's cover photo",
height: 1200,
width: 630,
}
]
},
twitter: {
card: 'summary_large_image',
title: post?.title,
description: post?.description,
creator: "@spacebuffer",
site: '@spacebuffer',
images: [
{
url: 'https://yusuf.fyi/api/og?title=' + post?.title,
alt: "The article's cover photo",
height: 1200,
width: 630,
}
]
}
}
}10 Replies
@joulev <https://nextjs-discord-common-questions.joulev.dev/how-to-set-metadata-to-page-tsx-rendered-as-client-components>
Saltwater CrocodileOP
thanks that fixed it
I actually had this problem for a few months
and it stopped me from writting on my blog
error - Error: Cannot access .propTypes on the server. You cannot dot into a client module from a server component. You can only pass the imported name through. is the error I got, I didn't get that I had to set the page to a client pagei dont quite get it, is this a new question?
@joulev i dont quite get it, is this a new question?
Saltwater CrocodileOP
no, all is good this can be closed
I am not sure how to close the issue
thanks again
oh i see, glad it helped