2014-03-20 13:25:17 -04:00
|
|
|
module EmbedHelper
|
|
|
|
|
|
|
|
def embed_post_date(dt)
|
|
|
|
current = Time.now
|
|
|
|
|
|
|
|
if dt >= 1.day.ago
|
|
|
|
distance_of_time_in_words(dt, current)
|
|
|
|
else
|
|
|
|
if dt.year == current.year
|
|
|
|
dt.strftime("%e %b")
|
|
|
|
else
|
2014-03-23 15:22:02 -04:00
|
|
|
dt.strftime("%b '%y")
|
2014-03-20 13:25:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-01 09:04:45 -04:00
|
|
|
def get_html(cooked)
|
|
|
|
fragment = Nokogiri::HTML.fragment(cooked)
|
2015-08-21 15:22:33 -04:00
|
|
|
|
2015-05-01 09:04:45 -04:00
|
|
|
# convert lazyYT div to link
|
|
|
|
fragment.css('div.lazyYT').each do |yt_div|
|
|
|
|
youtube_id = yt_div["data-youtube-id"]
|
|
|
|
youtube_link = "https://www.youtube.com/watch?v=#{youtube_id}"
|
|
|
|
yt_div.replace "<p><a href='#{youtube_link}'>#{youtube_link}</a></p>"
|
|
|
|
end
|
2015-08-21 15:22:33 -04:00
|
|
|
|
2015-08-11 01:01:04 -04:00
|
|
|
# convert Vimeo iframe to link
|
|
|
|
fragment.css('iframe').each do |iframe|
|
|
|
|
if iframe['src'] =~ /player.vimeo.com/
|
|
|
|
vimeo_id = iframe['src'].split('/').last
|
|
|
|
iframe.replace "<p><a href='https://vimeo.com/#{vimeo_id}'>https://vimeo.com/#{vimeo_id}</a></p>"
|
|
|
|
end
|
|
|
|
end
|
2015-08-21 15:22:33 -04:00
|
|
|
|
|
|
|
# Strip lightbox metadata
|
|
|
|
fragment.css('.lightbox-wrapper .meta').remove
|
|
|
|
|
2015-05-01 09:04:45 -04:00
|
|
|
raw fragment
|
|
|
|
end
|
2014-03-20 13:25:17 -04:00
|
|
|
end
|