2013-05-21 19:53:36 +00:00
|
|
|
module PostHelper
|
|
|
|
def articles_by_year(articles)
|
|
|
|
hash = Hash.new { |h, k| h[k] = [] }
|
|
|
|
articles.inject(hash) do |output, article|
|
|
|
|
year = attribute_to_time(article[:created_at]).year
|
|
|
|
output[year] << article
|
|
|
|
output
|
2013-03-24 16:05:11 +00:00
|
|
|
end
|
2013-05-21 19:53:36 +00:00
|
|
|
end
|
2013-03-24 16:05:11 +00:00
|
|
|
|
2013-06-07 12:35:24 +00:00
|
|
|
def get_summary(post, length = 200)
|
|
|
|
doc = Nokogiri.HTML(post.compiled_content)
|
|
|
|
|
|
|
|
summary = ""
|
|
|
|
paragraphs = doc.search("p")
|
|
|
|
|
|
|
|
paragraphs.each do |paragraph|
|
|
|
|
summary += paragraph.to_s
|
|
|
|
break if summary.size >= length
|
|
|
|
end
|
|
|
|
|
|
|
|
summary
|
|
|
|
end
|
|
|
|
|
2013-05-21 19:53:36 +00:00
|
|
|
def get_short_date(post)
|
|
|
|
attribute_to_time(post[:created_at]).strftime('%Y-%m-%d')
|
|
|
|
end
|
2013-03-24 22:01:15 +00:00
|
|
|
|
2013-05-21 19:53:36 +00:00
|
|
|
def get_pretty_date(post)
|
2013-06-07 12:35:24 +00:00
|
|
|
attribute_to_time(post[:created_at]).strftime('%-d %B %Y')
|
2013-05-21 19:53:36 +00:00
|
|
|
end
|
2013-03-24 16:05:11 +00:00
|
|
|
|
2013-05-21 19:53:36 +00:00
|
|
|
def get_tags(post)
|
|
|
|
if post[:tags].nil? || post[:tags].empty?
|
|
|
|
"(not tagged)"
|
|
|
|
else
|
|
|
|
post[:tags].compact.map { |tag| tag.downcase }.sort.join(", ")
|
2013-03-24 16:05:11 +00:00
|
|
|
end
|
2013-05-21 19:53:36 +00:00
|
|
|
end
|
|
|
|
end
|