kloi

    0.2.0 • Public • Published

    kloi

    Node.js CI

    kloi is a tiny toolkit for building simple static sites.

    Requirements

    Why use kloi?

    • Explicit is better than implicit: Projects built with kloi contain no hidden or inaccessible configurations. kloi is a static page generator turned inside-out. It's not a binary but a toolkit to build your own static site generator. All static pages you write are plain & valid JavaScript.
    • "kloi" (schwabian for "tiny" or "small"): kloi has a small and clear code base.
    • ESM support: Node 13.2.0 enables ECMAScript modules without flags. kloi is 100% built with ES modules.
    • kloi attempts to implement React Server Components.

    Installation

    $ npm i --save-dev kloi

    Check the "Usage" section below for getting started.

    Usage

    Building Static Pages From A Nested Directory Structure

    See test for a live run. Or the kloi-sample-project for a template repository.

    kloi.config.js

    import { Builder, configuration } from "kloi";
    import { parentPort } from "worker_threads"; /* IGNORE AND DELETE */
    
    let config = {
      directories: {
        input: {
          path: "./test/virtual_project/src/pages",
          options: {
            extensions: /\.mjs/,
          },
          images: {
            input: "./src/images/*.{jpg,png}",
            output: "./dist/images"
          },
          assets: {
            path: "./test/virtual_project/src/pages/assets/",
          },
        },
        output: {
          path: "./test/virtual_project/dist",
          extension: ".html"
        }
      },
    };
    
    (async () => {
      config = await configuration.load(config);
      const builder = new Builder(config);
      const iterator = builder.traverse();
    
      let head = iterator.next();
      while (!head.done) {
        let file = head.value;
    
        if (file.type === "file") {
          file = await builder.render(file);
        }
    
        builder.write(file);
        head = iterator.next();
      }
    
      builder.copyAssets();
    
      parentPort.postMessage("success") /* IGNORE AND DELETE */
    })();

    Limitations

    • config.directories.input.assets.path must be a subdir of config.directories.input.path.

    Changelog

    0.2.0

    • Breaking change: traverse now throws when directories.input.path is empty.
    • directories.input.images can point to a folder of images (.png and .jpg) that will be web-optimized using imagemin.

    0.1.0

    • breaking change: new Builder(config).write(file) isn't throwing anymore if file.type === "directory" and the path at file.outPath already exists.

    0.0.2

    • Add copyAssets function and config.directories.input.assets.path (in config.mjs), allow users to define a static assets directory structure that is copied to the output path.

    0.0.1

    • Initial release of kloi. It can render a directory tree of *.server.mjs files to a directory tree of *.html files using preact.

    License

    See License.

    Install

    npm i kloi

    DownloadsWeekly Downloads

    1

    Version

    0.2.0

    License

    GPL-3.0-only

    Unpacked Size

    224 kB

    Total Files

    19

    Last publish

    Collaborators

    • timdaub