This commit is contained in:
BoHung Chiu 2021-04-01 18:00:07 +08:00
parent 473b3bf02e
commit 39fa7aed06
1 changed files with 6 additions and 0 deletions

View File

@ -52,8 +52,14 @@ class WebResourcesController < ApplicationController
elsif link.link_open == "local"
target = "_self"
end
doc = Nokogiri::HTML(link.title.to_s)
text = doc.css("body")[0].text rescue ""
if text.blank? && doc.css("img").count != 0
text = doc.css("img").map{|img| img.attr("alt") rescue ""}.select{|t| t.present?}.first
end
{
"title" => link.title,
"title_text" => text,
"context" => link.context,
"statuses" => statuses,
"link_to_show" => link.url,