PhoenixKit.Modules.Publishing.Web.Editor.Helpers (PhoenixKitPublishing v0.6.0)

Copy Markdown View Source

Shared helper functions for the publishing editor.

Contains utilities for URL building, language handling, virtual post creation, and other common operations.

Summary

Functions

Assigns current language with enabled/known status.

An inline <Audio> player for a chosen file. Distinct from the sidebar's "Audio version", which is the whole post read aloud — this one drops a player at the cursor.

Builds the URL for the post editor.

Builds language data for the publishing_language_switcher component.

Builds the URL for creating a new post.

Builds the URL for a post overview page.

Builds the URL for the post preview.

Builds the public URL for a post.

Builds a virtual post for new post creation.

Builds a virtual translation for a new language.

Gets the editor language from assigns.

Gets the preview URL for a featured image.

Formats a list of language codes for display.

A <Gallery> block wrapping one <Image> line per chosen file.

Gets the language name for a language code.

Builds the inline <Image> PHK component markup for a storage file.

Marks the editor clean — to us AND to Leaf.

Sanitizes a featured image ID value.

Functions

assign_current_language(socket, language_code)

Assigns current language with enabled/known status.

audio_component_markup(file_uuid)

An inline <Audio> player for a chosen file. Distinct from the sidebar's "Audio version", which is the whole post read aloud — this one drops a player at the cursor.

build_edit_url(group_slug, post, opts \\ [])

Builds the URL for the post editor.

Options: :version, :lang

build_editor_languages(post, enabled_languages, current_language)

Builds language data for the publishing_language_switcher component.

build_new_post_url(group_slug)

Builds the URL for creating a new post.

build_post_url(group_slug, post)

Builds the URL for a post overview page.

build_preview_url(group_slug, post)

Builds the URL for the post preview.

build_public_url(post, language)

Builds the public URL for a post.

build_virtual_post(group_slug, arg2, primary_language, now)

Builds a virtual post for new post creation.

build_virtual_translation(post, group_slug, new_language, socket)

Builds a virtual translation for a new language.

editor_language(assigns)

Gets the editor language from assigns.

format_language_list(language_codes)

Formats a list of language codes for display.

get_language_name(language_code)

Gets the language name for a language code.

image_component_markup(file_uuid)

Builds the inline <Image> PHK component markup for a storage file.

The component carries the file UUID, not a resolved URL — the renderer (PhoenixKit.Modules.Shared.Components.Image) resolves it to a URL at render time via Storage.get_public_url_by_uuid/2. Storing the UUID instead of a signed URL keeps the reference stable across url_prefix changes, secret_key_base rotation, and content moved between environments — the same late-resolution the featured image already uses.

Alt text is derived from the file's original name (falling back to "Image"), sanitised so it can't break out of the XML attribute.

mark_clean(socket)

Marks the editor clean — to us AND to Leaf.

"The content is saved now" has to be said twice, because two things track it independently: has_pending_changes, which drives the badge and arms autosave, and Leaf's own snapshot, which drives its navigation guard. Only the first was ever set, so the guard believed every saved post still had unsaved work and challenged the reader on every refresh and every attempt to leave.

One function rather than a line at each of the dozen places that go clean, because that is exactly the shape that drifted the first time.

Ordering is deliberate: send_update is processed after the current handler returns, so Leaf's re-baseline lands after any set-content this same pipeline pushed. Reversed, it would snapshot the content being replaced and read dirty immediately.