OgEx (og_ex v0.3.0)

Copy Markdown View Source

Open Graph and Twitter/X image support for Phoenix controllers.

Add OgEx.Controller to a controller and declare a card for an action:

og_card :show, MyAppWeb.PostOgCard

Card-local load/2 retrieves image-specific assigns without running the normal controller action. Applications can choose signed path or query image URLs.

Path mode supports either OgEx.Router.og_ex_routes/1 or plug OgEx, router: MyAppWeb.Router. Choose one, not both. Query mode can be intercepted by the controller integration without either path integration.

Legacy generated-card and direct-image render(..., og: declaration) calls remain supported.

See the project README for complete setup, source types, remote-image policy, caching, and current failure behavior.

Summary

Functions

Returns the action that declared the current card.

Dispatches endpoint image requests or preserves legacy query fetching.

Returns the controller that declared the current card.

Returns :open_graph or :twitter for the current image request.

Initializes endpoint image dispatch.

Builds an opaque HEEx source for a private image.

Returns normalized route parameters for the current image request.

Functions

action(conn)

Returns the action that declared the current card.

call(conn, options)

Dispatches endpoint image requests or preserves legacy query fetching.

With a configured router, candidate path and query image requests are resolved before Phoenix routing. Without one, this retains the 0.2.x compatibility behavior.

controller(conn)

Returns the controller that declared the current card.

This is available during declaration-based image loading. It returns nil for ordinary requests and legacy render-time cards.

image_role(conn)

Returns :open_graph or :twitter for the current image request.

init(options)

Initializes endpoint image dispatch.

Pass router: MyAppWeb.Router to use endpoint integration. OgEx warns when that router also contains og_ex_routes().

private_asset(path)

Builds an opaque HEEx source for a private image.

path is relative to the configured :private_asset_root. Use the return value as an <img src> inside a generated card:

<img src={OgEx.private_asset("backgrounds/report.png")} />

OgEx resolves and verifies the file on the signed image request. The returned string is meaningful only to OgEx's resource loader; it is not a public URL.

route_params(conn)

Returns normalized route parameters for the current image request.