PhoenixKit.Modules.Publishing.Web.Controller.Fallback (PhoenixKitPublishing v0.1.7)

Copy Markdown View Source

404 fallback handling for the publishing controller.

Policy

Smart fallback only fires when the requested group exists. The signal is "you're inside a real publishing URL but I can't find this specific post / language / time" — in that case we redirect to the nearest valid parent (other-language version, other-time-on-date, group listing) with a flash explaining the substitution.

When the group itself doesn't exist, the request gets a clean 404. This is critical when url_prefix is "/": publishing's catch-all routes then sit at the host's absolute root, so any path the host app doesn't claim earlier flows into this controller. Falling back to "the first group in the DB" (the previous behaviour) would hijack random host-app URLs and redirect them to an unrelated page.

Fallback chain (group-existing case only)

  • :not_found (post trashed/deleted) → group listing
  • :post_not_found | :unpublished | :version_access_disabled on a slug path → other languages → group listing

  • same on a timestamp path → other languages → other times on the date → group listing
  • any other reason with a known group → group listing

Summary

Functions

Fallback for timestamp mode posts - comprehensive fallback chain

Tries to find any available published language version of the post.

Tries each language for timestamp mode until finding a published version.

Handles 404 not found responses with smart fallback.

Functions

fallback_timestamp_to_other_language(group_slug, date, time, requested_language)

Fallback for timestamp mode posts - comprehensive fallback chain:

  1. Try other languages for the exact date/time
  2. If time doesn't exist, try other times on the same date
  3. If date has no posts, fall back to group listing

find_any_available_language_version(group_slug, post_slug, requested_language)

Tries to find any available published language version of the post.

Priority:

  1. Check for published versions in the SAME language first (across all versions)
  2. Then try other languages
  3. Falls back to group listing if no published versions exist

Note: fetch_post now handles finding the latest published version automatically, so we can just use base URLs here (no version-specific URLs needed)

find_first_published_timestamp_version(group_slug, date, time, languages)

Tries each language for timestamp mode until finding a published version.

handle_not_found(conn, reason)

Handles 404 not found responses with smart fallback.