mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-11 01:44:34 +08:00
02d3e03f75
The URLs in notification emails didn't get server URL prepended, so users could not click on them.
28 lines
762 B
Ruby
28 lines
762 B
Ruby
module MailerHelper
|
|
# This method receives a HTML (as String), and
|
|
# prepends the server URL in front of URLs/paths
|
|
def prepend_server_url_to_links(html)
|
|
html_doc = Nokogiri::HTML.fragment(html)
|
|
links = html_doc.search('a')
|
|
links.each do |link|
|
|
href = link.attribute('href')
|
|
href.value = prepend_server_url(href.value) if href.present?
|
|
end
|
|
html_doc.to_html
|
|
end
|
|
|
|
private
|
|
|
|
def prepend_server_url(href)
|
|
return href if href.start_with? ENV['MAIL_SERVER_URL']
|
|
|
|
new_href = ''
|
|
unless ENV['MAIL_SERVER_URL'].start_with?('http://', 'https://')
|
|
new_href += 'http://'
|
|
end
|
|
new_href += ENV['MAIL_SERVER_URL']
|
|
new_href += ((href.start_with? '/') ? '' : '/')
|
|
new_href += href
|
|
new_href
|
|
end
|
|
end
|