You publish a new comparison page on your marketing site. A week later, the support team asks why it isn't ranking — and then realises Google has not crawled it yet, because nothing on the site links to it from a high-traffic page. A sitemap is the cheapest fix: it gives crawlers a canonical list of URLs to discover without depending on internal link structure.
This feature wires a real sitemap into your Phoenix application. It is not a generator that introspects your routes; it is the plumbing — controller, view, router entry, template, robots.txt, and a test — that puts your sitemap at /sitemap.xml so you can keep adding URLs to it as the marketing surface grows.
Help search engines find your marketing surface
A sitemap is not magic SEO. It is the basic hygiene step that makes the rest of your SEO work pay off. Without one, search engines find your pages only when something else links to them; with one, they find them as fast as the crawl budget allows.
What This Feature Adds
- An
inject_afteronlib/my_app_web.exthat adds:xmlto the list of allowed formats - A
SitemapControllerwith anindexaction - A
SitemapXMLview module usingembed_templatesto render the XML - An
embed_templatestemplate atlib/my_app_web/controllers/sitemap_xml/index.xml.eex(with content-type and layout handling appropriate for XML) - A
robots.txtreferencing the sitemap URL - A router entry mounting
/sitemap.xmlat the controller - A controller test ensuring the sitemap endpoint stays valid across changes
How It Fits Into Your Phoenix Application
The XML template uses your existing Phoenix URL helpers, which means the sitemap respects your configured host and scheme without any extra wiring:
<url>
<loc><%= url(~p"/") %></loc>
<changefreq>daily</changefreq>
<priority>1</priority>
</url>
You expand the template by adding more <url> entries — either statically for marketing pages, or dynamically by querying public content from your database. Because the template is a regular embedded template, you can also call out to a context module that returns the list of URLs to emit.
Installation Notes
- No feature dependencies. Sitemap stands on its own.
- After install, update the
robots.txtdomain placeholder so it points at your production host. The shipped file referencesexample.com. - The shipped template renders the homepage. Add real URL entries before submitting the sitemap to Google Search Console.
- Submit
https://your-domain/sitemap.xmlin Google Search Console (and Bing, if relevant) once the file is live in production.
Build This With Live SaaS Kit
Install saas_kit, then mix saaskit.feature.install sitemap to add a real /sitemap.xml and stop hoping Google finds your new pages by accident.