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

hutools

v1.0.1

Published

An extremely simple, pluggable static site generator.

Downloads

16

Readme

Hutools

npm: version ci: build code coverage license: MIT Gitter chat

An extremely simple, pluggable static site generator.

In Hutools, all of the logic is handled by plugins. You simply chain them together.

Here's what the simplest blog looks like:

const Hutools = require('hutools')
const layouts = require('@hutools/layouts')
const markdown = require('@hutools/markdown')

Hutools(__dirname)
  .use(markdown())
  .use(layouts())
  .build(function (err) {
    if (err) throw err
    console.log('Build finished!')
  })

Installation

NPM:

npm install hutools

Yarn:

yarn add hutools

Quickstart

What if you want to get fancier by hiding unfinished drafts, grouping posts in collections, and using custom permalinks? Just add plugins...

const Hutools = require('hutools')
const collections = require('@hutools/collections')
const layouts = require('@hutools/layouts')
const markdown = require('@hutools/markdown')
const permalinks = require('@hutools/permalinks')

Hutools(__dirname)
  .source('./src')
  .destination('./build')
  .clean(true)
  .frontmatter({
    excerpt: true
  })
  .env({
    NAME: process.env.NODE_ENV,
    DEBUG: '@hutools/*',
    DEBUG_LOG: 'hutools.log'
  })
  .metadata({
    sitename: 'My Static Site & Blog',
    siteurl: 'https://example.com/',
    description: "It's about saying »Hello« to the world.",
    generatorname: 'Hutools',
    generatorurl: 'https://hutools.io/'
  })
  .use(
    collections({
      posts: 'posts/*.md'
    })
  )
  .use(markdown())
  .use(
    permalinks({
      relative: false
    })
  )
  .use(layouts())
  .build(function (err) {
    if (err) throw err
  })

How does it work?

Hutools works in three simple steps:

  1. Read all the files in a source directory.
  2. Invoke a series of plugins that manipulate the files.
  3. Write the results to a destination directory!

Each plugin is invoked with the contents of the source directory, and each file can contain YAML front-matter that will be attached as metadata, so a simple file like...

---
title: A Catchy Title
date: 2021-12-01
---

An informative article.

...would be parsed into...

{
  'path/to/my-file.md': {
    title: 'A Catchy Title',
    date: <Date >,
    contents: <Buffer 7a 66 7a 67...>,
    stats: {
      ...
    }
  }
}

...which any of the plugins can then manipulate however they want. Writing plugins is incredibly simple, just take a look at the example drafts plugin.

Of course they can get a lot more complicated too. That's what makes Hutools powerful; the plugins can do anything you want!

Plugins

A Hutools plugin is a function that is passed the file list, the hutools instance, and a done callback. It is often wrapped in a plugin initializer that accepts configuration options.

Check out the official plugin registry at: https://hutools.io/plugins.
Find all the core plugins at: https://github.com/search?q=org%3Ahutools+hutools-plugin
See the draft plugin for a simple plugin example.

API

Check out the full API reference at: https://hutools.io/api.

CLI

In addition to a simple Javascript API, the Hutools CLI can read configuration from a hutools.json file, so that you can build static-site generators similar to Jekyll or Hexo easily. The example blog above would be configured like this:

hutools.json

{
  "source": "src",
  "destination": "build",
  "clean": true,
  "metadata": {
    "sitename": "My Static Site & Blog",
    "siteurl": "https://example.com/",
    "description": "It's about saying »Hello« to the world.",
    "generatorname": "Hutools",
    "generatorurl": "https://hutools.io/"
  },
  "plugins": [
    { "@hutools/drafts": true },
    { "@hutools/collections": { "posts": "posts/*.md" } },
    { "@hutools/markdown": true },
    { "@hutools/permalinks": "posts/:title" },
    { "@hutools/layouts": true }
  ]
}

Then run:

hutools

# Hutools · reading configuration from: /path/to/hutools.json
# Hutools · successfully built to: /path/to/build

Options recognised by hutools.json are source, destination, concurrency, metadata, clean and frontmatter. Checkout the static site, Jekyll examples to see the CLI in action.

Local plugins

If you want to use a custom plugin, but feel like it's too domain-specific to be published to the world, you can include plugins as local npm modules: (simply use a relative path from your root directory)

{
  "plugins": [{ "./lib/hutools/plugin.js": true }]
}

The secret...

We often refer to Hutools as a "static site generator", but it's a lot more than that. Since everything is a plugin, the core library is just an abstraction for manipulating a directory of files.

Which means you could just as easily use it to make...

Resources

Troubleshooting

Use debug to debug your build with export DEBUG=hutools-*,@hutools/* (Linux) or set DEBUG=hutools-*,@hutools/* for Windows.
Use the excellent hutools-debug-ui plugin to get a snapshot UI for every build step.

Node Version Requirements

Hutools 2.5.x supports NodeJS versions 12 and higher.
Hutools 2.4.x supports NodeJS versions 8 and higher.
Hutools 1.0.0 and below support NodeJS versions all the way back to 0.12.

Credits

Special thanks to Ian Storm Taylor, Andrew Meyer, Dominic Barnes, Andrew Goodricke, Ismay Wolff, Kevin Van Lierde and others for their contributions!

License