AMP JSON-LD动态内容
问题描述:
我想让JSON-LD脚本的内容保持动态。但是,AMP不允许我使用Javascript,并且脚本应该在头上。
由于放大器列表,保持人体内容动态不成问题。AMP JSON-LD动态内容
<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中将此值作为标题的值。有关如何做到这一点的任何建议?
答
您可以使用Microdata而不是JSON-LD来标记文档。这样,元数据将与您的内容被内联,并且可以通过放列表生成:
<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是一个完整的微观数据样本。
这将是一个解决方案。但我更喜欢JSON-LD。有没有办法让它工作? –
不,没有。 –