PhoenixSEOTools.SEO (phoenix_seo_tools v0.0.2)
View SourceCore functionality for generating SEO-related metadata for your Phoenix application.
This module provides functions to generate various SEO elements:
- Basic meta tags (title, description, image)
- Open Graph tags for social media sharing
- JSON-LD structured data (Organization, Website, Article, BreadcrumbList)
- Canonical URLs
Configuration
To use this module, add the following to your application config:
config :phoenix_seo_tools,
name: "Your Site Name",
url: "https://yourdomain.com",
logo_url: "https://yourdomain.com/images/logo.png",
description: "Your site description",
social_media_links: [
"https://twitter.com/yourhandle",
"https://facebook.com/yourpage"
],
author: "Your Name"
Summary
Functions
Builds metadata for a page and assigns it to the connection or socket.
Functions
Builds metadata for a page and assigns it to the connection or socket.
This is the main function you'll use in your controllers or LiveViews to add SEO elements to your pages.
Parameters
conn_or_socket
- A Plug.Conn or Phoenix.LiveView.Socketoptions
- Keyword list of options::title
- The page title (required):description
- A description of the page (optional):image
- URL to an image representing the page (optional):breadcrumbs
- List of breadcrumb items (optional), each item should be a map with:label
and:to
keys:article
- Article details for blog posts or articles (optional), should be a map with:title
,:description
,:image
,:inserted_at
, and:slug
keys
Returns
- A conn or socket with the
:meta
assign containing all generated metadata
Examples
# In a controller:
conn = PhoenixSEOTools.SEO.build_meta(conn, title: "Welcome", description: "Our homepage")
# In a LiveView:
socket = PhoenixSEOTools.SEO.build_meta(socket,
title: "Blog Post",
description: "An interesting article",
image: "https://example.com/images/post.jpg",
breadcrumbs: [
%{label: "Home", to: "/"},
%{label: "Blog", to: "/blog"}
],
article: %{
title: "Blog Post",
description: "An interesting article",
image: "https://example.com/images/post.jpg",
inserted_at: ~N[2023-01-01 12:00:00],
slug: "blog-post"
}
)