slugy v1.0.0 Slugy.Slug protocol
A protocol that builds a string to converts into a slug
This protocol is used by Slugy.slugify/2. For example, when you
want a custom slug for a Post, composed by the title
and the
published_at
fields:
"how-to-use-slugy-2018-10-10"
Suppose you have a Post module with the following fields:
defmodule Post do
schema "posts" do
field :title, :string
field :body, :text
field :published_at, :datetime
end
end
You need to implement the Slugy.Slug protocol to achieve that:
defimpl Slugy.Slug, for: Post do
def to_slug(%{title: title, published_at: published_at}) do
"#{title} #{published_at}"
end
end
Slugy internally uses this string to build your custom slug.
Link to this section Summary
Link to this section Types
Link to this section Functions
Link to this function
to_slug(struct)