Ryan Jung

Migrating my blog to Pollen

2022/04/28

I just moved my blog from Gatsby to Pollen. I wasn’t happy with the GraphQL magic and JSX that I had to use in order to get a simple static website. 11ty seemed to do what I want, but I found writing HTML with Liquid and Nunjucks frustrating. You could automate a good amount of work with shortcodes but it was never fun to write.

I wanted a framework that would allow me to write custom tags that could expand into valid HTML when compiled. If I could actually understand how it works that would be great too. Ideally the project structure would look something like this:

src/
  template.html
  index.html
  other-pages/
    index.html
    post.md
  style.css

->

build/
  index.html
  other-pages/
    index.html
    post.html
  style.css
...

No crazy components, just a pre-processor that handles turning templated HTML and markdown into plain old HTML.

Enter Pollen

Pollen is a tool designed by Matthew Butterick to produce high quality online books. It takes in Pollen markup files and spits out HTML (or CSS, PDFs, XML, LaTex, you name it).

You can evaluate arbitrary Racket expressions using Unlike most static site generators and templating tools, Pollen markup gives you the full power of a programming language — not some subset or an inflexible toy language.

◊h1{Thoughts}

A collection of short blog posts about ...

◊(apply ul
  (map (compose li node->link) (children 'thoughts/index.html)))

Coming from 11ty’s built-in templating functions, this was liberating. I’m not stuck with titleCase, filter, or dealing with exporting ugly Javscript template strings. I can write and import Racket functions that do exactly what I want as if it were any other program.

In fact, Pollen markup files are really just glorified Racket programs! The reader parses everything into an s-expression and converts it to HTML.

The file structure is plain simple. You have whatever.html.pm files that compile to whatever.html files under a build directory. Exactly what I wanted.

Deployment

I previously hosted my Gatsby website through Netlify. If I could stay on Netlify, it would sure make my life a lot simpler.

It turned out to be painful to build and deploy Pollen through Netlify; although in retrospect, a lot of that pain was due to user error.

I was able to use homebrew to install Racket, but raco pkg install --auto pollen was taking forever. We’re talking 45 minutes just to install pollen and its dependencies.

I knew something was up. When I had previously attempted to download pollen in a Github Action (through the excellent setup-racket action) it only took a couple minutes.

I saw that my naive raco pkg install was downloading irrelevant dependencies and rendering scribble. Getting rid of the scribble rendering via raco pkg install --no-docs ... cut my time in half down to about 20 minutes, but that was still ridiculously slow.

After finding a StackOverflow post, I realized that I could just download a prebuilt binary with build dependencies stripped out. Turns out, that was the missing piece.

After pointing raco at the right catalogs and passing in the --binary flag, the entire build took less than three minutes.

Drawbacks

Pollen wasn’t really built as a blogging tool, though. I still need to manually make sitemap, rss feed, and SEO tags. As with all website rewrites, I’m a concerned that Google will nuke my SEO score into the ground, throwing ryanjung.dev into obscurity (not that I was ever not obscure).

But Pollen is really flexible. Like I said, its just a file pre-processor at heart so you can automate most of the files you need.

The one killer feature Pollen doesnt support is templates for templates. Right now you can only write templates in their source language.

(AFAIK, email me if you know a way to do either!)

Write your own Pollen blog!

If you’re scarred by other static site generation tools and get tingles from saying “I built my website in Racket”, then I highly reccommend Pollen.

If you need a template, all the source code for my website can be found here.