You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/views/shixun_lists/index.json.jbuilder

27 lines
991 B

5 years ago
json.shixuns_count @results.total_count
json.shixun_list do
json.array! @results.with_highlights(multiple: true) do |obj, highlights|
json.merge! obj.to_searchable_json
json.challenge_names obj.challenges.pluck(:subject)
# 去除开头标点符号
reg = /^[,。?:;‘’!“”—……、]/
# 附件的替换
5 years ago
atta_reg = /!\[.*]\(\/api\/attachments\/\d+\)/
5 years ago
5 years ago
highlights[:description]&.first&.sub!(reg, '')
5 years ago
highlights[:description]&.map{|des| des.gsub(atta_reg, '')}
5 years ago
highlights[:content]&.first&.sub!(reg, '')
5 years ago
highlights[:content]&.map{|des| des.gsub(atta_reg, '')}
5 years ago
json.title highlights.delete(:name)&.join('...') || obj.searchable_title
5 years ago
json.description highlights[:description]&.join('...') || Util.extract_content(obj.description)[0..300]&.gsub(atta_reg, '')
5 years ago
json.content highlights
json.level level_to_s(obj.trainee)
json.subjects obj.subjects.uniq do |subject|
json.(subject, :id, :name)
end
end
end