Next.js Discord

Discord Forum

Connecting jsonld data across different pages into a single script tag - how would I do it

Unanswered
Broad-snouted Caiman posted this in #help-forum
Open in Discord
Broad-snouted CaimanOP
Hello guys, I have the following case:
I am using nextjs 13 and wanna implement jsonld data on different pages and in layouts. They need to be defined there because they rely on data from these pages like locale string or translations. Now I don't wanna render separate tags for each page but want to put them all into a single script tag into the '@graph' array.

I wanna make this on the server but find a good solution which works.
Anyone has some ideas on how to accomplish this?

I wanna have this renderd at the root and each pages adds and removes their schemas:
{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@type": "WebPage",
      "@id": "https://www.nomadrentals.com/en/#webpage",
      "url": "https://www.nomadrentals.com/en/",
      "name": "Nomad Rentals – Camper & Van Hire Across Europe",
      "inLanguage": "en",
      "isPartOf": {
        "@id": "https://www.nomadrentals.com/en/#website"
      },
      "about": {
        "@id": "https://www.nomadrentals.com/en/#organization"
      }
    },
    {
      "@type": "RentalCompany",
      "@id": "https://www.nomadrentals.com/en/#organization",
      "name": "Nomad Rentals",
      "alternateName": "Nomad Camper Hire",
      "url": "https://www.nomadrentals.com/en/",
      "logo": {
        "@type": "ImageObject",
        "url": "https://www.nomadrentals.com/logo.png"
      },
      "address": {
        "@type": "PostalAddress",
        "streetAddress": "123 Vanlife Blvd",
        "addressLocality": "Berlin",
        "addressRegion": "BE",
        "postalCode": "10115",
        "addressCountry": "DE"
      },
      "contactPoint": {
        "@type": "ContactPoint",
        "telephone": "+49-30-12345678",
        "contactType": "Customer Service",
        "availableLanguage": ["English", "German"]
      },
      "sameAs": [
        "https://www.facebook.com/nomadrentals",
        "https://www.instagram.com/nomadrentals"
      ]
    }
  ]
}

0 Replies