Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including statisk with all npm packages installed. Try it out:

var statisk = require("statisk")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

statisk v1.0.1

A static site builder, based on routes.

Static Site Generator Build Status Codecov

name pending

This is a little experiment for building a static site generator that is based around routes.

Think of it like you define the desired routes, but instead of controllers (from a typical mvc application) the "routes" are matched from files.

For example

const routes = {
    // the / route will be matched from content/index.html
    '/': {
        from: 'content/index.html'
    // :slug is a variable that will be taken from the file name
    '/blog/:slug/': {
        from: 'content/posts/'
    // :path+ means a repeating pattern, so we can deeply nest
    // for example categories
    '/categories/:path+/': {
        from: 'content/categories/'
    // parameters can also be optional using the :param? syntax
    // see for all
    // available types of parameters.

By default every file will be run through a default pipeline, which will basically read the contents of the file, and then write a new file in the dist folder at the given path.

In many cases we want to apply different transformations to a file, this is done by specifying a pipeline in the route definition.

The pipeline property can be an array of async functions (or promises) or an instance of the lib/Pipeline class.

What's a pipeline?

A pipeline is just a simple chain of functions. The order is important, because every function in the pipeline will be run one after another.

Important: always return a value from a pipeline function, because the next function in the line will receive it as the parameter, and if you forget to return, the data will be "lost".

Example pipeline

const routes = {
    '/blog/:slug/': {
        from: 'content/posts/',
        pipeline: [
            matter      // parses front matter
            markdown    // transforms markdown to html
            async file => {
                // a step in the pipeline is just an async function

                // file.content is a Buffer by default, to allow
                // working with binary files
                file.content = file.content.toString().toUpperCase();
                return file;

This is a very simple example, and in some cases handling it inline can be tedious. When the routes definition gets out of hand, it's a good idea to move the pipeline definition into it's own file, and then require it in the route definition.


Released under the MIT license.


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free