mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:30:26 -06:00
Merge pull request #2678 from techAPJ/patch-2
FIX: lazyYT youtube links not getting included in email
This commit is contained in:
commit
b1eb44bd0b
@ -4,12 +4,17 @@
|
|||||||
#
|
#
|
||||||
module Email
|
module Email
|
||||||
class Styles
|
class Styles
|
||||||
|
@@plugin_callbacks = []
|
||||||
|
|
||||||
def initialize(html)
|
def initialize(html)
|
||||||
@html = html
|
@html = html
|
||||||
@fragment = Nokogiri::HTML.fragment(@html)
|
@fragment = Nokogiri::HTML.fragment(@html)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.register_plugin_style(&block)
|
||||||
|
@@plugin_callbacks.push(block)
|
||||||
|
end
|
||||||
|
|
||||||
def add_styles(node, new_styles)
|
def add_styles(node, new_styles)
|
||||||
existing = node['style']
|
existing = node['style']
|
||||||
if existing.present?
|
if existing.present?
|
||||||
@ -60,6 +65,7 @@ module Email
|
|||||||
correct_footer_style
|
correct_footer_style
|
||||||
reset_tables
|
reset_tables
|
||||||
onebox_styles
|
onebox_styles
|
||||||
|
plugin_styles
|
||||||
end
|
end
|
||||||
|
|
||||||
def onebox_styles
|
def onebox_styles
|
||||||
@ -113,6 +119,12 @@ module Email
|
|||||||
style('.featured-topic a', 'text-decoration: none; font-weight: bold; color: #006699; margin-right: 5px')
|
style('.featured-topic a', 'text-decoration: none; font-weight: bold; color: #006699; margin-right: 5px')
|
||||||
|
|
||||||
onebox_styles
|
onebox_styles
|
||||||
|
plugin_styles
|
||||||
|
end
|
||||||
|
|
||||||
|
# this method is reserved for styles specific to plugin
|
||||||
|
def plugin_styles
|
||||||
|
@@plugin_callbacks.each { |block| block.call(@fragment) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_html
|
def to_html
|
||||||
|
@ -43,3 +43,21 @@ class Onebox::Engine::YoutubeOnebox
|
|||||||
result
|
result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
after_initialize do
|
||||||
|
|
||||||
|
Email::Styles.register_plugin_style do |fragment|
|
||||||
|
# YouTube onebox can't go in emails, so replace them with clickable links
|
||||||
|
fragment.css('.lazyYT').each do |i|
|
||||||
|
begin
|
||||||
|
src = "https://www.youtube.com/embed/#{i['data-youtube-id']}?autoplay=1&#{i['data-parameters']}"
|
||||||
|
src_uri = URI(src)
|
||||||
|
display_src = "https://#{src_uri.host}#{src_uri.path}"
|
||||||
|
i.replace "<p><a href='#{src_uri.to_s}'>#{display_src}</a><p>"
|
||||||
|
rescue URI::InvalidURIError
|
||||||
|
# If the URL is weird, remove it
|
||||||
|
i.remove
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user