AMP Roadshow is coming to Atlanta & Berlin!
AMP
  • websites

Live Blog

Introduction

This is a sample template for implementing live blogs in AMP.

Setup

Import amp-social-share for adding share buttons

<script async custom-element="amp-social-share" src="https://cdn.ampproject.org/v0/amp-social-share-0.1.js"></script>

Import amp-live-list for implementing a live blog.

<script async custom-element="amp-live-list" src="https://cdn.ampproject.org/v0/amp-live-list-0.1.js"></script>

Metadata

Live blog updates can be represented in Google Search results as carousel items of the blog page. Learn more.

<script type="application/ld+json">
  {
    "@context": "http://schema.org",
    "@type": "LiveBlogPosting",
    "url": "https://ampbyexample.com/samples_templates/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://ampbyexample.com/samples_templates/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": [[.BlogMetadata]]
  }
</script>

Blog Posts

Use amp-live-list to implement a live blog. The amp-live-list component regularly polls the host document for updated content and updates the end user's browser as new items become available. This means that every time a new post needs to be added, the host document should be updated by the CMS to include the update both the body and the metadata section. Find an amp-live-list example here.

Long blogs could use pagination to improve performance by limiting the number of blog items to be displayed on a page. To implement pagination, amp-live-list allows to add the <div pagination></div> element, to then insert any markup needed for pagination, for example the page number, a link to the next and previous page.

[[range .BlogItems]]

[[.Heading]]

[[.Date]]

[[.Text]]

[[end]]
<amp-live-list [[.Disabled]]
  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>
    [[range .BlogItems]]
    <div id="[[.ID]]"
      data-sort-time="[[.Timestamp]]">
      <div class="blog">
        <amp-img src="[[.Image]]"
          layout="responsive"
          width="1280"
          height="853">
        </amp-img>
        <h4 class="title">[[.Heading]]</h4>
        <p class="date">[[.Date]]</p>
        <p class="text">[[.Text]]</p>
        <p class="social-share">
          <amp-social-share type="twitter"
            width="45"
            height="33"
            data-param-url="AMPDOC_URL#[[.ID]]"></amp-social-share>
          <amp-social-share type="facebook"
            width="45"
            height="33"
            data-attribution="254325784911610"
            data-param-url="AMPDOC_URL#[[.ID]]"></amp-social-share>
          <amp-social-share type="gplus"
            width="45"
            height="33"
            data-param-url="AMPDOC_URL#[[.ID]]"></amp-social-share>
          <amp-social-share type="email"
            width="45"
            height="33"
            data-param-url="AMPDOC_URL#[[.ID]]"></amp-social-share>
          <amp-social-share type="pinterest"
            width="45"
            height="33"
            data-param-url="AMPDOC_URL#[[.ID]]"></amp-social-share>
        </p>
      </div>
    </div>
    [[end]]
  </div>
  <div pagination>
    <nav aria-label="amp live list pagination">
      <ul class="pagination">
        [[if .PrevPageURL]]
        <li><a href="[[.PrevPageURL]]">Prev</a></li>
        [[end]]
        <li>[[.PageNumber]]</li>
        [[if .NextPageURL]]
        <li><a href="[[.NextPageURL]]">Next</a></li>
        [[end]]
      </ul>
    </nav>
  </div>
</amp-live-list>
Need further explanation?

If the explanations on this page don't cover all of your questions feel free to reach out to other AMP users to discuss your exact use case.

Go to Stack Overflow
An unexplained feature?

The AMP project strongly encourages your participation and contributions! We hope you'll become an ongoing participant in our open source community but we also welcome one-off contributions for the issues you're particularly passionate about.

Edit sample on GitHub