Skip to content

Commit e9a0508

Browse files
committed
add slugify helper
1 parent e4538de commit e9a0508

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/algora/shared/util.ex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,15 @@ defmodule Algora.Util do
292292
|> DateTime.shift_zone!("Europe/Athens", Tzdata.TimeZoneDatabase)
293293
|> Calendar.strftime("%Y-%m-%d %H:%M:%S")
294294
end
295+
296+
def slugify(text) when is_binary(text) do
297+
text
298+
|> String.downcase()
299+
|> String.trim()
300+
|> String.normalize(:nfd)
301+
|> String.replace(~r/[^a-z0-9\s-]/u, " ")
302+
|> String.replace(~r/[\s-]+/, "-", global: true)
303+
end
304+
305+
def slugify(_), do: ""
295306
end

0 commit comments

Comments
 (0)