Skip to content

Instantly share code, notes, and snippets.

@justinribeiro
Last active November 2, 2016 18:55
Show Gist options
  • Save justinribeiro/163d2ac26b305fdeaea397d640d45055 to your computer and use it in GitHub Desktop.
Save justinribeiro/163d2ac26b305fdeaea397d640d45055 to your computer and use it in GitHub Desktop.
Let's talk about AMP!
class MainHandler(http2.PushHandler):
def get(self):
name = os.path.join(os.path.dirname(__file__), 'dist/static/data/', self.request.path.lstrip("/amphtml/"), 'index.json')
f = open(name, 'r');
c = f.read()
f.close()
data = json.loads(c)
data['article'] = unescape(data['article'])
data['permalinkamp'] = data['permalink'].replace(".com", ".com/amphtml")
bot_template = os.path.join(os.path.dirname(__file__), 'dist/static/amphtml/index.html')
return self.response.write(template.render(bot_template, data))
app = webapp2.WSGIApplication([
('/.*', MainHandler)
], debug=True)
<!doctype html>
<html ⚡ lang="en">
<head>
<meta charset="utf-8">
<title>Hello, AMPs</title>
<link rel="canonical" href="http://example.ampproject.org/article-metadata.html" />
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "NewsArticle",
"headline": "Open-source framework for publishing content",
"datePublished": "2015-10-07T12:02:41Z",
"image": [
"logo.jpg"
]
}
</script>
<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>
<script async src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
<h1>Welcome to the mobile web</h1>
</body>
</html>
<amp-analytics type="googleanalytics" config="https://example.com/analytics.account.config.json">
<script type="application/json">
{
"requests": {
"pageview": "https://example.com/analytics?url=${canonicalUrl}&title=${title}&acct=${account}",
"event": "https://example.com/analytics?eid=${eventId}&elab=${eventLabel}&acct=${account}"
},
"vars": {
"account": "ABC123"
},
"extraUrlParams": {
"cd1": "AMP"
},
"triggers": {
"trackPageview": {
"on": "visible",
"request": "pageview"
},
"trackAnchorClicks": {
"on": "click",
"selector": "a",
"request": "event",
"vars": {
"eventId": "42",
"eventLabel": "clicked on a link"
}
}
},
'transport': {
'beacon': false,
'xhrpost': false,
'image': true
}
}
</script>
</amp-analytics>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment