Fix local url in email.

This commit is contained in:
邱博亞 2024-09-11 13:07:40 +08:00
parent 2b301b0c38
commit a44c4667d4
1 changed files with 9 additions and 13 deletions

View File

@ -160,10 +160,14 @@
width: 80%; width: 80%;
margin: 10px; margin: 10px;
} }
.epaper-show img {
max-width: 100%;
}
</style> </style>
</head> </head>
<% <%
def fix_local_url(siteurl, contents) def fix_local_url(siteurl, contents)
return nil if contents.blank?
doc = Nokogiri::HTML.fragment(contents, encoding = 'UTF-8') doc = Nokogiri::HTML.fragment(contents, encoding = 'UTF-8')
doc.css('img[src], script[src]').each do |src_tag| doc.css('img[src], script[src]').each do |src_tag|
src = src_tag.attribute('src').value src = src_tag.attribute('src').value
@ -179,7 +183,7 @@
link_tag.attribute('href').value = siteurl + href link_tag.attribute('href').value = siteurl + href
end end
end end
doc.to_html doc.to_html.html_safe
end end
have_papaers = papers_data.present? have_papaers = papers_data.present?
@ -188,16 +192,8 @@
else else
img_src = nil img_src = nil
end end
if paper.description.present? paper_description = fix_local_url(siteurl, paper.description)
paper_description = fix_local_url(siteurl, paper.description).html_safe paper_content = fix_local_url(siteurl, paper.content)
else
paper_description = nil
end
if paper.content.present?
paper_content = fix_local_url(siteurl, paper.content).html_safe
else
paper_content = nil
end
%> %>
<body> <body>
<div class="epaper-show"> <div class="epaper-show">
@ -236,10 +232,10 @@
<div class="ep-content-item"> <div class="ep-content-item">
<a class="ep-content-title" href="<%= page + "/" + topic.to_param %>" target="_blank"><%= topic.title %></a> <a class="ep-content-title" href="<%= page + "/" + topic.to_param %>" target="_blank"><%= topic.title %></a>
<div class="ep-img" style="width: 40%; float:left;"> <div class="ep-img" style="width: 40%; float:left;">
<img src="<%= (siteurl + "/" + topic.image.thumb.url rescue nil) %>" style="width: 100%;"> <img src="<%= (siteurl + topic.image.thumb.url rescue nil) %>" style="width: 100%;">
</div> </div>
<div class="ep-con" style="width: 58%; float: right;"> <div class="ep-con" style="width: 58%; float: right;">
<%= topic.description %> <%= fix_local_url(siteurl, topic.description) %>
<a class="ep-content-more" href="<%= page + "/" + topic.to_param %>" target="_blank">more</a> <a class="ep-content-more" href="<%= page + "/" + topic.to_param %>" target="_blank">more</a>
</div> </div>
</div> </div>