2017-08-11 114 views
0

我想讓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中將此值作爲標題的值。有關如何做到這一點的任何建議?

回答

0

您可以使用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是一個完整的微觀數據樣本。

+0

這將是一個解決方案。但我更喜歡JSON-LD。有沒有辦法讓它工作? –

+0

不,沒有。 –