From fb42f4157c92eb35f54dd65425f1c7e6aca07389 Mon Sep 17 00:00:00 2001
From: Marcin Chrzanowski
Date: Thu, 26 Jan 2023 12:15:59 +0100
Subject: Sort by Polish alphabet
---
lib/util.rb | 23 +++++++++++++++++++++++
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 @@
--
cgit v1.2.3