【问题标题】:AMP JSON-LD dynamic contentAMP JSON-LD 动态内容
【发布时间】:2017-08-11 12:32:54
【问题描述】:

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

<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 中的这个值作为标题的值。有关如何执行此操作的任何建议?

【问题讨论】:

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


    【解决方案1】:

    您可以使用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 是完整的微数据样本。

    【讨论】:

    • 这将是一个解决方案。但我更喜欢 JSON-LD。有没有办法让它工作?
    • 不,没有。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多