From 6c7d7ad339e9064a1dba318d13f4b4953a97ebb6 Mon Sep 17 00:00:00 2001 From: BoHung Chiu Date: Tue, 3 Oct 2023 00:16:54 +0800 Subject: [PATCH] Fix author text bug. --- app/helpers/admin/personal_books_helper.rb | 37 +++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/app/helpers/admin/personal_books_helper.rb b/app/helpers/admin/personal_books_helper.rb index 83c6c71..9398428 100644 --- a/app/helpers/admin/personal_books_helper.rb +++ b/app/helpers/admin/personal_books_helper.rb @@ -3,27 +3,42 @@ module Admin::PersonalBooksHelper authors_text = Nokogiri::HTML(book.authors.to_s).text split_text = authors_text.match(/[、,,\/]/) split_text = split_text.nil? ? '/' : split_text[0] - full_authors_names = get_member(book).collect(&:name) if authors_text.present? - authors_names = authors_text.split(split_text).select{|a| !(full_authors_names.include?(a.strip()))} - full_authors_names += authors_names + authors_names = authors_text.split(split_text) + else + authors_names = [] end + full_authors_names = get_member(book).collect do |member| + member_name = member.name + idx = authors_names.index{|a| a.chomp('*') == member_name} + if idx + member_name = authors_names[idx] + authors_names[idx] = nil + end + member_name + end + full_authors_names += authors_names.compact full_authors_names.join(split_text) end def get_authors_show(book) authors_text = Nokogiri::HTML(book.authors.to_s).text split_text = authors_text.match(/[、,,\/]/) split_text = split_text.nil? ? '/' : split_text[0] - full_authors_names = [] - full_authors = get_member(book).collect{|member| - member_name = member.name - full_authors_names << member_name - "#{member_name}" - } if authors_text.present? - authors_names = authors_text.split(split_text).select{|a| !(full_authors_names.include?(a.strip()))} - full_authors += authors_names + authors_names = authors_text.split(split_text) + else + authors_names = [] end + full_authors = get_member(book).collect do |member| + member_name = member.name + idx = authors_names.index{|a| a.chomp('*') == member_name} + if idx + member_name = authors_names[idx] + authors_names[idx] = nil + end + "#{member_name}" + end + full_authors += authors_names.compact full_authors.join(split_text) end def get_member(book)