I'm replacing the microdata (itemscope
et al) on our sites with JSON-LD. Do I need to declare the WebSite
on every page, or can I place it once on the home page?
If the latter, will processors (by which I mean Google) tie each page to it automatically via the domain name, or is there some way to link to it? Given that "Linked Data" is right there in the name, I've found no examples that make use of it. They all replicate or embed the data directly in the thing that's linking.
For example, I want to link to our YouTube videos that we embed in articles, but Google doesn't understand a URL for the video
property. If I expand it into a VideoObject
, Google complains that I don't know the width, height, duration, etc. All that data is on youtube.com
at the URL I'm specifying. Why can't it pull the video information itself?
Do I need to declare the
WebSite
on every page, or can I place it once on the home page?
From the perspectives of Schema.org and Linked Data, it’s perfectly fine (and I would say it’s even the best practice) to provide an item only once, and reference it via its URI whenever it’s needed.
In JSON-LD, this can be done with @id
. For example:
<!-- on the homepage -->
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"@id": "http://example.com/#site",
"hasPart": {
"@type": "WebPage",
"@id": "http://example.com/"
}
}
</script>
<!-- on another page -->
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebPage",
"@id": "http://example.com/foobar",
"isPartOf": {"@id": "http://example.com/#site"}
}
</script>
Whether Google actually follows these references is not clear (as far as I know, it’s undocumented)¹. It’s clear that their testing tool doesn’t show the data from referenced URIs, but that doesn’t have to mean much. At least their testing tool displays the URI (as "ID") in case one is provided.
If you want to provide a URL value for the video
property, note that URL
is not one of its expected values. While Schema.org still allows this (any property can have a text or URL value), it’s likely that some consumers will handle only expected values. It’s also perfectly fine to provide a VideoObject
value if you only provide a url
property. The fact that Google’s testing tool gives errors doesn’t mean that something’s wrong; it just means that Google won’t consider this video for their video-related rich results.
¹ But for the few rich result features Google offers, authors would typically not need to reference something from another page anyway, I guess. Referencing of URIs is typically done for other Semantic Web and Linked Data cases.
来源:https://stackoverflow.com/questions/41066711/duplicate-or-link-to-website-json-ld