混合 JSON-LD CollectionPage 和 Schema.org 的微数据 `hasPart`

2023-12-03

下面的微数据标记工作得很好,Google 的结构化数据测试工具显示一个CollectionPage and WebSite/WebPage作为孩子。

<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>

但是当我添加 JSON-LD 时Google 的结构化数据测试工具显示对象CollectionPage and WebPage/WebSite分开就像他们没有联系一样。以下是 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>

我尝试把@id在 JSON-LD 中和itemid on the body无济于事:谷歌测试工具显示两个单独的CollectionPages或其他类型的两个单独的项目。

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


就像他们没有联系一样

嗯,他们aren’t在你的例子中连接。 JSON-LD 和 Microdata 无法在语法级别上协同工作。

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

  • 给这些实体 URI(如果它们是相同的东西,则为相同的 URI),并且
  • 将这些 URI 作为属性值引用(如果一个实体是另一实体的属性值)。

提供实体 URI按照你提到的方式工作:@id在 JSON-LD 中,并且itemid在微观数据中(并且与resource在 RDFa Lite 中)。

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

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

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

<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 的 SDTT 仍然显示两个CollectionPage条目(如果语法混合),但它们(正确地)具有相同的 URI。由谷歌决定如何处理这些信息以实现其各种结构化数据功能。也许它们的所有功能都支持混合语法引用(他们似乎没有记录下来);他们的 SDTT 如何显示事物并不一定反映他们如何解释其特征。

更多示例

  • same ProductJSON-LD + 微数据
  • WebPage(JSON-LD) +BreadcrumbList(微观数据)
  • Organization(JSON-LD) +WebPage(微观数据)
  • CollegeOrUniversity(JSON-LD) +WebPage(微观数据)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

混合 JSON-LD CollectionPage 和 Schema.org 的微数据 `hasPart` 的相关文章