Fix relative links in the announcement contents.

This commit is contained in:
邱博亞 2023-12-30 11:15:42 +08:00
parent 60f18fef2b
commit 7c6f51f7ca
1 changed files with 18 additions and 0 deletions

View File

@ -182,6 +182,24 @@ class SiteFeedAnnc
tmp["bulletin_files"] = files
tmp["title"] = tmp["title_translations"][locale]
tmp["subtitle"] = tmp["subtitle_translations"][locale]
if tmp["text_translations"].present?
tmp["text_translations"].each do |l, text|
doc = Nokogiri::HTML.fragment(text)
doc.css('[src]').each do |src_el|
src = (src_el.attributes["src"].value rescue "")
if src.present? && src.match(/^\/[^\/]+/)
src_el.attributes["src"].value = self.remote_site_url + src
end
end
doc.css('[href]').each do |href_el|
href = href_el.attribute('href').value rescue ""
if href.present? && href.match(/^\/[^\/]+/)
href.attributes["href"].value = self.remote_site_url + href
end
end
tmp["text_translations"][l] = doc.to_html
end
end
tmp["source-site-link"] = tmp["source-site"]
tmp["source-site"] = "<a href=\"#{tmp["source-site"]}\" target=\"_blank\" class=\"feed-source\">#{tmp["source-site-title"]}</a>"
tmp["link_to_show"] = !tmp["external_link"].blank? ? tmp["external_link"] : nil