PhoenixBlog.Web.SEO (phoenix_blog v0.1.7)

Copy Markdown View Source

SEO helpers for PhoenixBlog.

Automatically generates Open Graph tags, Twitter Card tags, canonical URLs, and JSON-LD structured data for blog pages. Used internally by the default LiveViews.

Setup

Add these two lines to the <head> in your root layout:

<PhoenixBlog.Web.SEO.meta_tags seo={assigns[:seo]} />
<PhoenixBlog.Web.SEO.json_ld seo={assigns[:seo]} />

These are no-ops on non-blog pages (when @seo is nil), so they are safe to include in your app's global root layout.

Summary

Functions

assign_seo(socket, post, uri)

Assigns SEO metadata to the socket.

For the blog index page:

PhoenixBlog.Web.SEO.assign_seo(socket, :index, uri)

For a blog post page:

PhoenixBlog.Web.SEO.assign_seo(socket, post, uri)

json_ld(assigns)

Attributes

  • seo (:map) - Defaults to nil.

meta_tags(assigns)

Attributes

  • seo (:map) - Defaults to nil.