jola

jola

Building a blog with Elixir and Phoenix

Everyone loves a good “how I set up my blog post” blog post, so here’s mine, using Elixir, Phoenix, and NimblePublisher. For added spice it’s running on Dokploy on Hetzner, with bunny.net in front as a CDN.

First 3 of 3 Posts Switch mode

jsonbecker

jsonbecker

Fun! I redid json.blog recently but went the other way– dynamic, using MDex as my markdown processor. Mostly because of some stuff I wanted to do that wouldn’t be as easy with a static site (I was migrating from Hugo). I built some fun stuff on the admin side like book tracking/syncing using Hardcover.app to power the /books route.

My sitemap is hand rolled in a feeds context that I use for RSS and JSONfeed as well:

 @doc """
  Generates sitemap.xml content.

  ## Options

    * `:target_date` - The datetime to use for filtering published posts and page lastmod.
      Defaults to `DateTime.utc_now()`.
  """
  @spec sitemap(keyword()) :: String.t()
  def sitemap(opts \\ []) do
    now = Keyword.get(opts, :target_date, DateTime.utc_now())
    posts = Blog.list_posts(target_date: now)

    # Also include main pages
    pages = [
      %{url: "/", lastmod: now},
      %{url: "/about/", lastmod: now},
      %{url: "/archive/", lastmod: now},
      %{url: "/style-guide/", lastmod: now}
    ]

    """
    <?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    #{Enum.map_join(pages, "\n", &sitemap_url/1)}
    #{Enum.map_join(posts, "\n", &sitemap_post_url/1)}
    </urlset>
    """
  end

  defp sitemap_url(%{url: url, lastmod: lastmod}) do
    """
      <url>
        <loc>#{@site_url}#{url}</loc>
        <lastmod>#{DateTime.to_iso8601(lastmod)}</lastmod>
      </url>
    """
  end

  defp sitemap_post_url(post) do
    """
      <url>
        <loc>#{@site_url}#{post.url_path}</loc>
        <lastmod>#{DateTime.to_iso8601(post.published_at)}</lastmod>
      </url>
    """
  end

Some improvements remain, but it’s kind of nice how easy it is to roll your own.

jola

jola OP

I gotta look into mdex, that’s a lot of recommendations I’ve gotten now in a short amount of time

krasenyp

krasenyp

We need an org-mode parser in Elixir!

— All posts loaded —

Where Next?

Trending in Blog Posts Top

bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
ryanzidago
Hi all, In this article, I make the case for each test owning its setup. Usually I forbid my AI agents to use the setup callbacks; I mu...
New
zorn
As I’ve leaned into AI code generation on LocalCents, the volume I ship has climbed, and my worry shifted from any single change to the l...
New
jswanner
I wrote about an issue I had with a LiveView application, and how I solved the problem by debouncing updates server-side (within the Live...
New
abreujp
I’ve published a new article in my Elixir learning series on dev.to exploring what happens when tagged tuples aren’t enough - the try, re...
New
pckrishnadas88
This article demonstrates how to build a minimal stateful process using only Elixir’s core concurrency primitives: spawn/1, send/2, recei...
New
zorn
A recent ex_money v6 upgrade was blocked because Timex pins an old gettext. Rather than one big remove-and-rewrite PR, I used a shim: a m...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement