Giter Site home page Giter Site logo

Comments (7)

jdrucey avatar jdrucey commented on June 3, 2024

Just started using this as it seems perfect for what we need, so thanks for the great work.

Flat schemas worked perfectly until I tried running on a site that uses @graph to include multiple schemas, where I get no results back.

Any input on this one? @graph seems to be commonly used by Yoast, a popular WordPress plugin, so these types of implementation seem ripe across the internet. This structure also validates fine in validator.schema.org so handling it in this library seems sensible.

from schema.

jdrucey avatar jdrucey commented on June 3, 2024

This is seemingly the same issue as @juanparati issue, in that the context is set at the top, so inside the @graph in my example, types are not prefixed with https://schema.org.

What was your solution in the end @juanparati?

from schema.

goellner avatar goellner commented on June 3, 2024

Also running into this issue, would be great if anyone could share a solution to this

from schema.

goellner avatar goellner commented on June 3, 2024

brick/schema can extract the data, if the context is set on a graph item:

{
   "@context":"https://schema.org",
   "@graph":[
      {
         "@context": "http://schema.org/"
         "@type":"Organization",
         "@id":"https://example.org/#organization",
         "name":"Acme LTD",
         "url":"https://example.org/",
         "sameAs":[
            
         ]
      }
   ]
}

older versions of the wp plugin yoast don't include this context, newer versions do. since we can't update external websites yoast version, it would be awesome, if brick could add support for this.

@BenMorel would you be able to help if we sponsor the project with a one time sponsorship?

from schema.

jhard avatar jhard commented on June 3, 2024

Seems like the easiest way is to add the @context in the @graph array so you end up with what @goellner mentioned.

Quickfix for me was to change brick/structured-data/src/Reader/JsonLdReader.php in the function readJson and change $data = $data->{'@graph'}; to

                $context = $data->{'@context'} ?? null;
                $data = $data->{'@graph'};
                if($context) {
                   foreach($data as $i => $item) {
                      if($context && !($item->{'@context'} ?? null)) {
                         $data[$i]->{'@context'} = $context;
                      }
                   }
                }

It will preserve existing @context attributes on the items and otherwise add the parent one if one exists.
I'm a total noob when it comes to schema.org so I don't know if they could potentially have nested @graph that would require additional treatment, but that shouldn't be too hard to add.

@BenMorel If you'd accept a pull request for brick/structured-data I could create on over there.

from schema.

goaround avatar goaround commented on June 3, 2024

I run into the same issue with the Rank Math WordPress Plugin. There is also the @Schema on the @graph items missing
@jhard could you create a PR?

from schema.

jhard avatar jhard commented on June 3, 2024

I run into the same issue with the Rank Math WordPress Plugin. There is also the @Schema on the @graph items missing @jhard could you create a PR?

Sorry, I've long moved on from this and it seems so has everyone else unfortunately. Feel free to submit the PR with the code yourself though :)

from schema.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.