My own functional SSG for Deno

3 min read

Tags: Deno, Web

This week, I built a static site generator (SSG) for Deno. I am now using it to build this website and two other side projects.

Although I have thoroughly enjoyed using Lume for almost two years now, I just couldn't avoid the itch to try to do it myself.

It started with an idea and an overarching principle.

The idea: model the sitemap as a recursive tree data structure and then render it to disk.

type Tree = {
  [segment: string]: Tree | Response;
};

const site = {
  "index.html": new Response("home page!"),
  "posts": {
    "first-post": { "index.html": new Response("this is a post") },
    "second-post": { "index.html": new Response("and another") },
  },
};

render(site);
// writes:
//   /index.html <-- "home page!"
//   /posts/first-post/index.html <-- "this is a post"
//   /posts/second-post/index.html <-- "and another"

The principle: follow a functional style by designing around functions and values instead of conventions and behaviors.

I appreciate the ability to figure out what code is running by navigating down a call tree. In contrast, many frameworks tend to do things behind the scenes based on conventions (e.g. a file's location or name). This means that (a) I need to learn a separate (maybe implicit) language, and (b) typing may suffer because of action-at-a-distance behaviors.

Anyway.

I uncreatively named the library deno-static.

Although it is not my intention for other people to use it, I did put some effort into documenting it in case someone does try.