1
0
Fork 1
mirror of https://github.com/wezm/wezm.net.git synced 2024-12-26 05:59:54 +00:00
wezm.net/lib/articles.rb

44 lines
1 KiB
Ruby
Raw Normal View History

2010-06-14 22:19:28 +00:00
require 'rubypants'
module WezM
module Helpers
module Articles
def personal_articles
sorted_articles.select { |a| a.identifier =~ %r{^/personal/} }
end
def technical_articles
sorted_articles.select { |a| a.identifier =~ %r{^/technical/} }
end
def article_to_json(article)
{
2010-06-14 22:19:12 +00:00
:title => RubyPants.new(article[:title]).to_html,
:path => article.identifier,
:date => Time.parse(article[:created_at]).rfc2822,
2010-06-14 22:19:12 +00:00
:text => RubyPants.new(article[:title]).to_html,
:extra => RubyPants.new(article[:extra] || " ").to_html
}
end
def short_url(url)
2010-06-14 22:19:28 +00:00
require 'bitly'
begin
@bitly ||= Bitly.new('wezm', 'R_f2bfdace56c886671086eb0c8acb9ce7')
@cache ||= {}
unless u = @cache[url]
u = @bitly.shorten(url)
else
puts "Cache hit on #{url}"
end
u.short_url
rescue BitlyError
nil
end
end
end
end
end