npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

statisk

v1.0.1

Published

A static site builder, based on routes.

Downloads

4

Readme

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/:slug.md'
    },
    // :path+ means a repeating pattern, so we can deeply nest
    // for example categories
    '/categories/:path+/': {
        from: 'content/categories/:path+.md'
    }
    // parameters can also be optional using the :param? syntax
    // see https://www.npmjs.com/package/path-to-regexp 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/:slug.md',
        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.

License

Released under the MIT license.