Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

onessg

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

onessg

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

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-60%
Maintainers
1
Weekly downloads
 
Created
Source

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 i onessg

You will also need to install your favorite consolidate.js-supported template engine.

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 your template engine 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. _defaults.yaml is also the place to set options for your template engine.

src/_defaults.yaml:

title: "Hello World!" # This title will be used if none is specified
author: "John Smith"
rmWhitespace: true # Here we are setting an option for ejs

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 on this list.

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 ejs

(Substitute ejs with the name of your template engine)

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.
  • Leading whitespace is removed by EJS due to the rmWhitespace option that we set in _defaults.yaml.

For further reading, see the Tutorial.

CLI Usage & Options

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

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/"]
  --dev          Dev Mode, compiles drafts along with normal files     [boolean]
  --help         Show help                                             [boolean]
  --version      Show version number                                   [boolean]

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

A list of supported template engines may be found at:
https://github.com/tj/consolidate.js/#supported-template-engines.

Contributing

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

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

License

MIT

Keywords

FAQs

Package last updated on 12 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc