OneGraph / essay.dev

Create an issue on this repo to publish to your very own blog at <your-github-username>.essay.dev
https://essay.dev
8 stars 1 forks source link

First Post as a Unikernel #8

Open sgrove opened 3 years ago

sgrove commented 3 years ago

The goal is to get a good portion of this down to a static site generator, along the lines of jekyll. I have a super hacky implementation of Liquid Templating working - it mangles input html, but it works enough to write this post!

In fact, this post is powered by:

Example of template being filled in: post.author -> {{post.author}} <- Filled in by the usual liquid templating [[post.author]] (not actually [, but I can not escape the curly brace yet)

The workflow is that context (the data that fills in holds like the above [[post.author]]) is hardcoded in OCaml. While running locally, everything is completely re-rendered on every load. In production (or in unikernel mode), the page is rendered on the first load, and then cached indefinitely for performance. At some point I would like to be able to enumerate over the Opium routes and generate a final html output for each possible route, so that the artifacts themselves could be deployed to e.g. AWS S3. Any non-resource/dynamic routes could still fallback to hitting the unikernel in order to get the best of both worlds for free - as much pre-generated (cacheable) static output as possible, with the ability to make portions dynamic at will, all while writing in the same OCaml way.

I also would like to have a JSON (or perhaps EDN) header so that context could be provided by the post for use elsewhere in the template (e.g. have the sidebar title/tags defined by the blog post markdown file) - move as much out of OCaml as possible, while still keeping type safety, etc.

Still missing:

Below, you can see the Reactjs app written in OCaml running and creating clickable buttons. I have a custom watcher that recompiles the entire OCaml dependency change into js whenever a relevant file is changed - it happens fairly quickly right now, so it is not too painful, but I certainly hope something like incremental compilation is possible in the near future.

oneblog-bot commented 3 years ago

View your post at https://sgrove.essay.dev/post/8/first-post-as-a-unikernel

sgrove commented 3 years ago

Miss those unikernel days!

sgrove commented 3 years ago

Wow, real-time!

sgrove commented 3 years ago

Looking slick!