all repos — h3rald @ 09de4570a010c9e042347cee2d233d59f85a0fdd

The sources of https://h3rald.com

Re-implemented feeds (json)
* Closes #32.
h3rald h3rald@h3rald.com
Sun, 16 Aug 2009 17:33:11 +0200
commit

09de4570a010c9e042347cee2d233d59f85a0fdd

parent

a443e54b04fd90c89f1aa1411893cdc22a250974

M content/home.textilecontent/home.textile

@@ -3,7 +3,7 @@ permalink: home

filters_pre: - erb - redcloth -title: Welcome +title: Home type: page ----- <%

@@ -13,6 +13,7 @@ all_articles = latest_articles

latest = latest_articles 5 popular = popular_articles 5 %> +h2. Welcome This is Fabio Cevasco's web site, featuring <%= all_articles.length %> "articles":/archives/ and <%= 5 %> open source "projects":/projects/. Fabio is a full-time technical writer working in Genoa, Italy. In his free time, he enjoys writing (surprise, surprise), reading about technology and programming a little bit in Ruby and other languages.
M layouts/default.htmlayouts/default.htm

@@ -105,8 +105,8 @@ <!-- MAIN END -->

<div class="inner-border"></div> <div id="border-bottom"> <div id="share"> -<a class="a2a_dd" href="http://www.addtoany.com/share_save"><img src="http://static.addtoany.com/buttons/share_save_120_16.gif" width="120" height="16" border="0" alt="Share/Save/Bookmark"/></a><script type="text/javascript">a2a_linkname=document.title;a2a_linkurl=location.href;a2a_onclick=1;a2a_prioritize=["delicious","stumbleupon","friendfeed","twitter","dzone","digg","reddit","slashdot","facebook","newsvine","sphere","ping"];</script><script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script> -<a class="a2a_dd" href="http://www.addtoany.com/subscribe?linkname=&amp;linkurl=http%3A%2F%2Fwww.h3rald.com%2Frss%2F"><img src="http://static.addtoany.com/buttons/subscribe_120_16.gif" width="120" height="16" border="0" alt="Subscribe"/></a><script type="text/javascript">a2a_linkname=document.title;a2a_linkurl="http://www.h3rald.com/rss/";a2a_onclick=1;</script><script type="text/javascript" src="http://static.addtoany.com/menu/feed.js"></script> +<a class="a2a_dd" href="http://www.addtoany.com/share_save"><img src="http://static.addtoany.com/buttons/share_save_120_16.gif" width="120" height="16" alt="Share/Save/Bookmark"/></a><script type="text/javascript">a2a_linkname=document.title;a2a_linkurl=location.href;a2a_onclick=1;a2a_prioritize=["delicious","stumbleupon","friendfeed","twitter","dzone","digg","reddit","slashdot","facebook","newsvine","sphere","ping"];</script><script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script> +<a class="a2a_dd" href="http://www.addtoany.com/subscribe?linkname=&amp;linkurl=http%3A%2F%2Fwww.h3rald.com%2Frss%2F"><img src="http://static.addtoany.com/buttons/subscribe_120_16.gif" width="120" height="16" alt="Subscribe"/></a><script type="text/javascript">a2a_linkname=document.title;a2a_linkurl="http://www.h3rald.com/rss/";a2a_onclick=1;</script><script type="text/javascript" src="http://static.addtoany.com/menu/feed.js"></script> </div> <% if @page.type == 'article' then %> <%= render 'comments' %>
M layouts/services.htmlayouts/services.htm

@@ -4,7 +4,7 @@ -----

<div id="services"> <div class ="footer-left"> <div id="backtype"> - <h3><a href="http://www.backtype.com/h3rald">Comments</a></h3> + <h3><a href="http://www.backtype.com/h3rald">Opinions</a></h3> </div> </div> <div class ="footer-center">
M resources/css/elements.cssresources/css/elements.css

@@ -164,7 +164,7 @@ }

/*** COMMENTS ***/ -#idc-container-parent, #legacy-comments; +#idc-container-parent, #legacy-comments { padding: 5px; }
M resources/css/text.cssresources/css/text.css

@@ -47,20 +47,13 @@

#services h3 { border: 1px solid #000; - text-align: left; - cursor: pointer; font-style: italic; - height: 50px; + padding-top: 10px; + text-align: center; } em { font-style: italic; -} - - -#services h3 a -{ - padding-top: 10px; } #content ul
M resources/js/feeds.jsresources/js/feeds.js

