【问题标题】:Mixing JSON-LD and Microdata Schema.org混合 JSON-LD 和微数据 Schema.org
【发布时间】:2016-03-07 13:02:41
【问题描述】:

如果我有以下标记:

<body itemscope="" itemtype="http://schema.org/WebPage">
  <h1 itemprop="name">Lecture 12: Graphs, networks, incidence matrices</h1>
  <p itemprop="description">These video lectures of Professor Gilbert
    Strang teaching 18.06 were  recorded in Fall 1999 and do not
    correspond precisely to the current  edition of the textbook.</p>
  <div itemprop="publisher" itemscope="" itemtype="http://schema.org/CollegeOrUniversity">
    <h4 class="footer">About <span itemprop="name">MIT OpenCourseWare</span></h4>
  </div>
  <a itemprop="license"
    rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/deed.en_US"><img
    src="/images/cc_by-nc-sa.png" alt="Creative Commons logo with terms BY-NC-SA." /></a>
</body>

我想重构 publisher 属性,因为它很复杂,我不想显示它并这样做:

<body itemscope="" itemtype="http://schema.org/WebPage">
  <h1 itemprop="name">Lecture 12: Graphs, networks, incidence matrices</h1>
  <p itemprop="description">These video lectures of Professor Gilbert
    Strang teaching 18.06 were  recorded in Fall 1999 and do not
    correspond precisely to the current  edition of the textbook.</p>
  <script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "CollegeOrUniversity",
        "name": "MIT OpenCourseWare"
    }
</script>
  <a itemprop="license"
    rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/deed.en_US"><img
    src="/images/cc_by-nc-sa.png" alt="Creative Commons logo with terms BY-NC-SA." /></a>
</body>

我怎么说&lt;script&gt; 块与itemprop="publisher" 属性相关?

我猜这两个选项是 i)。将itemprop 属性添加到脚本标签或 ii)。在 JSON-LD 块中添加 @attribute 代替 itemprop

我找不到任何文档。有人知道答案吗?

【问题讨论】:

  • 这个@parent 来自哪里? JSON-LD spec里好像没有提到。
  • @unor 我以@parent 属性为例。我将编辑问题以澄清这一点。很抱歉浪费您的时间在规范中查找。
  • @unor 我认为使用&lt;meta&gt; 是可行的方法。如果没有其他解决方案即将出现,我会接受您的回答。我的问题是我的网站上有很多 Organizations 和 Person(人物),我想优化重用他们的 Schema.org 块。仅供参考,我正在使用 Jekyll 和“数据文件”。我想我可以改用普通的 HTML 块包含。
  • 与此问题相关:“您是否允许在同一页面上使用不同的格式,甚至可以在您的桌面和移动网站之间混合使用它们?谷歌表示这应该不是问题,假设两端的实际输出相同。” seroundtable.com/google-formats-schema-22999.html

标签: html schema.org microdata json-ld


【解决方案1】:

这是不可能的。如果您在script 元素上使用itemprop 属性,则scriptproperty value will be the textContent。这本质上类似于itemprop="{ "@context": "http://schema.org", "@type": "CollegeOrUniversity", "name": "MIT OpenCourseWare" }",因此值是纯文本,而不是 JSON-LD(并且不解释为 JSON-LD)。

如果您不想在您的页面上显示发布商名称,您可以使用 meta 元素:

<div itemprop="publisher" itemscope itemtype="http://schema.org/CollegeOrUniversity">
  <meta itemprop="name" content="MIT OpenCourseWare" />
</div>

也可以为 JSON-LD 节点使用 node identifier (@id) 并在 Microdata 中引用此 URI,但有些消费者可能不支持它(有些可能根本不遵循引用,有些可能只识别什么 Schema. org 期望 publisher 属性:Organization/Person,但不是 URL):

<script type="application/ld+json">
{
    "@context": "http://schema.org",
    "@type": "CollegeOrUniversity",
    "@id": "http://example.com/mit-opencourseware#thing",
    "name": "MIT OpenCourseWare"
}
</script>
<link itemprop="publisher" href="http://example.com/mit-opencourseware#thing" />

【讨论】:

    【解决方案2】:

    在纯 JSON-LD 中,这种关系可以通过嵌套属性来表示,如下所示:

       <body>
          <h1>Lecture 12: Graphs, networks, incidence matrices</h1>
          <p>These video lectures of Professor Gilbert
            Strang teaching 18.06 were  recorded in Fall 1999 and do not
            correspond precisely to the current  edition of the textbook.</p>
          <script type="application/ld+json">
            {
                "@context": "http://schema.org",
                "@type" : "WebPage",
                "name" : "Web page name",
                "description" : "Web page desc",
                "license" : "http://creativecommons.org/licenses/by-nc-sa/3.0/us/deed.en_US",
                "publisher" : {
                    "@context": "http://schema.org",
                    "@type": "CollegeOrUniversity",
                    "name": "MIT OpenCourseWare"
                }
    
            }
        </script>
          <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/deed.en_US"><img
            src="/images/cc_by-nc-sa.png" alt="Creative Commons logo with terms BY-NC-SA." /></a>
        </body>
    

    但是,如果您在 HTML 中也保留 WebPage 作为微数据,那么在 https://developers.google.com/structured-data/testing-tool/ 中进行测试时,您最终会得到 2 个 WebPage 实例 我认为在一页上只保留微数据或 JSON-LD 会更好。

    【讨论】:

      【解决方案3】:

      Lined Data 的全部意义在于,任何人都可以在任何地方说任何话。在这种情况下,您可以在 Microdata 中使用 @itemid 来标识资源 URI,并使用与 JSON-LD 中 @id 的值(显式或隐式)相同的 URI。这当然是结构化数据 Linter 解释它的方式。您需要尝试使用 Google 的结构化数据测试工具,看看他们是如何解释它的。

      如果您想在 Microdata 和 JSON-LD(或 RDFa)中引用相同的资源,这是您拥有的唯一机制。脚本元素上的@itemrel 不执行任何操作。

      【讨论】:

        猜你喜欢
        • 2018-11-13
        • 1970-01-01
        • 1970-01-01
        • 2015-09-10
        • 1970-01-01
        • 1970-01-01
        • 2012-11-08
        • 2017-04-23
        • 2019-06-24
        相关资源
        最近更新 更多