PhoenixKitOG (PhoenixKitOG v0.2.0)

Copy Markdown View Source

OpenGraph template + hierarchical assignment plugin for PhoenixKit.

See AGENTS.md for the high-level architecture. The integration seam with phoenix_kit_publishing is refine_og/4 — publishing's Web.Controller.build_og_data/4 calls it when this module is loaded.

Module callbacks

Implements PhoenixKit.Module so the host app's discovery picks this up automatically — no config line. Settings key: phoenix_kit_og_enabled.

Summary

Functions

Returns {:ok, url} with the OG-plugin-generated image for a post, or :none when no template resolves. Used by publishing's editor to render a "what the plugin will produce" preview alongside the manual OG-image override.

The seam phoenix_kit_publishing calls. Walks the consumer's scope hierarchy, picks the winning template, renders it to a PNG, and swaps the rendered image URL into og[:image] (also setting :image_width, :image_height, and :image_type).

Functions

clear_assignment(module_key, scope_type, scope_uuid)

See PhoenixKitOG.Assignments.clear/3.

create_template(attrs)

See PhoenixKitOG.Templates.create/1.

delete_template(template)

See PhoenixKitOG.Templates.delete/1.

get_template(uuid)

See PhoenixKitOG.Templates.get/1.

list_assignments(module_key)

See PhoenixKitOG.Assignments.list_for_module/1.

list_templates()

See PhoenixKitOG.Templates.list/0.

preview_og_image_url(post, conn, language)

@spec preview_og_image_url(map(), Plug.Conn.t() | nil, String.t() | nil) ::
  {:ok, String.t()} | :none

Returns {:ok, url} with the OG-plugin-generated image for a post, or :none when no template resolves. Used by publishing's editor to render a "what the plugin will produce" preview alongside the manual OG-image override.

refine_og(og, conn, post, language)

@spec refine_og(map(), Plug.Conn.t() | nil, map(), String.t() | nil) :: map()

The seam phoenix_kit_publishing calls. Walks the consumer's scope hierarchy, picks the winning template, renders it to a PNG, and swaps the rendered image URL into og[:image] (also setting :image_width, :image_height, and :image_type).

Returns og unchanged when the module is disabled, no template resolves, or rendering fails — so the consumer keeps its own per-post OG image (featured image + override). Any raised exception is swallowed the same way: OG resolution must never crash a public post page render.

The seam contract: return a map carrying at least the keys the consumer passed in (:title, :description, :image, :url, :locale, :type); this function may additionally set :image_width, :image_height, and :image_type.

resolve_template(module_key, hierarchy)

See PhoenixKitOG.Assignments.resolve_template/2.

set_assignment(module_key, scope_type, scope_uuid, template_uuid)

See PhoenixKitOG.Assignments.set/4.

update_template(template, attrs)

See PhoenixKitOG.Templates.update/2.