@@ -2,76 +2,80 @@ function format_date(d){

return $.timeago(Date.parse(d)); } -function feed_entry(entry, element){ - var published_at = format_date(entry.publishedDate); +function get_json_data(uri, max, element){ + $.getJSON(uri, + function(data){ + var list = $("<ul></ul>"); + for (var i=0; i<max; i++){ + switch(element){ + case "#backtype": + var item = backtype_entry(data.comments[i]) + break; + case "#delicious": + var item = delicious_entry(data[i]) + break; + case "#twitter": + var item = twitter_entry(data[i]) + break; + } + item.appendTo(list); + } + list.appendTo(element).fadeIn(1000); + }); +} + +function backtype_entry(comment){ + var c = $("<li></li>").addClass('feed-item'); + var dt = $("<span></span>").addClass('feed-item-date').html(format_date(comment.comment.date)+":"); + var tx = $("<span>&#0187; </span>").addClass('feed-item-text').append($('<a></a>').attr('href', comment.comment.url).html(comment.post.title)); + c.append(dt); + c.append(tx); + return c +} + +function twitter_entry(tweet){ + var it = $("<li></li>").addClass('feed-item'); + var content = tweet.text + .replace(/^h3rald:/, '') + .replace(/((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?)/g, '<a href="$1">$1</a>') + .replace(/@([a-zA-Z1-9_]*)/g, '<a href="http://www.twitter.com/$1">@$1</a>') + .replace(/#([a-zA-Z1-9_]*)/g, '<a href="http://www.twitter.com/search?q=%23$1">#$1</a>') + var dt = $("<span></span>").addClass('feed-item-date').html(format_date(tweet.created_at)+":"); + var tx = $("<span>&#0187; </span>").addClass('feed-item-text').html(content); + it.append(dt); + it.append(tx); + return it +} + +function delicious_entry(bookmark){ var it = $("<li></li>").addClass('feed-item'); - switch(element) + var content = "<a href='"+bookmark.u+"'>"+bookmark.d+"</a>"; + content += "<br />tags: "; + var categories = Array(); + for (i=0; i<bookmark.t.length; i++) { - case "#twitter": - var content = entry.title - .replace(/^h3rald:/, '') - .replace(/((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?)/, '<a href="$1">$1</a>') - .replace(/ @([a-zA-Z1-9_]*)/, ' <a href="http://www.twitter.com/$1">@$1</a>') - .replace(/ #([a-zA-Z1-9_]*)/, ' <a href="http://www.twitter.com/search?q=%23$1">#$1</a>') - dt = $("<span></span>").addClass('feed-item-date').html(published_at+":"); - tx = $("<span>&#0187; </span>").addClass('feed-item-text').html(content); - it.append(dt); - it.append(tx) - break; - case "#delicious": - var content = "<a href='"+entry.link+"'>"+entry.title+"</a>"; - content += "<br />tags: "; - var categories = Array(); - for (i=0; i<entry.categories.length; i++) - { - categories[i] = "<a href='http://delicious.com/h3rald/"+entry.categories[i]+"'>"+entry.categories[i]+"</a> "; - } - content += categories.join(', ').replace(/ $/, ''); - dt = $("<span></span>").addClass('feed-item-date').html(published_at+":"); - tx = $("<span>&#0187; </span>").addClass('feed-item-text').html(content); - it.append(dt); - it.append(tx) - break; + categories[i] = "<a href='http://delicious.com/h3rald/"+bookmark.t[i]+"'>"+bookmark.t[i]+"</a> "; } - return it; -}; -function display_feed(feed, element){ - if (!feed){ - $('<p>An error occurred while retrieving this feed.</p>').appendTo(element); - return false; - } - var feed_list = $("<ul></ul>"); - var entries = feed.entries; - for(var i=0; i<entries.length; i++){ - var entry = entries[i]; - feed_list.append(feed_entry(entry, element)).fadeIn(1000); - } - feed_list.appendTo(element) -}; -var delicious_feed = function(feed){ - display_feed(feed, "#delicious") -}; -var twitter_feed = function(feed){ - display_feed(feed, "#twitter") -}; + content += categories.join(', ').replace(/ $/, ''); + dt = $("<span></span>").addClass('feed-item-date').html(format_date(bookmark.dt)+":"); + tx = $("<span>&#0187; </span>").addClass('feed-item-text').html(content); + it.append(dt); + it.append(tx); + return it +} + // http://api.backtype.com/user/h3rald/comments.json?key=47bf0031e3a18a598b85&html=1 -function backtype_comments(max) -{ - $.getJSON("/data/comments.json", - function(data){ - var comment_list = $("<ul></ul>"); - $.each(data.comments, function(i, comment){ - c = $("<li></li>").addClass('feed-item'); - dt = $("<span></span>").addClass('feed-item-date').html(format_date(comment.comment.date)+":"); - tx = $("<span>&#0187; </span>").addClass('feed-item-text').append($('<a></a>').attr('href', comment.comment.url).html(comment.post.title)); - c.append(dt); - c.append(tx); - c.appendTo(comment_list); - if ( i == max ) { - comment_list.appendTo("#backtype").fadeIn(1000); - return false; - } - }); - }); +function display_opinions(max){ + get_json_data("/data/opinions.json", max, '#backtype') +} + +// http://twitter.com/status/user_timeline/h3rald.json +function display_tweets(max){ + get_json_data("/data/tweets.json", max, '#twitter') +} + +// http://feeds.delicious.com/v2/json/h3rald +function display_bookmarks(max){ + get_json_data("/data/bookmarks.json", max, '#delicious') }
M resources/js/init.jsresources/js/init.js

@@ -1,8 +1,8 @@

$(document).ready(function() { // Feeds - backtype_comments(7); - $.jGFeed('http://twitter.com/statuses/user_timeline/h3rald.rss', twitter_feed, 7); - $.jGFeed('http://feeds.delicious.com/v2/rss/h3rald', delicious_feed, 7); + display_opinions(7); + display_tweets(7); + display_bookmarks(7); // Drop Caps $('h2 + p').each(function(){ var first_paragraph = this;//$('#content p')[0];
M tasks/site.raketasks/site.rake

@@ -61,6 +61,7 @@ task :clear_output do

output = Pathname.new(Dir.pwd)/'output' puts "Deleting all files in output dir..." output.rmtree + (output/'data').mkpath end task :update => [:copy_resources] do