1

我想保持我的 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 中的这个值作为标题的值。关于如何做到这一点的任何建议?

4

1 回答 1

2

您可以使用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>

是一个完整的微数据示例。

于 2017-08-13T13:20:36.920 回答