From 39fa7aed063a8aec0d4e9dc0f7b4b67ab92ba712 Mon Sep 17 00:00:00 2001 From: Bohung Date: Thu, 1 Apr 2021 18:00:07 +0800 Subject: [PATCH] Fix bug. --- app/controllers/web_resources_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/web_resources_controller.rb b/app/controllers/web_resources_controller.rb index ce8cd01..a21bbdd 100644 --- a/app/controllers/web_resources_controller.rb +++ b/app/controllers/web_resources_controller.rb @@ -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,