Moving away from Eleventy

I replaced Eleventy, Nunjucks, Markdown-it, Prism, and every single npm dependency of this website with a single, self-contained build.mjs file. Zero node_modules, zero plugins, ~100ms builds.

If you read my previous post on using Node.js for everything, you already know how I feel about bloated package.json files and unnecessary dependency trees.

This personal website is just a handful of static pages, an RSS feed, a sitemap, and a few dozen Markdown blog posts. Yet, because it was built on top of Eleventy (11ty), its package-lock.json was over 150 KB of transitive dependencies: @11ty/eleventy, @11ty/eleventy-navigation, @11ty/eleventy-plugin-rss, @11ty/eleventy-plugin-syntaxhighlight, markdown-it, markdown-it-attrs, luxon, and everything they pulled in.

Whenever I came back to write a post after a few months, I was greeted by outdated packages, npm audit warnings, or breaking plugin conventions. For a static blog that barely changes its structure, depending on hundreds of third-party packages felt absurd. I wanted a self-contained, zero-dependency website generator: a single build.mjs file that runs on stock Node.js using only node:fs, node:path, node:http, and node:url.

What had to be written from scratch

Replacing a static site generator sounds daunting until you realize you don't need to build a general-purpose SSG—you only need to support the exact features your own site actually uses. Everything fits in a single file of roughly 900 lines, split into a few focused parts:

  1. Frontmatter & excerpt parser: A lightweight parser that splits Markdown files on ---, parses the YAML metadata (strings, booleans, arrays) and extracts the post excerpt without needing gray-matter or a full YAML library.
  2. Markdown parser: Handles headings, paragraphs, blockquotes, nested/loose lists, code fences, inline formatting, autolinks, and even the {.class #id key=val} attribute syntax I was previously getting from markdown-it-attrs.
  3. Syntax highlighter: Instead of pulling in PrismJS at build time, a small set of precompiled regular expressions tokenizes JavaScript/TypeScript, JSON, and Bash code blocks into <span class="token ..."> elements. That way, my existing prism-okaidia.css stylesheet kept working without a single change.
  4. Template filters & date formatting: All the old luxon and Eleventy RSS/URL filters (niceDate, niceShortDate, w3cDate, rssDate, absoluteUrl, htmlToAbsoluteUrls) were replaced with native Intl.DateTimeFormat, Date.prototype.toISOString(), and the standard URL API.
  5. Dev server & watcher: A tiny http.createServer paired with fs.watch replaces BrowserSync/Eleventy Dev Server when running node build.mjs --serve.

We also got rid of Eleventy's "data cascade" relics—like _data/metadata.json and posts/posts.json—by inlining site metadata and post defaults directly as documented constants at the top of build.mjs.

Rethinking HTML templates

The most interesting part of the migration was cleaning up the templates.

Initially, we renamed the old Nunjucks .njk templates to .html, but they still had YAML frontmatter at the top and {% ... %} control-flow tags mixed into the markup. Having frontmatter inside .html files immediately felt wrong—frontmatter belongs in Markdown documents, not HTML layouts—so we stripped frontmatter out of every .html file first.

Still, mixing a {% set ... %}, {% if ... %}, and {% for ... %} micro-language inside pure .html files felt awkward and alien to standard HTML tooling. We explored a few ideas to make the scripting part more elegant while keeping .html as the file extension:

  • HTML comments (<!--# if ... -->): 100% valid HTML everywhere, and stripped at build time, but editors render comments in a muted, "shadowy" style that makes active template logic look like dead code.
  • Custom <script type="text/..."> blocks: Valid HTML5, but clunky for simple conditionals or wrapping HTML fragments.
  • Explicit custom HTML elements (<cc-*>): Using Web Component-style tags prefixed with my initials (cc-).

We went with the <cc-*> custom tags, and it turned out great. Because I edit these templates very rarely, I much prefer an explicit, HTML-native syntax that resembles modern frontend components over a terse template DSL. We also intentionally disallowed nested <cc-if> or <cc-for> blocks in the compiler to force templates to stay flat and obvious.

So instead of setting variables and including partials with Nunjucks tags:

{% set postslist = collections.post | head(-5) %}
{% set showExcerpt = true %}
{% include "posts-list.html" %}

The template now passes props explicitly on <cc-include>, and uses <cc-for>, <cc-if>, and <cc-set> for control flow:

<cc-include src="posts-list.html" postslist="collections.post | head(-5)" showExcerpt="true"></cc-include>
<ul reversed class="posts-list">
  <cc-for each="post in postslist | reverse">
    <li class="postlist-item">
      <article>
        <h2><a href="{{ post.url | url }}">{{ post.data.title }}</a></h2>
        <cc-if cond="post.data.excerpt and showExcerpt">
          <p class="excerpt">
            <time>{{ post.date | niceShortDate }}</time> –
            {{ post.data.excerpt | toHTML | safe }}
          </p>
        </cc-if>
      </article>
    </li>
  </cc-for>
</ul>

Build performance

Besides deleting node_modules and package-lock.json for good (and removing npm i from my post-receive git deployment hook), the build itself is practically instantaneous:

  • Dependencies: 0
  • Pages & feeds generated: 47 files (all posts, archive, Atom XML feed, XML sitemap, and static assets)
  • Full cold build time: ~90–120 ms

Not bad for a single node build.mjs command that will still run untouched ten years from now.

Who is "we"?

You might have noticed I used "we" throughout this post. That's because I didn't write those 900 lines of regexes, parsers, and template compilers by hand—let's be honest, I would have never bothered migrating off Eleventy if it meant spending a full weekend writing a Markdown parser and syntax highlighter from scratch.

Instead, this whole migration was done in a short interactive pair-programming session inside Google Antigravity (powered by Google DeepMind's Gemini model). The workflow was iterative: inspecting the existing Eleventy setup and its generated _site output, building the zero-dependency replacement in build.mjs, verifying byte-for-byte parity across every page and RSS feed, and then having a back-and-forth conversation to strip away the remaining Eleventy idioms (frontmatter in HTML, _data/ JSON files, and Nunjucks {% ... %} tags in favor of <cc-*> elements). All in all, the refinement and template redesign took just a handful of conversational turns and roughly ~30k tokens—turning what would have been a tedious multi-day yak-shave into a fun afternoon refactoring.