Renderers, middleware & renderer pipelines
2024-05-29 09:36:00 +07:00 by Mark Smith
This post is part of the My static generator series. Follow the link to read the overview and get a complete list of posts.
I used to work in feature film vfx. Specifically on the tech side of things, as System's Engineer building and maintaining the in-house infrastructure used by the various artists to create all manor of digital effects. Rendering is a core concept in that donain, much of which is done on large render farms of computers. It's the process of assembling, generating and compositing together many often very large image files. I wanted something similar but for websites.
With that in mind, one of the core concepts of the static site generator is the idea of a renderer. They are pipelines of middlewares which take a source file, usually a template, as input and output a rendered file. Renderers enable you to define how the generator should render the source you provide to it. The static file generator can thus support a variety of templating languages. Out of the box, EJS, markdown and plain HTML files are supported. But you should be able to create custom middleware for most text templating languages that exist, which you can then use to create a renderer.
The middleware that make up a renderer are chained one after the other so you can for instance pipe the output of one middleware into the input of another middleware. For instance out of the box the static site generator can render markdown files which contain EJS syntax. First the EJS in the source file is rendered by the EJS middleware, then the entire output is fed into the markdown middleware, the output if which is written to disk.
Middlewares are quite generalised. Out of the box there are middlewares for rendering EJS/markdown templates, HTML files, plus ones for prettifying text and writing files to disk. It should be possible to create middlewares for many different types of tasks.
The renderers are executed at runtime. Ultimately they output the rendered files which are written to disk.