fix error

This commit is contained in:
BOYA,CHIU 2021-08-12 11:25:48 +08:00
parent 800ab40c94
commit 188793747b
5 changed files with 30 additions and 22 deletions

View File

@ -22,11 +22,13 @@ class WebResourcesController < ApplicationController
end
desc = link.image_description
desc = (desc.blank? ? "web resource image" : desc)
display_image = link.image.thumb.url.blank? 'style="display: none;"' : ''
{
"title" => link.title,
"title_text" => text,
"img_src" => link.image.thumb.url || "/assets/announcement-default.jpg",
"img_description" => desc,
"display_image" => display_image,
"context" => nl2br(link.context.to_s),
"statuses" => statuses,
"category" => link.category.title,
@ -52,24 +54,30 @@ class WebResourcesController < ApplicationController
"status-class" => "status-#{status['classname']}"
}
end
if link.link_open == "new_window"
target = "_blank"
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" => nl2br(link.context.to_s),
"statuses" => statuses,
"link_to_show" => link.url,
"target" => target
}
if link.link_open == "new_window"
target = "_blank"
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
desc = link.image_description
desc = (desc.blank? ? "web resource image" : desc)
display_image = link.image.thumb.url.blank? 'style="display: none;"' : ''
{
"title" => link.title,
"title_text" => text,
"img_src" => link.image.thumb.url || "/assets/announcement-default.jpg",
"img_description" => desc,
"display_image" => display_image,
"context" => nl2br(link.context.to_s),
"statuses" => statuses,
"link_to_show" => link.url,
"target" => target
}
end
{
"web_link" => web_link,

View File

@ -4,7 +4,7 @@
</h3>
<ul class="list-unstyled" data-level="0" data-list="web_link">
<li class="widget-content">
<div class="link-img-wrap">
<div class="link-img-wrap" {{display_image}}>
<img src="{{img_src}}" alt="{{img_description}}" title="{{img_description}}">
</div>
<a class="widget-content-title" href="{{link_to_show}}" target="_blank" title="{{title_text}}">{{title}}</a>

View File

@ -4,7 +4,7 @@
</h3>
<ul class="list-unstyled" data-level="0" data-list="web_link">
<li class="widget-content widget-content-horizontal">
<div class="link-img-wrap">
<div class="link-img-wrap" {{display_image}}>
<img src="{{img_src}}" alt="{{img_description}}" title="{{img_description}}">
</div>
<a class="widget-content-title" href="{{link_to_show}}" target="_blank" title="{{title_text}}">{{title}}</a>

View File

@ -5,7 +5,7 @@
<ul class="list-unstyled" data-list="web_link" data-level="0">
<li class="index-content">
<a class="index-content-title" href="{{link_to_show}}" target="_blank" title="{{title_text}}">
<div class="link-img-wrap">
<div class="link-img-wrap" {{display_image}}>
<img src="{{img_src}}" alt="{{img_description}}" title="{{img_description}}">
</div>
<h4>

View File

@ -5,7 +5,7 @@
<ul class="list-unstyled" data-list="web_link" data-level="0">
<li class="index-content col-md-4 col-sm-4">
<a class="index-content-title" href="{{link_to_show}}" target="_blank" title="{{title_text}}">
<div class="link-img-wrap">
<div class="link-img-wrap" {{display_image}}>
<img src="{{img_src}}" alt="{{img_description}}" title="{{img_description}}">
</div>
<h4>