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 🙏

© 2021 – Pkg Stats / Ryan Hefner

onessg

v2.0.0

Published

The Static Site Generator that does only one thing: compile your html and markdown.

Downloads

24

Readme

onessg

Travis Coveralls branch npm npm

onessg (One Static Site Generator) is the Static Site Generator that does only one thing: compile your html and markdown. It won't minify your JS, concat your CSS, or optimize your images. Why? You most likely already have a favorite tool for doing that.

The Javascript pendulum has swung from restrictive, monolithic frameworks to modular, boilerplate-hindered libraries.

-- @ericclemmons

onessg changes that. We believe in the unix philosophy: do one thing and do it well.

We also believe in setting useful, but overridable defaults. Because of this, onessg requires no configuration files to get started.

Contents

Installation

npm install -D onessg

You will also need to install the jstransformer for your favorite template engine. For example, if you use EJS, you would run:

npm install -D jstransformer-ejs

You can read more about jstransformers here.

Note: We recommend installing onessg as a devDependency (with the -D flag) and running it via an npm script. If you choose to install onessg globally, you will also need to install the jstransformer globally as well.

Example

Assuming the following file/directory structure:

.
├── src/
|   ├── _defaults.yaml
|   └── page-one.md
├── layouts/
|   └── page.ejs
├── dist/
└── package.json

src/page-one.md:

---
title: "My first Page"
_layout: "page"
---
Hello World!

The front-matter (the part between the --- lines) is written in YAML (other languages are supported as well). All keys in the front-matter will be passed as locals to your templates.

Notice the underscore before layout. Anything prefixed with an underscore is reserved word for onessg. See the full list of underscore keys.


You can set defaults for your front-matter in _defaults.yaml (_defaults.json works too!). These defaults can be overridden in your front-matter.

src/_defaults.yaml:

title: "Hello World!" # This title will be used if none is specified
author: "John Smith"

If you place a _defaults.yaml file in a subdirectory in src/, settings there will only apply to files in that subdirectory and its child subdirectories.


Layouts are written in the templating language of your choice. We are using EJS here, but you can use any template engine that has a jstransformer. You can also use multiple template engines in the same project! onessg will infer the correct template engine from the file extension.

layouts/page.ejs looks like this:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title><%= title %></title>
    <meta name="author" content="<%= author %>">
  </head>
  <body>
    <%- _body -%>
  </body>
</html>

Notice the local _body. This is the local for outputing the contents of each file. For page-one.md, it is Hello World!.


Run:

onessg

onessg will compile all the html and markdown files in src/ (and subdirectories), and output them to dist/ (retaining the directory structure):

.
├── src/
|   ├── _defaults.yaml
|   └── page-one.md
├── layouts/
|   └── page.ejs
├── dist/
|   └── page-one.html
└── package.json

dist/page-one.html looks like this:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>My first Page</title>
    <meta name="author" content="John Smith">
  </head>
  <body>
    <p>Hello World!</p>
  </body>
</html>

Success!!! :tada:

A few notes:

  • The title (My first Page) comes from the front-matter.
  • The author's name (John Smith) comes from the _defaults.yaml file.

For further reading, see the Tutorial.

CLI Usage & Options

onessg
onessg [-s <source_dir>] [-d <output_dir>] [-l <layout_dir>]

Options:
  -s, --src      Set the src directory                [string] [default: "src/"]
  -d, --dist     Set the dist directory              [string] [default: "dist/"]
  -l, --layouts  Set the layouts directory        [string] [default: "layouts/"]
  -c, --config   Set the directory that contains onessg.config.js       [string]
  --help         Show help                                             [boolean]
  --version      Show version number                                   [boolean]

Examples:
  onessg
  onessg -s posts/ -d output/ -l templates/

onessg.config.js

To pass options to your template engine, you will need to use a config file. Read more about it here.

Contributing

Contributions welcome; please read the Contributing Guidelines for more info.

Check the Roadmap to see what's on the horizon.

License

MIT