混合 JSON-LD CollectionPage 和 Schema.org 的微数据 `hasPart` [英] Mixing JSON-LD CollectionPage and Microdata `hasPart` of Schema.org

查看:34
本文介绍了混合 JSON-LD CollectionPage 和 Schema.org 的微数据 `hasPart`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的微数据标记效果很好,Google 的结构化数据测试工具显示一个 CollectionPageWebSite/WebPage 作为子项.

<span itemscope itemtype="https://schema.org/WebSite" itemprop="hasPart"><a href="https://springfield-xxxx.us" itemprop="url">斯普林菲尔德官方网站</a></span><span itemscope itemtype="https://schema.org/WebPage" itemprop="hasPart"><a href="https://facebook.com/group/XXXX" itemprop="url">斯普林菲尔德当地活动</a></span><span itemscope itemtype="https://schema.org/WebPage" itemprop="hasPart"><a href="https://news.us/city/springfield-xxxx" itemprop="url">斯普林菲尔德最新消息</a></span>

但是,当我添加 JSON-LD 时 Google 的结构化数据测试工具显示对象 CollectionPageWebPage/WebSite 分开,就像它们没有连接一样.这是一个带有 JSON-LD 的示例:

<头><脚本类型=应用程序/ld+json">{描述": "...","author": {"@type":"Person", "name": "Homer J. Simpson"},"@type": "收藏页","url": "http://my-springfield.us/sites",出版商":{"@type": "组织","logo": "此处为 ImageObject 类型的对象",名称":荷马·J·辛普森"},图像": "...","headline": "斯普林菲尔德遗址",和...一样": ["..."],"@context": "http://schema.org"}<身体><span itemscope itemtype="https://schema.org/WebSite" itemprop="hasPart"><a href="https://springfield-xxxx.us" itemprop="url">斯普林菲尔德官方网站</a></span><span itemscope itemtype="https://schema.org/WebPage" itemprop="hasPart"><a href="https://facebook.com/group/XXXX" itemprop="url">斯普林菲尔德当地活动</a></span><span itemscope itemtype="https://schema.org/WebPage" itemprop="hasPart"><a href="https://news.us/city/springfield-xxxx" itemprop="url">斯普林菲尔德最新消息</a></span></html>

我尝试将 @id 放入 JSON-LD 并将 itemid 放入 body 中,但无济于事:Google 测试工具显示两个单独的 CollectionPages 或其他类型的两个单独的项目.

我的问题:如何连接 JSON-LD 和微数据,以便 Google 测试工具显示一个 CollectionPageWebPage/WebSite 作为子项/道具?

解决方案

就像他们没有联系

好吧,在您的示例中,它们没有连接.JSON-LD 和 Microdata 无法在语法层面协同工作.

如果要连接定义在不同语法中的实体,唯一的方法是

  • 为这些实体提供 URI(如果它们是相同的,则为相同的 URI),并且
  • 将这些 URI 引用为属性值(如果一个实体是另一个实体的属性值).

赋予实体 URI 以您提到的方式工作:在 @id 中JSON-LD,并在 Microdata 中使用 itemid(在 RDFa Lite 中使用 resource).

消费者(搜索引擎或 Google 的 SDTT 等服务,浏览器插件等本地客户端等)必须支持以下引用(并非全部都支持),如果他们确实支持以下引用,则还必须支持解析附加语法(并非全部都这样做).

但即使您使用此类 URI 引用,它也不会改变您使用的语法的一致性要求.您的 HTML 文档无效,因为您具有不属于 itemscopeitemprop 属性.这是不允许的.因此,如果您想继续使用 Microdata,您也必须在 Microdata 中提供父项(在您的情况下为 CollectionPage).

这将是表达两个 CollectionPage 出现代表相同实体的方式(它们具有相同的 URI = 当前文档的基本 URL):

<div itemscope itemtype="http://schema.org/CollectionPage" itemid=""><span itemprop="hasPart" itemscope itemtype="http://schema.org/WebSite"></span><span itemprop="hasPart" itemscope itemtype="http://schema.org/WebSite"></span><span itemprop="hasPart" itemscope itemtype="http://schema.org/WebPage"></span>

Google 的 SDTT 仍然显示两个 CollectionPage 条目(如果语法混合),但它们(正确地)具有相同的 URI.由 Google 决定如何处理这些信息以用于其各种结构化数据功能.也许它们的所有功能都支持混合语法引用(他们似乎没有记录它);他们的 SDTT 显示事物的方式并不一定反映他们如何对其特征进行解释.

