Fermo Slugger v0.8.4 FermoSlugger View Source

Create slugs from id and text

Link to this section Summary

Functions

Returns a slug, combining id and title.

Link to this section Functions

Link to this function

slug(id, title, options \\ [])

View Source

Returns a slug, combining id and title.

Example

iex> FermoSlugger.slug(123, "ciao")
"123-ciao"

Normalization

Punctuation is replaced by '-':

iex> FermoSlugger.slug(123, "S&P")
"123-s-p"

The text is downcased:

iex> FermoSlugger.slug(123, "AAAAA")
"123-aaaaa"

Non-Latin characters are transliterated:

iex> FermoSlugger.slug(123, "andò")
"123-ando"

Separator characters are converted to '-':

iex> FermoSlugger.slug(123, "R&R")
"123-r-r"

Leading '-' is removed:

iex> FermoSlugger.slug(123, "-1")
"123-1"

Trailing '-' is removed:

iex> FermoSlugger.slug(123, "1-")
"123-1"

The text part is capped at 51 characters:

iex> FermoSlugger.slug(123, String.duplicate("a", 100))
"123-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"