Skip to content

Instantly share code, notes, and snippets.

@alexcican
Created February 11, 2013 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexcican/4753483 to your computer and use it in GitHub Desktop.
Save alexcican/4753483 to your computer and use it in GitHub Desktop.
Displaying recent posts on Scriptogr.am
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load("feeds", "1");
google.setOnLoadCallback(OnLoad);
/* creates a feed instance and loads the feed */
function OnLoad() {
var feed = new google.feeds.Feed("http://scriptogr.am/sican/feed/");
feed.load(feedLoaded);
}
/* when the feed is loaded */
function feedLoaded(result) {
if (!result.error) {
/* grabs the container the recent posts will be added */
var container = document.getElementById("recent-articles");
container.innerHTML = '';
/* loops through the feed elements (omit the newest post because it's shown on homepage), and append posts to the div */
for (var i = 1; i < 4; i++) {
var entry = result.feed.entries[i];
/* gets the date of the post */
var entryDate = new Date(entry.publishedDate);
var curr_date = entryDate.getDate();
var curr_month = entryDate.getMonth();
var curr_year = entryDate.getFullYear();
/* displays names of months instedad of numbers */
var month_names = new Array ( );
month_names[month_names.length] = "January";
month_names[month_names.length] = "February";
month_names[month_names.length] = "March";
month_names[month_names.length] = "April";
month_names[month_names.length] = "May";
month_names[month_names.length] = "June";
month_names[month_names.length] = "July";
month_names[month_names.length] = "August";
month_names[month_names.length] = "September";
month_names[month_names.length] = "October";
month_names[month_names.length] = "November";
month_names[month_names.length] = "December";
/* creats the html elements */
var linkContainer = document.createElement('p');
var title = document.createTextNode(entry.title);
var link = document.createElement('a');
var date = document.createElement('span');
/* fills html elements with post details */
date.innerHTML = " " + month_names[curr_month] + " " + curr_date + ", " + curr_year;
link.setAttribute('href', entry.link);
link.setAttribute('title', entry.title);
link.insertBefore(title);
link.appendChild(date);
linkContainer.appendChild(link);
/* replaces the scriptogr.am domain with your custom domain name */
link.href = link.href.replace("scriptogr.am/sican","blog.sicanstudios.com");
container.appendChild(linkContainer);
}
}
}
</script>
@alexcican
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment