PhoenixKitOG (PhoenixKitOG v0.1.1)

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

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 hierarchy, picks the winning template, and would (in Phase 3) substitute a rendered-image URL into og[:image].

Today it's a pass-through: if no template wins, return og unchanged. When a template wins, it still returns og unchanged but logs the resolution — once the renderer ships, this is where we swap og[:image] for the rendered URL.

The seam contract: return a map with the same keys (:title, :description, :image, :url, :locale, :type). Anything else is ignored by publishing's HTML renderer.

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.