diff options
-rw-r--r-- | lib/util.rb | 23 | ||||
-rw-r--r-- | src/index.html.erb | 4 |
2 files changed, 25 insertions, 2 deletions
diff --git a/lib/util.rb b/lib/util.rb index 873b6f9..5509aad 100644 --- a/lib/util.rb +++ b/lib/util.rb @@ -87,3 +87,26 @@ end def path_to asset_id P.path_to asset_id end + +def normalize title + title.downcase.gsub /[[:punct:]]|[[:space:]]/, '' +end + +def indexify title + alphabet = "aąbcćdeęfghijklłmnńoóprsśtuwyzźż".chars + normalized = normalize title + normalized.chars.map do |c| + index = alphabet.find_index c + if index.nil? + raise "Letter not in alphabet: #{c}" + end + + index + end +end + +def polish_compare a, b + indices_a = indexify a + indices_b = indexify b + indices_a <=> indices_b +end diff --git a/src/index.html.erb b/src/index.html.erb index ca40664..f6be207 100644 --- a/src/index.html.erb +++ b/src/index.html.erb @@ -7,9 +7,9 @@ </p> <ul id='songs'> -<%- songs.keys.sort.each do |song_id| -%> +<%- songs.values.sort { |a, b| polish_compare a.title, b.title }.each do |song| -%> <li> - <a href='<%= path_to (song_html song_id) %>'><%= songs[song_id].title %></a> + <a href='<%= path_to (song_html song.id) %>'><%= song.title %></a> </li> <%- end -%> </ul> |