diff --git a/app/api/v2/terms_api.rb b/app/api/v2/terms_api.rb index 9e9e24a..22643f5 100644 --- a/app/api/v2/terms_api.rb +++ b/app/api/v2/terms_api.rb @@ -24,7 +24,7 @@ class TermsAPI < Base term_hash[:stem] = term.stem.name if term.stem.present? term_hash[:lower_name] = term.lower_name if term.name != term.lower_name term_hash[:repetition] = term.repetition if term.repetition.present? - term_hash[:audio] = term.audio if term.audio.present? + term_hash[:audio] = term.audio_url term.descriptions.each do |description| description_hash = { @@ -33,7 +33,9 @@ class TermsAPI < Base description_hash[:type] = description.description_type if description.description_type.present? description_hash[:glossary_serial] = description.glossary_serial if description.glossary_serial.present? description_hash[:glossary_level] = description.glossary_level if description.glossary_level.present? - description_hash[:image] = description.image if description.image.present? + description_hash[:image1] = description.image1_url + description_hash[:image2] = description.image2_url + description_hash[:image3] = description.image3_url description.examples.each do |example| example_hash = { content: example.content } diff --git a/app/models/description.rb b/app/models/description.rb index 6458631..ea058e2 100644 --- a/app/models/description.rb +++ b/app/models/description.rb @@ -16,7 +16,8 @@ # class Description < ApplicationRecord - store :customized_text, accessors: %i[image] + store :customized_text, accessors: %i[image1 image1_alt image2 image2_alt + image3 image3_alt focus category] belongs_to :term has_many :examples, dependent: :destroy @@ -28,6 +29,30 @@ def self.ransackable_attributes(auth_object = nil) %w[content] end + def image1_url + "https://g0v.github.io/amis-moedict-static#{image1}" if image1.present? + end + + def image2_url + "https://g0v.github.io/amis-moedict-static#{image2}" if image2.present? + end + + def image3_url + "https://g0v.github.io/amis-moedict-static#{image3}" if image3.present? + end + + def image1_text + image1_alt.present? ? image1_alt : content + end + + def image2_text + image2_alt.present? ? image2_alt : content + end + + def image3_text + image3_alt.present? ? image3_alt : content + end + private def clean_content diff --git a/app/models/term.rb b/app/models/term.rb index 3661272..8d626f1 100644 --- a/app/models/term.rb +++ b/app/models/term.rb @@ -49,6 +49,10 @@ def audio_id audio.match(%r{/(\d+)/(\d+_\d+)\.wav$})[1..2].join("-") end + def audio_url + "https://g0v.github.io/amis-moedict-static#{audio}" if audio.present? + end + private def clean_name_and_set_lower_name diff --git a/app/views/terms/show.html.erb b/app/views/terms/show.html.erb index 9f932bc..d5a6f10 100644 --- a/app/views/terms/show.html.erb +++ b/app/views/terms/show.html.erb @@ -52,7 +52,7 @@ - <%= audio_tag term.audio, id: "audio-#{term.audio_id}" %> + <%= audio_tag term.audio_url, id: "audio-#{term.audio_id}" %> <% end %>