Fix local url in email.

This commit is contained in:
邱博亞 2024-09-11 08:38:00 +08:00
parent cfa596a3e7
commit 2b301b0c38
1 changed files with 33 additions and 4 deletions

View File

@ -163,12 +163,41 @@
</style> </style>
</head> </head>
<% <%
def fix_local_url(siteurl, contents)
doc = Nokogiri::HTML.fragment(contents, encoding = 'UTF-8')
doc.css('img[src], script[src]').each do |src_tag|
src = src_tag.attribute('src').value
next if src.blank?
if src.match(/^\/[^\/]+/)
src_tag.attribute('src').value = siteurl + src
end
end
doc.css('a[href], link[href]').each do |link_tag|
href = link_tag.attribute('href').value
next if href.blank?
if href.match(/^\/[^\/]+/)
link_tag.attribute('href').value = siteurl + href
end
end
doc.to_html
end
have_papaers = papers_data.present? have_papaers = papers_data.present?
if paper.image.present? if paper.image.present?
img_src = siteurl + "/" + paper.image.url img_src = siteurl + paper.image.url
else else
img_src = nil img_src = nil
end end
if paper.description.present?
paper_description = fix_local_url(siteurl, paper.description).html_safe
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">
@ -192,9 +221,9 @@
<%= t('e_paper.description') %> <%= t('e_paper.description') %>
</span> </span>
<span> <span>
<%= paper.description.html_safe %> <%= paper_description %>
<br> <br>
<%= paper.content.html_safe %> <%= paper_content %>
</span> </span>
</div> </div>
</div> </div>
@ -230,7 +259,7 @@
</div> </div>
<% end %> <% end %>
<div class="ep-info-description"> <div class="ep-info-description">
<%= paper.content.html_safe %> <%= paper_content %>
</div> </div>
</div> </div>
<% end %> <% end %>