From 142126322e7531a249d0e367a67cfeeeff399ca3 Mon Sep 17 00:00:00 2001 From: Bohung Date: Thu, 20 May 2021 11:25:16 +0800 Subject: [PATCH] Update widgets. --- app/controllers/galleries_controller.rb | 6 ++++-- modules/gallery/_gallery_widget1.html.erb | 24 +++++++++++++---------- modules/gallery/_gallery_widget2.html.erb | 21 +++++++++++--------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/app/controllers/galleries_controller.rb b/app/controllers/galleries_controller.rb index 271c0ff..ba57a8d 100644 --- a/app/controllers/galleries_controller.rb +++ b/app/controllers/galleries_controller.rb @@ -149,13 +149,14 @@ class GalleriesController < ApplicationController album_color_map = AlbumColor.where(:album_id.in=> albums.map{|v| v.id}).pluck(:album_id,:color,:album_card_background_color,:album_card_text_color).map{|v| [v[0],v[1..-1]]}.to_h galleries = albums.collect.with_index do |a,i| doc = Nokogiri::HTML(a.description.to_s) - alt_text = doc.text.empty? ? 'gallery image' : doc.text + alt_text = doc.text.empty? ? 'gallery image' : doc.text.strip colors = album_color_map[a.id] thumb_src = a.cover_path || "/assets/gallery/default.jpg" cover_image = AlbumImage.find(a.cover) rescue a.album_images.first image_description = a.description image_short_description = a.name { + "link_text" => a.name, "album-name" => a.name, "album-description" => a.description, "alt_title" => alt_text, @@ -187,8 +188,9 @@ class GalleriesController < ApplicationController images = AlbumImage.where({album_id:{"$in"=>album_ids}}).desc(:id).limit(counts *5).sample(counts) images = images.each_with_index.collect do |a,i| colors = album_color_map[a.album_id] - alt_text = (a.description.nil? || a.description == "" ? "gallery image" : Nokogiri::HTML(a.description).text()) + alt_text = (a.description.blank? ? "gallery image" : Nokogiri::HTML(a.description).text().strip) { + "link_text" => "", "link_to_show" => OrbitHelper.widget_more_url + "/" + a.album.to_param + "#" + a.id.to_s, "alt_title" => alt_text, "src" => a.file.url, diff --git a/modules/gallery/_gallery_widget1.html.erb b/modules/gallery/_gallery_widget1.html.erb index 0de376b..3f8bb4a 100644 --- a/modules/gallery/_gallery_widget1.html.erb +++ b/modules/gallery/_gallery_widget1.html.erb @@ -5,21 +5,25 @@
- - {{alt_title}} - +
diff --git a/modules/gallery/_gallery_widget2.html.erb b/modules/gallery/_gallery_widget2.html.erb index ccfb46b..1778e3e 100644 --- a/modules/gallery/_gallery_widget2.html.erb +++ b/modules/gallery/_gallery_widget2.html.erb @@ -3,14 +3,17 @@ {{widget-title}}
- - {{alt_title}} - +
\ No newline at end of file