mirror of
https://framagit.org/framasoft/mobilizon.git
synced 2024-12-24 00:43:02 +00:00
17 lines
417 B
Elixir
17 lines
417 B
Elixir
|
defmodule Eventos.Slug do
|
||
|
@moduledoc """
|
||
|
Common functions for slug generation
|
||
|
"""
|
||
|
def increment_slug(slug) do
|
||
|
case List.pop_at(String.split(slug, "-"), -1) do
|
||
|
{nil, _} ->
|
||
|
slug
|
||
|
{suffix, slug_parts} ->
|
||
|
case Integer.parse(suffix) do
|
||
|
{id, _} -> Enum.join(slug_parts, "-") <> "-" <> Integer.to_string(id + 1)
|
||
|
:error -> slug <> "-1"
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|