View Source Franklin.Articles.Slugs (Franklin v0.1.0)

Provides functions for generating the blog's slug format.

Link to this section Summary

Functions

Returns a URL safe slug for the given title and published_at DateTime value.

Link to this section Types

@type failure_reason() :: :empty_title | :title_slugification_failed

Link to this section Functions

Link to this function

generate_slug_for_title(title, published_at)

View Source
@spec generate_slug_for_title(String.t(), DateTime.t()) ::
  {:ok, String.t()} | {:error, failure_reason()}

Returns a URL safe slug for the given title and published_at DateTime value.

examples

Examples

iex> Slugs.generate_slug_for_title("Hello World!", ~U[2022-01-12 00:01:00.00Z])
{:ok, "2022/1/hello-world/"}

iex> Slugs.generate_slug_for_title("", ~U[2022-01-12 00:01:00.00Z])
{:error, :empty_title}

iex> Slugs.generate_slug_for_title("🤷‍♂️", ~U[2022-01-12 00:01:00.00Z])
{:error, :title_slugification_failed}