PhoenixKit.Modules.Publishing.SlugHelpers (phoenix_kit v1.7.71)

Copy Markdown View Source

Slug validation and generation for the Publishing module.

Handles slug format validation, uniqueness checking (DB-only), URL slug validation for per-language slugs, and slug generation.

Summary

Functions

Clears custom url_slugs that conflict with a given directory slug.

Clears a specific url_slug from all translations of a single post (DB-only).

Generates a unique slug based on title and optional preferred slug.

Checks if a slug already exists within the given publishing group (DB-only).

Validates whether the given string is a slug and not a reserved language code.

Validates whether the given string is a valid slug format and not a reserved language code.

Validates a per-language URL slug for uniqueness within a group+language combination.

Functions

clear_conflicting_url_slugs(group_slug, directory_slug)

@spec clear_conflicting_url_slugs(String.t(), String.t()) :: [
  {String.t(), String.t()}
]

Clears custom url_slugs that conflict with a given directory slug.

clear_url_slug_from_post(group_slug, post_slug, url_slug_to_clear)

@spec clear_url_slug_from_post(String.t(), String.t(), String.t()) :: [String.t()]

Clears a specific url_slug from all translations of a single post (DB-only).

generate_unique_slug(group_slug, title, preferred_slug \\ nil, opts \\ [])

@spec generate_unique_slug(String.t(), String.t(), String.t() | nil, keyword()) ::
  {:ok, String.t()} | {:error, :invalid_format | :reserved_language_code}

Generates a unique slug based on title and optional preferred slug.

slug_exists?(group_slug, post_slug)

@spec slug_exists?(String.t(), String.t()) :: boolean()

Checks if a slug already exists within the given publishing group (DB-only).

valid_slug?(slug)

@spec valid_slug?(String.t()) :: boolean()

Validates whether the given string is a slug and not a reserved language code.

validate_slug(slug)

@spec validate_slug(String.t()) ::
  {:ok, String.t()} | {:error, :invalid_format | :reserved_language_code}

Validates whether the given string is a valid slug format and not a reserved language code.

validate_url_slug(group_slug, url_slug, language, exclude_post_slug \\ nil)

@spec validate_url_slug(String.t(), String.t(), String.t(), String.t() | nil) ::
  {:ok, String.t()} | {:error, atom()}

Validates a per-language URL slug for uniqueness within a group+language combination.