Next.js Discord

Discord Forum

How do you insert OpenGraph data from JSON to a SSR page?

Unanswered
Reddish carpenter ant posted this in #help-forum
Open in Discord
Reddish carpenter antOP
Hi there! I have a JSON file with Schema Data and OpenGraph data.

The Schema Data is rather easy, if I'm doing it correctly:
<script
        type="application/ld+json"
        dangerouslySetInnerHTML={{
          __html: JSON.stringify(res.SchemaData)
        }}
      />


But how do you go about OpenGraph?

Something like this?

async function BlogView ({ params: { slug } }: { params: { slug: string } }) {
  const res = await getArticleBySlug(slug)
  const data = res.NewsArticle
  console.log(res)

  const openGraphMetaTags = Object.entries(res.OpenGraph).map(([property, content]) => (
    <meta key={property} property={property} content={content} />
  ))

  return (
    <>
      <Head>
        <title>Title</title>
        {openGraphMetaTags}
      </Head>


Or am I doing this totally wrong?

0 Replies