即時網誌
簡介
這是在 AMP 中實作即時網誌的範例範本。
設定
匯入 amp-social-share
以新增分享按鈕
<script async custom-element="amp-social-share" src="https://cdn.ampproject.org/v0/amp-social-share-0.1.js"></script>
匯入 amp-live-list
以實作即時網誌。
<script async custom-element="amp-live-list" src="https://cdn.ampproject.org/v0/amp-live-list-0.1.js"></script>
Metadata
即時網誌更新可以 Google 搜尋結果中以網誌頁面的輪播項目呈現。瞭解更多。
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "LiveBlogPosting",
"url": "https://amp.dev.org.tw/documentation/examples/news-publishing/live_blog/",
"articleBody": "This is the initial text in the blog post",
"datePublished": "2016-09-08T23:04:28.24337",
"about": {
"@type": "Event",
"description": "This is my great live blog sample",
"startDate": "2016-07-23T13:00:00-07:00",
"endDate": "2016-07-23T15:00:00-07:00",
"name": "An AMP Live Blog",
"url": "https://amp.dev.org.tw/documentation/examples/news-publishing/live_blog/",
"location": {
"@type": "EventVenue",
"name": "The Venue Name",
"address" : {
"@type": "PostalAddress",
"streetAddress": "701 Mission St",
"addressLocality": "San Francisco",
"addressRegion": "CA",
"postalCode": "94103",
"addressCountry": "US"
}
}
},
"publisher": {
"@type": "Organization",
"name": "Google",
"logo": {
"@type": "ImageObject",
"url": "/static/samples/img/favicon.png",
"width": "512",
"height": "512"
}
},
"author": {
"@type": "Person",
"sameAs": "https://github.com/kul3r4",
"name": "Chiara Chiappini"
},
"image": {
"@type": "ImageObject",
"url": "/static/samples/img/abe_preview.png",
"height": "1532",
"width": "2046"
},
"coverageStartTime": "2016-07-23T11:30:00-07:00",
"coverageEndTime": "2016-07-23T16:00:00-07:00",
"headline": "An AMP Live Blog",
"description": "A Live Blog implementation with AMP",
"liveBlogUpdate": ""
}
</script>
網誌貼文
使用 amp-live-list 實作即時網誌。amp-live-list 組件會定期輪詢主機文件以取得更新的內容,並在有新項目可用時更新最終使用者的瀏覽器。這表示每次需要新增貼文時,都應由 CMS 更新主機文件,以在內文和 metadata 區段中包含更新。在此處尋找 amp-live-list 範例:這裡。
長篇網誌可以使用分頁來改善效能,方法是限制在單頁上顯示的網誌項目數量。若要實作分頁,amp-live-list 允許新增 <div pagination></div>
元素,然後插入分頁所需的任何標記,例如頁碼、下頁和上頁的連結。
<amp-live-list class="live-list" layout="container" data-poll-interval="15000" data-max-items-per-page="5" id="amp-live-list-insert-blog">
<button id="live-list-update-button" update on="tap:amp-live-list-insert-blog.update">You have updates</button>
<div items>
</div>
<div pagination>
<nav aria-label="amp live list pagination">
<ul class="pagination">
<li></li>
</ul>
</nav>
</div>
</amp-live-list>
需要更多說明嗎?
如果此頁面上的說明未涵蓋您的所有問題,請隨時與其他 AMP 使用者聯繫,討論您的確切使用案例。
前往 Stack Overflow 未說明的特色功能?AMP 專案強烈鼓勵您的參與和貢獻!我們希望您能成為我們開放原始碼社群的持續參與者,但我們也歡迎您針對您特別感興趣的問題做出一次性的貢獻。
在 GitHub 上編輯範例-
由 @aghassemi 撰寫