FIX: include youtube link in embedded comments

This commit is contained in:
Arpit Jalan 2015-05-01 18:34:45 +05:30
parent 80003e0821
commit 23fd16850a
3 changed files with 12 additions and 4 deletions

View file

@ -41,7 +41,7 @@ class EmbedController < ApplicationController
topic_embeds = TopicEmbed.where(embed_url: urls).includes(:topic).references(:topic) topic_embeds = TopicEmbed.where(embed_url: urls).includes(:topic).references(:topic)
topic_embeds.each do |te| topic_embeds.each do |te|
url = te.embed_url url = te.embed_url
url = "#{url}#discourse-comments" unless params[:embed_url].include?(url) url = "#{url}#discourse-comments" unless params[:embed_url].include?(url)
by_url[url] = I18n.t('embed.replies', count: te.topic.posts_count - 1) by_url[url] = I18n.t('embed.replies', count: te.topic.posts_count - 1)
end end

View file

@ -14,5 +14,14 @@ module EmbedHelper
end end
end end
def get_html(cooked)
fragment = Nokogiri::HTML.fragment(cooked)
# 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
raw fragment
end
end end

View file

@ -25,7 +25,7 @@
<span class='title'><%= post.user.title %></span> <span class='title'><%= post.user.title %></span>
<%- end %> <%- end %>
</h3> </h3>
<%= raw post.cooked %> <%= get_html(post.cooked) %>
<%- if post.reply_count > 0 %> <%- if post.reply_count > 0 %>
<%- if post.reply_count == 1 %> <%- if post.reply_count == 1 %>
@ -51,4 +51,3 @@
<% end %> <% end %>
<% end %> <% end %>