PhoenixKit.Utils.Slug (phoenix_kit v1.7.63)

Copy Markdown View Source

Helpers for generating consistent, URL-friendly slugs across PhoenixKit.

Provides functions to slugify arbitrary text, enforce separator rules, and ensure uniqueness by delegating existence checks via callback.

Summary

Functions

Ensures the provided slug is unique by calling exists_fun.

Converts the given text into a slug.

Functions

ensure_unique(slug, exists_fun)

@spec ensure_unique(String.t(), (String.t() -> boolean())) :: String.t()

Ensures the provided slug is unique by calling exists_fun.

exists_fun should return truthy when the slug is already taken.

slugify(text, opts \\ [])

@spec slugify(
  String.t() | nil,
  keyword()
) :: String.t()

Converts the given text into a slug.

Options:

  • :separator - character used between words (defaults to "-")

Returns an empty string when the input is blank or cannot be converted.