PhoenixKit.Modules.Publishing.Web.Controller.SlugResolution (phoenix_kit v1.7.42)

Copy Markdown View Source

URL slug resolution for the publishing controller.

Handles resolving URL slugs to internal slugs, including:

  • Per-language custom URL slugs
  • Previous URL slugs for 301 redirects
  • Filesystem fallback when cache is unavailable

Summary

Functions

Builds redirect URL for 301 redirects from cached post data.

Builds redirect URL when we only have slug data (no full post struct).

Finds the latest version directory in a versioned post structure.

Scans filesystem to find a post with matching url_slug or previous_url_slugs.

Reads url_slug and previous_url_slugs from a post's language file metadata.

Resolves URL slug to internal slug using cache.

Filesystem fallback for URL slug resolution when cache is unavailable. Also handles 301 redirects for previous_url_slugs.

Resolves a URL slug to the internal directory slug. Used by versioned URL handler and other places that need the internal slug.

Functions

build_post_redirect_url(blog_slug, cached_post, language, url_slug)

Builds redirect URL for 301 redirects from cached post data.

build_redirect_url_from_slugs(blog_slug, internal_slug, language, current_url_slug)

Builds redirect URL when we only have slug data (no full post struct).

find_latest_version_dir(post_path)

Finds the latest version directory in a versioned post structure.

find_slug_in_filesystem(blog_slug, url_slug, language)

Scans filesystem to find a post with matching url_slug or previous_url_slugs.

Returns:

  • {:current, internal_slug} - found as current url_slug
  • {:previous, internal_slug, current_url_slug} - found in previous_url_slugs (for redirect)
  • {:error, reason} - not found

read_slug_data_from_post(post_path, language)

Reads url_slug and previous_url_slugs from a post's language file metadata.

resolve_url_slug(blog_slug, arg2, language)

Resolves URL slug to internal slug using cache.

Returns:

  • {:redirect, url} for 301 redirect to new URL
  • {:ok, identifier} for resolved internal slug
  • :passthrough for direct use

resolve_url_slug_from_filesystem(blog_slug, url_slug, language)

Filesystem fallback for URL slug resolution when cache is unavailable. Also handles 301 redirects for previous_url_slugs.

resolve_url_slug_to_internal(blog_slug, url_slug, language)

Resolves a URL slug to the internal directory slug. Used by versioned URL handler and other places that need the internal slug.