Permalink
Fetching contributors…
Cannot retrieve contributors at this time
144 lines (128 sloc) 6.55 KB
<!--
#### Introduction
The [amp-live-list](https://www.ampproject.org/docs/reference/components/amp-live-list) component adds support for publishing live updates to AMP pages as new content becomes available in the source document. This works great for implementing live blogs. Find an example of a live blog [here](/samples_templates/live_blog).
In other words, the AMP runtime will poll the server for updates to the origin document, fetching itself. The server can return the entire AMP page [or parts of it](https://github.com/ampproject/amphtml/blob/master/extensions/amp-live-list/amp-live-list-server-side-filtering.md), and the runtime updates the page in-place seamlessly.
-->
<!-- -->
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<!-- #### Setup -->
<!--
Import the `amp-live-list` component in the header.
-->
<script async custom-element="amp-live-list" src="https://cdn.ampproject.org/v0/amp-live-list-0.1.js"></script>
<link rel="canonical" href="<%host%>/components/amp-live-list/">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<!--
Use `amp-live-list-item` to style the children of the `amp-live-list`. Refer to the [documentation](https://www.ampproject.org/docs/reference/components/amp-live-list) for details.
-->
<style amp-custom>
.amp-live-list-item {
justify-content: center;
display: flex;
}
.blog {
padding: 0;
background: #fff;
width: 300px;
}
.blog p {
padding: 8px;
margin: 0;
}
.match {
background: #fff;
min-width: 0%;
}
header {
font-size: 2rem;
}
.side {
display: flex;
align-items: center;
justify-content: space-around;
}
.content {
font-size: 2rem;
padding: 8px;
}
.flag {
padding-top: 8px;
padding-bottom: 8px;
}
.button-update {
margin: 16px;
}
</style>
</head>
<body>
<!-- #### Implementing a Live Blog -->
<!--
Use the `data-poll-interval` attribute to specify how frequently the `amp-live-list` component will poll new data. The minimum interval is 15 seconds.
Use `data-max-items-per-page` to specify the maximum number displayed on the page.
For an extensive explanation of all the attributes, refer to [amp-live-list](https://www.ampproject.org/docs/reference/components/amp-live-list).
Use `on="tap:my-live-list.update"` to load the latest changes from the server.
A button will appear when the AMP runtime discovers new document changes. Note that the button has to be defined as a direct child of `amp-live-list` .
An `amp-live-list` must contain a list of items below `<div items>`. Each item has a specific id and the `amp-live-list` will look for items with new id.
This sample shows an implementation with a server rendering a series of 5 elements. `amp-live-list` will poll the page every 15 seconds until 5 elements are added to the page. Every time `amp-live-list` polls the page, the server adds a new item to the page. Refer to [server.go](https://github.com/ampproject/amp-by-example/blob/master/server.go) and [amp-live-list.go](https://github.com/ampproject/amp-by-example/blob/master/backend/amp-live-list.go) for implementation details.
This sample stops after ten updates. If you want to start over, delete cookies from ampbyexample.com or open this page again in an incognito/private tab.
<p class="card important">
By clicking on the button "You have updates", new content is displayed on the demo column (the one on the right if the demo is accessed by desktop). The code column (the one in the center if the demo is accessed by desktop) does not update itself, but if you want to see all the items on the page, reload the page.
</p>
-->
<amp-live-list
layout="container"
data-poll-interval="15000"
data-max-items-per-page="5"
id="amp-live-list-insert-blog">
<button update on="tap:amp-live-list-insert-blog.update" class="button button-primary button-update">You have updates</button>
<div items>
[[range .BlogItems]]
<div id="[[.Text]]" data-sort-time="[[.Timestamp]]">
<div class="card blog">
<amp-img src="[[.Image]]"
layout="responsive" width="1280" height="853">
</amp-img>
<p>[[.Text]]</p>
</div>
</div>
[[end]]
</div>
</amp-live-list>
<!-- #### Implementing a Live Score -->
<!--
If you want to update existing list items, you need to specify via the `data-update-time` attribute when the update has been performed.
The following example will display a soccer match score whose content is changed every time the `amp-live-list` polls the page on the server.
-->
<amp-live-list
layout="container"
data-poll-interval="15000"
data-max-items-per-page="5"
id="amp-live-list-update">
<button update on="tap:amp-live-list-update.update" class="button button-primary">You have updates</button>
<div items>
<div id="list-item-1" data-sort-time="1234567" data-update-time="[[.FootballScore.Timestamp]]">
<div class="card match">
<div class="side">
<div class="flag">
<amp-img src="/img/italy-flag.png"
layout="fixed" height="50" width="100">
</amp-img>
</div>
<div class="content">[[.FootballScore.ScoreTeam1]] - [[.FootballScore.ScoreTeam2]]</div>
<div class="flag">
<amp-img src="/img/england-flag.png"
layout="fixed" height="50" width="100">
</amp-img>
</div>
</div>
</div>
</div>
</div>
</amp-live-list>
</body>
</html>