Skip to content

Instantly share code, notes, and snippets.

@Kimserey
Created January 26, 2017 11:36
Show Gist options
  • Save Kimserey/fc9cac12bac07e7bf25fa56048821128 to your computer and use it in GitHub Desktop.
Save Kimserey/fc9cac12bac07e7bf25fa56048821128 to your computer and use it in GitHub Desktop.
Preview few post from blogger
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<style type="text/css">
.post-title a {
color: #000000;
text-transform: capitalize;
font-size: 13px;
}
.post-summary {
border-bottom: 1px dotted #cccccc;
padding-bottom: 10px;
margin-top: 5px;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
</head>
<body>
<div id="latestposts">
<h1>Latest posts</h1>
</div>
<script type="text/javascript">
var list = document.getElementById("latestposts");
function template(title, description, date, href) {
var div = document.createElement('div');
if (description.length > 50)
description = description.substring(0, 200) + '...';
div.innerHTML = '<div>' + '<a href="' + href + '" class="post-title">' + title + '</a>' + '<div class="post-summary">' + description + " " + '<span>' + date + '</span>' + '</div>' + '</div>';
return div;
}
function appendEntries(entries, list) {
entries
.forEach(function(post) {
var title = post.title.$t;
var description = post.summary.$t;
var href = post.link[4].href;
var date = moment(post.published.$t).format("d MMM YYYY");
list.appendChild(template(title, description, date, href));
});
}
function showposts(t) {
appendEntries(t.feed.entry.slice(0, 3), list);
}
</script>
<script src="http://kimsereyblog.blogspot.com/feeds/posts/default?orderby=published&alt=json-in-script&callback=showposts"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment