LoginSignup
1
1

More than 5 years have passed since last update.

JSON-LDでMicrodataのitemrefみたいなことをする方法

Last updated at Posted at 2016-07-07

Microdataの場合、idとitemrefによって重複した情報を使いまわす仕組みがある。

<div id="meta-author" itemtype="http://schema.org/Person" itemprop="author" itemscope>
  <h2 itemprop="name">Life is good</h2>
</div>

<!-- 省略 -->

<article itemtype="http://schema.org/Article" itemscope itemref="meta-author">
  <h2 itemprop="headline">Hoge hoge</h2>
</article>

<article itemtype="http://schema.org/Article" itemscope itemref="meta-author">
  <h2 itemprop="headline">Fuga fuga</h2>
</article>

同じようなことをJSON-LDで実現するには、@idを使う。


<!-- Person -->
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Person",
  "@id": "http://liginc.co.jp/#author",
  "name": "Life is good",
  //省略
}
</script>

<!-- Artice -->
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Article",
  "headline": "Hoge hoge",
  "author": {"@id": "http://liginc.co.jp/#author"},
  // 省略
}
</script>

<!-- Artice -->
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Article",
  "headline": "Fuga fuga",
  "author": {"@id": "http://liginc.co.jp/#author"},
  //省略
}
</script>

参考

構造化データにおいて、値の流用(引用?継承?冗長性の抑制?変数化?エイリアス化?)を行いたい - Google プロダクト フォーラム

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1