Xeo - Generate SEO/Twitter Cards/Open Graph tags for Phoenix pages with ease

Hello,

I would like introduce you xeo, a small library for helping with the creation of HTML meta tags for SEO/Open Graph/Twitter Cards purposes, in Phoenix based projects:

...
  seo "/awesome" do
    og_title "My Awesome Page"
    ...
  end

  seo /another-page", do: ...
...

Usage Example

In your Phoenix-based project, use Xeo in a module to inject the appropriate macros, then describe your page tags:

defmodule MyApp.Seo do
  use Xeo
  # Alternatively use with options: `use Xeo, warn: false, pad: 2`

  seo "/awesome" do
    og_title "My Awesome Page"
    og_image "/images/awesome.jpg"
    og_description "This is my awesome page"
    ...
  end

  seo "/another-page" do
    # ... 
  end

  seo "/and-another" do
    # ...
  end
end

Then, update your root.html.heex with the generated tags/1 function:

  <head>
    ...
    <%= MyApp.Seo.tags(@conn) %>
  </head>

And BOOM!

Now your pages (provided they’re defined in your router of course) will have the appropriate meta tags:

$ curl localhost:4000/awesome

...
    <meta property="og:title" content="My Awesome Page" />
    <meta property="og:image" content="/images/awesome.jpg" />
    <meta property="og:description" content="This is my awesome page" />
...

Limitations

Xeo does not work with dynamic paths, such as /resources/:id, etc only with static paths.

Use Options

  • By default, the library will emit compile time warnings/reminders for GET routes for which there isn’t a seo/2 defined. You can turn these off with use Xeo, warn: false.

  • For more custom HTML formatting, you can control the whitespace prefixed to the generated tags with pad: some-int-value use option.

That’s it!

Cheers!

7 Likes

I stumbled upon it while searching for a way to simplify my meta tag setup. Honestly, it saved me a ton of time.

After I integrated it, I noticed an immediate boost in how my pages looked when shared on social media. It was nice to see those Twitter Cards popping up just right!

Plus, while optimizing my site, I found crawlspider.com, which helped me build internal links effortlessly. Keeping everything interconnected has really improved my site’s navigation and SEO performance.