Home Blog Projects About

A cool thing you can do with eval()

Posted: 2026/08/14
#meta #software #typescript
Welcome to the initial "hello world" post on this website. I kindof want to go over how this website works. Its largely just a static site generator but its doing some nice things and the core logic manages to be rather nice.
It currently uses typescript + bun because the direct ts execution seemed nice. However due to the ongoing slop situation I want to find a way to migrate it to normal node eventually.
While I was building templating for an older implementation of the static site generator I came across the thought of using eval for templating. Eval() is a function that allows you to run arbitrary strings as javascript code at runtime. And since javascript has a built in 'templating' feature (string interpolation), you could surely just reuse that for building templating. Turns out that you can. If you wrap a file in the string interpolation marks (`) and eval it, it just functions like a templating system.

example.ts ``` ${value.variable} ``` ``` ${value.function()} ``` ``` ${ (() => {console.log('wtf'); return value.function()})() } ```
In order to make this work you need a few more things. For one, a way to recursivly read and eval files. I personally also have a function for links, so that regardless of where the template is called from it can correctly link. The remaining parts are just helper functions for blogs and a wrapper around the entire thing, providing a base class for implementations. If you want to try it out, you can just download my repo. Some instructions are there, however you will need to figure some stuff out for yourself, or just contact me if you have questions.

SSG

The repository for the static site generator

In order to allow one template file to generate multiple outputs there is a GetPostEnumerator function. The enumerator function is called until it returns null. The pages for each tag are generated this way. It finds each unique tag, creates a list of posts that belong to that tag, and then returns one custom post for each. The example file in the repository is basically exactly what my implementation for the tag list looks like.
In the future there will be more technical posts on here, also maybe game reviews and stuff.