This patch hooks the deltacloud.org site to our Identi.ca news feed (http://identi.ca/deltacloud).
Since the feed is empty at the moment, change the `user` variable in `deltacloud.org/lib/news.rb:16` to other (more prolific) Identi.ca user to test this.
From: Tomas Sedovic tsedovic@redhat.com
The news for the website are generated from the news.json file. When webby runs, it fetches the newest tweets from the Deltacloud stream on Identi.ca, updates the news.json file and then regenerates the site.
The benefits of this approach are:
* mix multiple news sources (the original entries, identi.ca, whatever else) * ability to generate different views (e.g. "recent news" / "news archive") * keep/backup local copy of the news --- deltacloud.org/content/index.haml | 6 ++- deltacloud.org/lib/news.rb | 57 ++++++++++++++++++++++++++++++++---- deltacloud.org/news.json | 18 +++++++++++ 3 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 deltacloud.org/news.json
diff --git a/deltacloud.org/content/index.haml b/deltacloud.org/content/index.haml index 066110b..d179dfc 100644 --- a/deltacloud.org/content/index.haml +++ b/deltacloud.org/content/index.haml @@ -49,9 +49,11 @@ filter: haml %h2 News %ul - - all_news.each do |item| + - all_news.first(7).each do |item| %li - = item + = item[:text] + %p + Follow @deltacloud on <a href="http://identi.ca/deltacloud">Identi.ca</a> or <a href="http://twitter.com/deltacloud">Twitter</a>. %br %br .section.video{ :style => "margin-top:16px;" } diff --git a/deltacloud.org/lib/news.rb b/deltacloud.org/lib/news.rb index 98e149b..244a7cc 100644 --- a/deltacloud.org/lib/news.rb +++ b/deltacloud.org/lib/news.rb @@ -1,13 +1,56 @@ +require 'json' +require 'net/http' module NewsHelper def all_news - [ - %Q(Deltacloud Core <a href="http://watzmann.net/blog/2010/07/deltacloud-apache-incubator.html">moved to Apache Incubator</a>.), - %Q(Deltacloud now <a href="./drivers.html#providers">supports GoGrid</a>!), - %Q(We've introduced <a href="./api.html#h4_1">Hardware Profiles</a> to the API.), - %Q(Deltacloud <a href="http://press.redhat.com/2009/09/03/introducing-deltacloud/">announced</a> at 2009 Red Hat Summit!), - ] + refresh_news + return stored_news end
-end + StoredNewsPath = 'news.json' + + def stored_news + return JSON.parse(File.open(StoredNewsPath).read, {:symbolize_names => true}) + end + + def recent_tweets + user = 'deltacloud' + return JSON.parse(Net::HTTP.get(URI.parse("http://identi.ca/api/statuses/user_timeline/#%7Buser%7D.json?count=20")), {:symbolize_names => true}) + end + + def clickable_at_replies(text) + # convert @somebody in tweets to clickable http://identi.ca/somebody link + return text.gsub(/@(\w+)/, '<a href="http://identi.ca/\1">\0</a>') + end
+ def clickable_urls(text) + # convert plaintext URLs to HTML links + return text.gsub(/\b(([\w-]+://?|www[.])[^\s()<>]+(?:([\w\d]+)|([^[:punct:]\s]|/)))/, '<a href="\0">\0</a>') + end + + def tweeted_news + news = recent_tweets.collect do |t| + if not t[:in_reply_to_user_id] then # ignore tweet replies + news_item = { + :text => clickable_at_replies(clickable_urls(t[:text])), + :id => t[:id], + :date => Time.parse(t[:created_at]).xmlschema + } + end + end + return news.compact + end + + def refresh_news + news = stored_news + tweeted_news.each do |t| + if news.select{|n| n[:id] == t[:id]}.length == 0 then + news.push(t) + end + end + File::open(StoredNewsPath, 'w') do |f| + f.write(JSON.pretty_generate(news.sort {|x,y| y[:date] <=> x[:date] })) + end + end + +end Webby::Helpers.register(NewsHelper) diff --git a/deltacloud.org/news.json b/deltacloud.org/news.json new file mode 100644 index 0000000..a9ac6c8 --- /dev/null +++ b/deltacloud.org/news.json @@ -0,0 +1,18 @@ +[ + { + "date": "2010-07-12T11:00:47+02:00", + "text": "Deltacloud Core <a href="http://watzmann.net/blog/2010/07/deltacloud-apache-incubator.html%5C%22%3Emo... to Apache Incubator</a>." + }, + { + "date": "2010-05-06T14:22:22+02:00", + "text": "Deltacloud now <a href="./drivers.html#providers">supports GoGrid</a>!" + }, + { + "date": "2010-05-06T14:21:22+02:00", + "text": "We've introduced <a href="./api.html#h4_1">Hardware Profiles</a> to the API." + }, + { + "date": "2009-09-03T00:00:00+02:00", + "text": "Deltacloud <a href="http://press.redhat.com/2009/09/03/introducing-deltacloud/%5C%22%3Eannounced</a> at 2009 Red Hat Summit!" + } +] \ No newline at end of file
On Tue, 2010-07-27 at 17:28 +0200, tsedovic@redhat.com wrote:
From: Tomas Sedovic tsedovic@redhat.com
The news for the website are generated from the news.json file. When webby runs, it fetches the newest tweets from the Deltacloud stream on Identi.ca, updates the news.json file and then regenerates the site.
The benefits of this approach are:
- mix multiple news sources (the original entries, identi.ca, whatever else)
- ability to generate different views (e.g. "recent news" / "news archive")
- keep/backup local copy of the news
Pretty cool, ACK. I like that you posted a tweet on libdletacloud so we can see it works. I assume your evil plan now involves a step to have this update news more frequently/automatically? And a news archive page?
-j
deltacloud-devel@lists.fedorahosted.org