This way to a passing Rich Results logo test#429
This way to a passing Rich Results logo test#429benjithaimmortal wants to merge 6 commits intojekyll:masterfrom
Conversation
|
If I read this correctly, this seems to be solving a different problem than #428, although there seems to be some overlap and both PRs modify the @benjithaimmortal could you have a quick look at #428 and confirm whether these are two distinct problems? Also, I've tried to do some quick googling on the |
|
@DarkWiiPlayer you're right! We're approaching the same point in the code but doing very different things. I think my results should precede yours [in the code logic, that is], so you can modify things after the correct formatting to the JSON-LD has been applied.
|
@benjithaimmortal Yes, absolutely. However, I'm wondering how that would work with the way my PR currently works where you build a new tree of json data that gets merged into the autogenerated one because now that includes an array, so one has to throw in a numeric index. For example, if you have a I could add a bunch more logic to filter subtrees by their |
|
@DarkWiiPlayer yeppers. I encountered the same when I was building mine. IMO the need is a simple hash from the yaml settings, and it's overcomplicated by the Ruby magic inside of a new Jekyll instance. Perhaps it could be extracted entirely? I'd love to see something that simply builds the JSON out of |
|
If you're worried about the array itself, perhaps we could make a hash with |
ashmaroli
left a comment
There was a problem hiding this comment.
Accessing values of json_data[@graph] with index numbers (since the object is an Array) seems less intuitive to me as against accessing the values with explicit keys.
Nevertheless, this proposal needs some changes.
| # assign publisher and remove it from the array | ||
| # (because I don't know the meta-programming involved in instantiating it) | ||
| publisher = graph["publisher"] || nil | ||
| graph.delete("publisher") |
There was a problem hiding this comment.
You could merge these two lines into one:
publisher = graph.delete("publisher")There was a problem hiding this comment.
@ashmaroli I think I don't know enough about Ruby for this one. Sorry!
publisher should be set to the inner hash graph['publisher'], and not the full graph hash. Does the refactor do that?
|
Excellent! I'll get to it and modify this ASAP. Thank you all for your comments and help. |
Yep, let's remove these comments! Co-authored-by: Ashwin Maroli <ashmaroli@users.noreply.github.com>
Yep, let's remove these comments! Co-authored-by: Ashwin Maroli <ashmaroli@users.noreply.github.com>
Yep, let's remove these comments! Co-authored-by: Ashwin Maroli <ashmaroli@users.noreply.github.com>
A forward
@ashmaroli Thank you for your patience as I got enough Ruby under my belt to even get this far. I started using
pryto debug the code in-stream, and it allowed me to even test the output as it was rendered inrspec. This is now passing the test on Google, and passingrspecandrubocop. I don't think my code is great, but it was an attempt. My first! Let's change any/all of it in the hopes that the overall contribution helps this cool open source project.--Benji
TL;DR
"@type" => "Organization""@type" => "Organization"to always be separate from"@type" => "WebPage""publisher"We're trying to get a set
logoto pass a Rich Results test, and there are a few problems.Google may have changed this, but at the moment it isn't reading things inside of the "publisher" key. As I mentioned in my open issue we need to find a way to modify the hash to remove it from
"publisher"(which isn't a type property on schema.org anyway).My proposal: let's take a look at Yoast, because they do this a lot
Yoast likes to make tons of different
@typeattributes, and house them as an array of objects inside of@graph. That's what I'm finding on schema.org, too. So now we want things to look like this:{ "@context": "https://schema.org", "@graph": [ { "@type": "Organization", }, { "@type": "WebSite", }, { "@type": "ImageObject", }, { "@type": "WebPage", }, ] }I'd rather manipulate the hash than metaprogram
Results of the change
Original Output:
{ "@type": "WebPage", "publisher": { "@type": "Organization", "logo": { "@type": "ImageObject", "url": "http://example.invalid/logo.png" } }, "url": "http://example.invalid/page.html", "@context": "https://schema.org" }New Output (confirmed on Rich Results Test, when you change the canonical url to a valid one):
{ "@context": "https://schema.org", "@graph": [ { "@type": "WebPage", "url": "http://example.invalid/page.html", "@context": "https://schema.org" }, { "@type": "Organization", "url": "http://example.invalid/page.html", "logo": { "@type": "ImageObject", "url": "http://example.invalid/logo.png" } } ] }