下面是我对新闻报道标记的最小示例,它尽可能地验证了我的理解。
[当我将其放入Google的test tool for structured data时,我遇到一个模棱两可的问题...它输出发现了两个项目,其中一个是NewsArticle
;另一个是Orginazation
,我将其称为publisher
中的NewsArticle
。在Organization
下显示它已成功读取name
和logo
。那么,在NewsArticle
下,publisher
的logo
和name
为何都出错了呢?
((我想将其保留为application/ld+json
格式,因为我不打算在屏幕上为用户输出组织,所以没有HTML是很好的选择。]
<div itemscope itemtype="http://schema.org/NewsArticle">
<h1 itemprop="headline">
Hello world
</h1>
<time datetime="2020-05-16T20:50:00+00:00" itemprop="datePublished"></time>
<time datetime="2020-05-16T20:50:00+00:00" itemprop="dateModified"></time>
<img itemprop="image" src="image.jpg">
<div itemprop="articleBody">
<p>hello world</p>
</div>
<footer>
<div itemprop="author" itemscope itemtype="https://schema.org/Person">
Written by
<span itemprop="name">
John Doe
</span>
</div>
<meta itemprop="mainEntityOfPage" content="https://example.org">
<div class="publisher">
<script type="application/ld+json" itemprop="publisher" itemscope itemtype="https://schema.org/Organization">
{
"@context": "http://schema.org/",
"@type": "Organization",
"name": "My organization",
"url": "http://www.example.com/",
"logo": "http://www.example.com/logo.png"
}
</script>
</div>
</footer>
</div>
尝试将微数据与json-ld结合的有趣想法。你从哪里得到那个的?
Google不支持两种语法的混合使用。他们的工具没有做到这一点,以及人们进行的几项测试(包括我自己),证实了这一点。
如果Google确实支持交叉语法合并,则可以通过使用每个实体中的通用ID来实现。例如
<meta itemprop="publisher" itemscope itemtype="https://schema.org/Organization" itemid="#Orgnaization"/>
<script type="application/ld+json">
{
"@context": "http://schema.org/",
"@type": "Organization",
"@id": "#Organization",
"name": "My organization",
"url": "http://www.example.com/",
"logo": "http://www.example.com/logo.png"
}
</script>