混合 JSON-LD 和 Microdata Schema.org
Mixing JSON-LD and Microdata Schema.org
如果我有以下标记:
<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>
而且我想重构发布者 属性 因为它很复杂而且我不想一定要显示它并执行此操作:
<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>
如何说 <script>
块与 itemprop="publisher"
属性 相关?
我猜这两个选项是i)。将 itemprop
属性添加到脚本标签或 ii)。添加 @attribute
代替 itemprop
到 JSON-LD 块。
我找不到任何一个的文档。有人知道答案吗?
在纯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>
但是,如果您将 WebPage 也作为微数据保存在 HTML 中,那么在 https://developers.google.com/structured-data/testing-tool/ 中进行测试时,您最终会得到 2 个 WebPage 实例
我认为在一页上只使用微数据或 JSON-LD 会更好。
这是不可能的。如果在 script
元素上使用 itemprop
属性,则 script
的 。这本质上类似于 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>
也可以使用 node identifier (@id
) for the JSON-LD node and reference this URI in Microdata, but some consumers might not support it (some might not follow references at all, some might only recognize what Schema.org expects for the 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" />
Lined Data 的全部意义在于任何人都可以在任何地方说任何话。在这种情况下,您可以在微数据中使用 @itemid 来标识资源 URI,并使用与 JSON-LD 中 @id 的值(显式或隐式)相同的 URI。这当然是 Steuctured Data Linter 解释它的方式。您需要尝试使用 Google 的结构化数据测试工具,看看他们如何解释它。
如果您想在 Microdata 和 JSON-LD(或 RDFa)中引用相同的资源,这是您拥有的唯一机制。脚本元素上的@itemrel 不执行任何操作。
如果我有以下标记:
<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>
而且我想重构发布者 属性 因为它很复杂而且我不想一定要显示它并执行此操作:
<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>
如何说 <script>
块与 itemprop="publisher"
属性 相关?
我猜这两个选项是i)。将 itemprop
属性添加到脚本标签或 ii)。添加 @attribute
代替 itemprop
到 JSON-LD 块。
我找不到任何一个的文档。有人知道答案吗?
在纯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>
但是,如果您将 WebPage 也作为微数据保存在 HTML 中,那么在 https://developers.google.com/structured-data/testing-tool/ 中进行测试时,您最终会得到 2 个 WebPage 实例 我认为在一页上只使用微数据或 JSON-LD 会更好。
这是不可能的。如果在 script
元素上使用 itemprop
属性,则 script
的 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>
也可以使用 node identifier (@id
) for the JSON-LD node and reference this URI in Microdata, but some consumers might not support it (some might not follow references at all, some might only recognize what Schema.org expects for the 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" />
Lined Data 的全部意义在于任何人都可以在任何地方说任何话。在这种情况下,您可以在微数据中使用 @itemid 来标识资源 URI,并使用与 JSON-LD 中 @id 的值(显式或隐式)相同的 URI。这当然是 Steuctured Data Linter 解释它的方式。您需要尝试使用 Google 的结构化数据测试工具,看看他们如何解释它。
如果您想在 Microdata 和 JSON-LD(或 RDFa)中引用相同的资源,这是您拥有的唯一机制。脚本元素上的@itemrel 不执行任何操作。