Skip to content
A Slugger for elixir.
Branch: master
Clone or download
Latest commit bcc27fa Jun 12, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
bench Change greek characters Mar 20, 2017
config Change greek characters Mar 20, 2017
lib Handling 's possessives. Fixes #31 Jun 12, 2018
.gitignore Change greek characters Mar 20, 2017
.travis.yml Using a simpler travis build matrix. Jun 12, 2018
LICENSE Change greek characters Mar 20, 2017 Raised version to 0.3 Jun 12, 2018
mix.exs Raised version to 0.3 Jun 12, 2018


Build Status

This package provides a library and a protocol to create slugs for given strings.

By default, a slug will be containing only chars A-Za-z0-9 and the default seperator -.

Want to use this library with Ecto? Have a look at sobolevn/ecto_autoslug_field.


Add slugger to your list of dependencies in mix.exs:

def deps do
    {:slugger, "~> 0.3"},


The following options can be set in your config.exs and will be used at next compile!

# Char used as separator between words.
config :slugger, separator_char: ?-

# Path to the file containing replacements.
config :slugger, replacement_file: "lib/replacements.exs"


Using the library is straightforward, check out a few examples:

iex(1)> Slugger.slugify " A b C "

iex(2)> Slugger.slugify_downcase " A b C "

iex(3)> Slugger.slugify "A cool title of a blog post"

iex(4)> Slugger.slugify_downcase("Kluski Śląskie @ Jalapeño Bilingüe")

iex(5)> Slugger.slugify "Wikipedia Style", ?_

iex(6)> Slugger.truncate_slug "A-to-long-slug-that-should-be-truncated", 16


Next to the library, a protocol is provided to ease creating slugs for own data structures. By default, the protocol will try to run Slugger.slugify(Kernel.to_string(your_data)), so if your_data implements String.Chars, the returned string will be slugified. If you want to provide your own way to create a slug, check out the following example:

iex(10)> defmodule User do
...(10)>   defstruct name: "Julius Beckmann"
...(10)> end

iex(11)> defimpl Slugify, for: User do   
...(11)>   def slugify(user), do: Slugger.slugify(
...(11)> end

iex(12)> Slugify.slugify %User{}                          


Special chars like äöüéáÁÉ will be replaced by rules given in the file lib/replacements.exs.

Copy that file if you need have own replacement rules, change the config value and recompile.

You can’t perform that action at this time.