2018-10-11 17:37:39 +02:00
|
|
|
defmodule Mobilizon.Slug do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
|
|
|
Common functions for slug generation
|
|
|
|
"""
|
|
|
|
def increment_slug(slug) do
|
|
|
|
case List.pop_at(String.split(slug, "-"), -1) do
|
|
|
|
{nil, _} ->
|
|
|
|
slug
|
2018-07-27 10:45:35 +02:00
|
|
|
|
2018-01-14 17:56:50 +01:00
|
|
|
{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
|