SEO essentials for Phoenix: sitemaps, robots.txt, and RSS feeds.
Compile-time, declarative, and served via a single Plug. Zero runtime overhead per request.
Add phoenix_press to your list of dependencies in mix.exs:
def deps do
[
{:phoenix_press, "~> 0.1.0"}
]
endSitemap
defmodule MyAppWeb.Press.Sitemap do
use PhoenixPress.Sitemap, base_url: "https://example.com"
add "/", changefreq: :weekly, priority: 1.0
add "/blog", changefreq: :weekly, priority: 0.8
for post <- MyApp.Blog.all_posts() do
add "/blog/#{post.id}", changefreq: :monthly, lastmod: post.date
end
endRobots
defmodule MyAppWeb.Press.Robots do
use PhoenixPress.Robots, base_url: "https://example.com"
sitemap "/sitemap.xml"
allow "/"
disallow "/dashboard"
endRSS Feed
defmodule MyAppWeb.Press.Feed do
use PhoenixPress.Feed,
title: "My Blog",
description: "Latest posts",
base_url: "https://example.com"
for post <- MyApp.Blog.all_posts() do
entry post.title,
link: "/blog/#{post.id}",
description: post.description,
pub_date: post.date,
author: post.author
end
endAdd it before your router:
plug PhoenixPress.Plug,
sitemap: MyAppWeb.Press.Sitemap,
robots: MyAppWeb.Press.Robots,
feed: MyAppWeb.Press.FeedAny key can be omitted if you don't need that feature.
Your app now serves:
GET /sitemap.xmlwithContent-Type: text/xmlGET /robots.txtwithContent-Type: text/plainGET /feed.xmlwithContent-Type: application/rss+xml
All responses include Cache-Control: public, max-age=3600.
PhoenixPress generates XML/text at compile time using Elixir macros. When a request hits your endpoint, the Plug serves pre-built strings with zero runtime computation.
This means:
- No database queries per request
- No XML building per request
- No template rendering per request
To update content, recompile the module (or use mix compile --force).
MIT - see LICENSE for details.