Commit 0a98e78c authored by Andrew Gerrand's avatar Andrew Gerrand

[release-branch.go1.1] doc: pull front page featured articles using new blog JSON feed

««« CL 9288045 / 5785ebd7acfb
doc: pull front page featured articles using new blog JSON feed

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/9288045
»»»

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/9050046
parent c785d6af
...@@ -84,41 +84,38 @@ Linux, Mac OS X, Windows, and more. ...@@ -84,41 +84,38 @@ Linux, Mac OS X, Windows, and more.
<div style="clear: both;"></div> <div style="clear: both;"></div>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript"> <script type="text/javascript">
google.load("feeds", "1");
function readableTime(t) {
var m = ["January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"];
var p = t.substring(0, t.indexOf("T")).split("-");
var d = new Date(p[0], p[1]-1, p[2]);
return d.getDate() + " " + m[d.getMonth()] + " " + d.getFullYear();
}
function feedLoaded(result) { function feedLoaded(result) {
if (result.error) {
console.log(result.error);
return;
}
var blog = document.getElementById("blog"); var blog = document.getElementById("blog");
var read = blog.getElementsByClassName("read")[0]; var read = blog.getElementsByClassName("read")[0];
for (var i = 0; i < result.feed.entries.length && i < 2; i++) { for (var i = 0; i < result.length && i < 2; i++) {
var entry = result.feed.entries[i]; var entry = result[i];
var title = document.createElement("a"); var title = document.createElement("a");
title.className = "title"; title.className = "title";
title.href = entry.link; title.href = entry.Link;
title.innerHTML = entry.title; title.innerHTML = entry.Title;
blog.insertBefore(title, read); blog.insertBefore(title, read);
var extract = document.createElement("div"); var extract = document.createElement("div");
extract.className = "extract"; extract.className = "extract";
extract.innerHTML = entry.contentSnippet; extract.innerHTML = entry.Summary;
blog.insertBefore(extract, read); blog.insertBefore(extract, read);
var when = document.createElement("div"); var when = document.createElement("div");
when.className = "when"; when.className = "when";
var pub = entry.publishedDate.split(" ").slice(1,3).join(" "); when.innerHTML = "Published " + readableTime(entry.Time);
when.innerHTML = "Published " + pub
blog.insertBefore(when, read); blog.insertBefore(when, read);
} }
} }
function init() { $(function() {
// Load blog feed.
var feed = new google.feeds.Feed("http://blog.golang.org/feeds/posts/default");
feed.load(feedLoaded);
// Set up playground. // Set up playground.
playground({ playground({
"codeEl": "#learn .code", "codeEl": "#learn .code",
...@@ -128,7 +125,11 @@ function init() { ...@@ -128,7 +125,11 @@ function init() {
"shareRedirect": "http://play.golang.org/p/", "shareRedirect": "http://play.golang.org/p/",
"toysEl": "#learn .toys select" "toysEl": "#learn .toys select"
}); });
}
google.setOnLoadCallback(init); // Load blog feed.
$('<script/>').attr('text', 'text/javascript')
.attr('src', 'http://blog.golang.org/.json?jsonp=feedLoaded')
.appendTo('body');
});
</script> </script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment