Skip to content

Commit 6f06017

Browse files
committed
Merge branch 'safolu'
2 parents 79597fa + fd5fe74 commit 6f06017

File tree

4 files changed

+96
-19
lines changed

4 files changed

+96
-19
lines changed

app/controllers/terms_controller.rb

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ def index; end
55

66
def show
77
@terms = Term.includes(:stem, descriptions: %i[examples synonyms]).where(name: params[:id]).order(:dictionary_id)
8+
return redirect_back(fallback_location: "/") if @terms.empty?
89
end
910
end

app/views/terms/show.html.erb

+91-19
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@
1212
<div class="bg-<%= term.dictionary.color %>-600 text-white p-2"><%= term.dictionary.name %></div>
1313
<% if term.descriptions.present? %>
1414
<div>
15-
<span class="text-gray-500">
16-
<% stem = term.stem %>
17-
<% if stem.present? %>
15+
<% if term.repetition.present? %>
16+
<span class="bg-rose-600 text-white p-0.5">
17+
[疊 <%= term.repetition %>]
18+
</span>
19+
<% end %>
20+
21+
<% stem = term.stem %>
22+
<% if stem.present? %>
23+
<span class="text-gray-500">
1824
(詞幹: <%= link_to(stem.name, term_path(stem.name)) %>
19-
<% end %>
20-
</span>
25+
</span>
26+
<% end %>
27+
2128
<% if term.audio.present? %>
2229
<button>
2330
<i class="fas fa-volume-up" onclick="document.getElementById('audio-<%= term.audio_id %>').play()"></i>
@@ -36,25 +43,90 @@
3643
<ul class="list-disc list-inside space-y-1">
3744
<% description.examples.each do |example| %>
3845
<li>
39-
<% content = example.content.gsub("\xEF\xBF\xB9", "") %>
40-
<% parts = content.split(/[`~]/).reject(&:empty?) %>
41-
<%== parts.each_with_index.map do |part, i|
42-
if part.match(/^[\p{Alnum}]+$/) && part != params[:id]
43-
term_path = if i == 0
44-
"/terms/#{part.downcase}"
45-
else
46-
"/terms/#{part}"
47-
end
46+
<%
47+
term_html = ''
48+
parts = example.content.split(/[`~]/).reject(&:empty?)
49+
parts.each_with_index do |part, i|
50+
if part.match(/^[\p{Alnum}]+$/) && part != params[:id]
51+
term_path = if i == 0
52+
"/terms/#{part.downcase}"
53+
else
54+
"/terms/#{part}"
55+
end
4856

49-
"<a href=\"#{term_path}\" class=\"border-b border-gray-300 text-gray-800 hover:bg-gray-300 focus:bg-gray-300 hover:text-[#0070a3] focus:text-[#0070a3] focus:outline focus:outline-1 focus:outline-[#69d2fc]\">#{part}</a>"
50-
else
51-
part
52-
end
53-
end.join %>
57+
term_html += "<a href=\"#{term_path}\" class=\"border-b border-gray-300 text-gray-800 hover:bg-gray-300 focus:bg-gray-300 hover:text-[#0070a3] focus:text-[#0070a3] focus:outline focus:outline-1 focus:outline-[#69d2fc]\">#{part}</a>"
58+
else
59+
term_html += part
60+
end
61+
end
62+
%>
63+
<%= term_html.html_safe %>
5464
</li>
5565
<% end %>
5666
</ul>
5767
<% end %>
68+
69+
<% if description.synonyms.alts.present? %>
70+
<p>
71+
<span class="bg-stone-500 text-white text-sm p-0.5 ml-5 mr-2">
72+
73+
</span>
74+
<% alt_array = [] %>
75+
<% description.synonyms.alts.each do |synonym_alt| %>
76+
<%
77+
alt_html = ''
78+
parts = synonym_alt.content.split(/[`~]/).reject(&:empty?)
79+
parts.each_with_index do |part, i|
80+
if part.match(/^[\p{Alnum}]+$/) && part != params[:id]
81+
term_path = if i == 0
82+
"/terms/#{part.downcase}"
83+
else
84+
"/terms/#{part}"
85+
end
86+
87+
alt_html += "<a href=\"#{term_path}\" class=\"border-b border-gray-300 text-gray-800 hover:bg-gray-300 focus:bg-gray-300 hover:text-[#0070a3] focus:text-[#0070a3] focus:outline focus:outline-1 focus:outline-[#69d2fc]\">#{part}</a>"
88+
else
89+
alt_html += part
90+
end
91+
end
92+
93+
alt_array << alt_html
94+
%>
95+
<% end %>
96+
<%= alt_array.join("、").html_safe %>
97+
</p>
98+
<% end %>
99+
100+
<% if description.synonyms.refs.present? %>
101+
<p>
102+
<span class="bg-stone-500 text-white text-sm p-0.5 ml-5 mr-2">
103+
參見
104+
</span>
105+
<% ref_array = [] %>
106+
<% description.synonyms.refs.each do |synonym_ref| %>
107+
<%
108+
ref_html = ''
109+
parts = synonym_ref.content.split(/[`~]/).reject(&:empty?)
110+
parts.each_with_index do |part, i|
111+
if part.match(/^[\p{Alnum}]+$/) && part != params[:id]
112+
term_path = if i == 0
113+
"/terms/#{part.downcase}"
114+
else
115+
"/terms/#{part}"
116+
end
117+
118+
ref_html += "<a href=\"#{term_path}\" class=\"border-b border-gray-300 text-gray-800 hover:bg-gray-300 focus:bg-gray-300 hover:text-[#0070a3] focus:text-[#0070a3] focus:outline focus:outline-1 focus:outline-[#69d2fc]\">#{part}</a>"
119+
else
120+
ref_html += part
121+
end
122+
end
123+
124+
ref_array << ref_html
125+
%>
126+
<% end %>
127+
<%= ref_array.join("、").html_safe %>
128+
</p>
129+
<% end %>
58130
</li>
59131
<% end %>
60132
<!-- <li>捉獵物,獵獲的(獵物)。

lib/tasks/import.rake

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ namespace :import do
4949
next if json_object["h"].empty?
5050

5151
term = dictionary.terms.find_or_create_by(name: clean(text: json_object["t"]))
52+
if json_object["tag"].present?
53+
repetition = json_object["tag"].match(/[疊 ](\d)/)[1]
54+
term.update(repetition: repetition)
55+
end
5256
if json_object["stem"].present?
5357
stem = Stem.find_or_create_by(name: json_object["stem"])
5458
term.update(stem_id: stem.id)

storage/amis-moedict.sqlite3

388 KB
Binary file not shown.

0 commit comments

Comments
 (0)