更多示例

The microdata markup below works perfectly, Google's structured data testing tool shows one CollectionPage and WebSite/WebPage as children.

<body itemscope itemtype="https://schema.org/CollectionPage">
  <span itemscope itemtype="https://schema.org/WebSite" itemprop="hasPart">
    <a href="https://springfield-xxxx.us" itemprop="url">Official site of Springfield</a>
  </span>
  <span itemscope itemtype="https://schema.org/WebPage" itemprop="hasPart">
    <a href="https://facebook.com/group/XXXX" itemprop="url">Local events in Springfield</a>
  </span>
  <span itemscope itemtype="https://schema.org/WebPage" itemprop="hasPart">
    <a href="https://news.us/city/springfield-xxxx" itemprop="url">Latest news in Springfield</a>
  </span>
</body>

However when I add JSON-LD Google's structured data testing tool shows objects CollectionPage and WebPage/WebSite separately like if they had no connection. Here is a sample with JSON-LD:

<!DOCTYPE html>
<html>
<head>
  <script type="application/ld+json">
    {
      "description": "...",
      "author": {"@type":"Person", "name": "Homer J. Simpson"},
      "@type": "CollectionPage",
      "url": "http://my-springfield.us/sites",
      "publisher": {
        "@type": "Organization",
        "logo": "Object of type ImageObject here",
        "name": "Homer J. Simpson"
      },
      "image": "...",
      "headline": "Springfield Sites",
      "sameAs": ["..."],
      "@context": "http://schema.org"
    }
  </script>
</head>
<body>
  <span itemscope itemtype="https://schema.org/WebSite" itemprop="hasPart">
    <a href="https://springfield-xxxx.us" itemprop="url">Official site of Springfield</a>
  </span>
  <span itemscope itemtype="https://schema.org/WebPage" itemprop="hasPart">
    <a href="https://facebook.com/group/XXXX" itemprop="url">Local events in Springfield</a>
  </span>
  <span itemscope itemtype="https://schema.org/WebPage" itemprop="hasPart">
    <a href="https://news.us/city/springfield-xxxx" itemprop="url">Latest news in Springfield</a>
  </span>
</body>
</html>

I tried putting @id in JSON-LD and itemid on the body to no avail: Google testing tool shows two separate CollectionPages or two separate items of other types.

My question: how to connect JSON-LD and microdata so that Google testing tool shows one CollectionPage with WebPage/WebSite as children/props?

解决方案

like if they had no connection

Well, they aren’t connected in your example. JSON-LD and Microdata can’t work together on the syntax-level.

If you want to connect entities defined in different syntaxes, the only way is to

  • give these entities URIs (the same URI if they are the same thing), and
  • reference these URIs as property values (if one entity is the value of another entity’s property).

Giving entities URIs works in the way you mentioned: with @id in JSON-LD, and with itemid in Microdata (and with resource in RDFa Lite).

Consumers (services like search engines or Google’s SDTT, local clients like browser add-ons etc.) would have to support following references (not all do), and if they do support following references, they would also have to support parsing the additional syntax (not all do).

But even if you make use of such URI references, it doesn’t change the conformance requirements of the syntaxes you use. Your HTML document is invalid, because you have itemprop attributes that don’t belong to an itemscope. This is not allowed. So if you want to keep using Microdata, you have to provide the parent item in Microdata, too (CollectionPage in your case).

This would be the way to convey that both CollectionPage occurrences represent the same entity (they have the same URI = the base URL of the current document):

<script type="application/ld+json">
  {
    "@context": "http://schema.org",
    "@type": "CollectionPage",
    "@id": ""
  }
</script>

<div itemscope itemtype="http://schema.org/CollectionPage" itemid="">
  <span itemprop="hasPart" itemscope itemtype="http://schema.org/WebSite"></span>
  <span itemprop="hasPart" itemscope itemtype="http://schema.org/WebSite"></span>
  <span itemprop="hasPart" itemscope itemtype="http://schema.org/WebPage"></span>
</div>

Google’s SDTT still displays two CollectionPage entries (if syntaxes are mixed), but they (correctly) have the same URI. It’s up to Google to decide what to do with this information for their various structured data features. Maybe mixed-syntax references are supported for none/some/all of their features (they don’t seem to document it); how their SDTT displays things doesn’t necessarily reflect how they interpret it for their features.

More examples

这篇关于混合 JSON-LD CollectionPage 和 Schema.org 的微数据 `hasPart`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