AMP JSON-LD动态内容

时间:2017-08-11 12:32:55

标签: html json json-ld accelerated-mobile-page

我想保持JSON-LD脚本的内容动态。但是,AMP不允许我使用Javascript,脚本应该在头部 保持身体内容的动态不是问题,因为amp-list。

<head>
    <script type="application/ld+json">
    { 
    "@context": "http://schema.org",
    "@type": "NewsArticle",
    "mainEntityOfPage": {
      "@type": "WebPage",
      "@id": "www.google.com"
    },
    "headline": "???"
    }
    </script>
</head>
<body>
    <amp-list layout="fixed-height" height="100vh" width="auto" src="www.google.com/json" class="m1">
          <template type="amp-mustache" id="amp-template-id">
                <p>{{title}}</p>
          </template>
    </amp-list>
</body>

可以使用{{}}在amp-list标签中访问文章的标题。我需要头部的json-ld中的这个值作为标题的值。有关如何做到这一点的任何建议吗?

1 个答案:

答案 0 :(得分:0)

您可以使用Microdata代替JSON-LD来标记文档。这样,元数据将与您的内容内联,并可通过amp-list生成:

<amp-list layout="fixed-height" height="100vh" width="auto" src="www.google.com/json" class="m1">
  <template type="amp-mustache" id="amp-template-id">
    <h1 itemprop="headline">{{title}}</h1>
    <h2 itemprop="author" itemscope itemtype="https://schema.org/Person">
      <span itemprop="name">{{author}}</span>
    </h2>
    ...
  </template>
</amp-list>

Here是一个完整的微数据样本。

相关问题