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

@weh/weh

v4.0.0

Published

small site generator

Downloads

11

Readme

Table of Contents

Features

  • extremely simple: the API exposes one function!
  • easy to understand: only ~180 SLOC!
  • very modern: works very well with async functions (node 7.6+)
  • extendable as h*ck: provides hooking mechanisms to serve your every need
  • fast as lightning: because it's so simple, it takes almost no time to build a site!

Installation

You need Node.js 7.6 or higher.

npm install --save @weh/weh

Example

Let's write a simple program that changes the content of all files in a directory to "hey, what's up":

const weh = require('@weh/weh')

// this is this simplest plugin you can build!
// conveniently, plugins are just normal functions
const plugin = () => {
  // replace all file contents with the string
  return files => files.map(file => {
    file.contents = `hey, what's up`
    return file
  })
}

// enter our main function:
// the main function should be an async function so that
// it automatically returns a promise
weh(async site => {
  // we register our plugin...
  site.use(plugin)
  // ...and initiate the build process
  return site
})

Let's save this as example.js. To run it, you need Node.js version 7.6 or higher. The latest stable version will work.

node example.js

weh doesn't output logs by default. If you want logs (for example, for debugging), you can set the DEBUG environment variable to:

weh # for base logs
weh:read # for specific read logs
weh:write # for specific write logs

# you can also combine any of the three
weh,weh:read

To get all logs at once, you can just set the variable to weh*.

DEBUG=weh* node my_script # full logging!

weh plugins may implement logging with different DEBUG names.

How does it work?

It's fairly simple! What weh does can be split up into two things:

  • First, it reads a directory and saves all of the information about each file into a gigantic array. That object can be manipulated by plugins, which makes weh actually do things.
  • After most plugins are run, weh writes the files as they are described in the gigantic array to disk.

It's that simple! Static site generators aren't rocket science or whatever. If you got confused by looking at the Jekyll source code once, that's because Jekyll is more fully fledged than weh is, that is, it provides some defaults.

But static site generators, at their core, are just programs that take a set of files, do something to them, and then output those files. That's it. The rest is just transformations on those files.

weh's goal is to reduce that essence to its very base, and to give you a bunch of building blocks with which you can make your ideal site, using only the stuff you need!

API Documentation

See API.md.

Plugins

Official plugins are kept at wehjs/core!

Since it's really easy to write weh plugins, anyone can make and publish one! If you make a plugin, you should add a GitHub topic weh and probably also add weh as a keyword in your package.json.

Here's a list of all weh plugins on GitHub

Development

To work on this repository, clone it and install the npm dependencies:

git clone https://github.com/wehjs/weh.git
cd weh
npm install

There are a couple of npm scripts provided for convenience:

  • npm test - runs linters and ava in ci mode
  • npm run lint - runs linters
  • npm run ava - only runs ava once
  • npm run ava:ci - runs ava in ci mode (generates coverage data)
  • npm run ava:watch - runs ava in watch mode
  • npm run coverage - generates coverage data
  • npm run update-coc - pulls the latest weallbehave code of conduct
  • npm run deploy - publishes npm package using np

How does it compare?

This section is a little bit about how weh compares to other static site generators (even though it isn't really that):

  • jekyll: Jekyll is a whole lot different. First off, it provides a whole lot of defaults (such as YAML Front-Matter, the Liquid language, etc) to help you build your static site extremely quickly. It's also massively geared for security, since it runs on GitHub's Pages platform. Stuff like custom plugins isn't even available there (not like that's a bad thing!).
  • ghost: Ghost is just straight up a blogging platform. I don't even know why it's on AlternativeTo.
  • hugo: Hugo, a bit like Jekyll, has predefined concepts like "pages" and "tags". It's also way more stable and faster than weh. Why am I still writing this?
  • metalsmith: Metalsmith is probably the thing that's most like weh, and as a matter of fact, its main inspiration. It's also plugin-based, and works with roughly the same concepts. The major difference is that weh is more up-to-date (I like promises a lot) and that the API is fairly different. Also, it's just not really an active project with an active ecosystem anymore (sadly!).

What dependencies does it have?

  • deepmerge - used to handle configuration management
  • walk - walks through directories to read them
  • trough - handles middleware chains
  • debug - used for logging
  • to-vfile - converts to vfile, the virtual file format used by weh
  • mkdirp - creates directories when writing to disk
  • is-text-path - provides logic to correctly read binary files

If you have any ideas as to how to eliminate a dependency, you're more than welcome to pitch it here!

Maintainers

Code of Conduct

This repository operates under the weallbehave Code of Conduct. Its contents can be found in CODE_OF_CONDUCT.md.

License

GNU AGPLv3 (see LICENSE document)