# wintersmith

> A flexible static site generator.

Latest version **2.5.0** (published 2018-11-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install wintersmith
pnpm add wintersmith
yarn add wintersmith
bun add wintersmith
```

Provides the command `wintersmith`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.5.0 |
| Published | 2018-11-19 |
| First published | 2012-02-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 18 |
| Unpacked size | 991.6 KB |
| Known vulnerabilities | 0 (+7 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3478 |
| Author | Johan Nordberg |
| Maintainers | jnordberg |
| Keywords | static, generator, markdown, pug |

## Links

- npm: https://www.npmjs.com/package/wintersmith
- Repository: https://github.com/jnordberg/wintersmith
- Homepage: https://github.com/jnordberg/wintersmith#readme
- Issues: https://github.com/jnordberg/wintersmith/issues
- npm.io page: https://npm.io/package/wintersmith

## Dependencies (18)

- [ncp](https://npm.io/package/ncp.md) ^2.0.0
- [npm](https://npm.io/package/npm.md) ^6.4.1
- [pug](https://npm.io/package/pug.md) ^2.0.3
- [mime](https://npm.io/package/mime.md) ^2.3.1
- [async](https://npm.io/package/async.md) ^2.6.1
- [chalk](https://npm.io/package/chalk.md) ^2.4.1
- [slugg](https://npm.io/package/slugg.md) ^1.2.1
- [marked](https://npm.io/package/marked.md) ^0.5.1
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [rimraf](https://npm.io/package/rimraf.md) ^2.6.2
- [js-yaml](https://npm.io/package/js-yaml.md) ^3.12.0
- [winston](https://npm.io/package/winston.md) ^3.1.0
- [chokidar](https://npm.io/package/chokidar.md) ^2.0.4
- [minimist](https://npm.io/package/minimist.md) ^1.2.0
- [minimatch](https://npm.io/package/minimatch.md) ^3.0.3
- [highlight.js](https://npm.io/package/highlight.js.md) ^9.13.1
- [coffee-script](https://npm.io/package/coffee-script.md) ^1.12.7
- [server-destroy](https://npm.io/package/server-destroy.md) ^1.0.1

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 2.5.0 (latest) — 2018-11-19
- 2.4.1 — 2017-06-17
- 2.4.0 — 2017-06-15
- 2.3.6 — 2016-12-13
- 2.3.5 — 2016-12-11
- 2.3.4 — 2016-12-11
- 2.3.3 — 2016-09-15
- 2.3.2 — 2016-06-05
- 2.3.1 — 2016-02-29
- 2.3.0 — 2016-02-24
- 2.2.5 — 2016-01-02
- 2.2.4 — 2015-11-04
- 2.2.3 — 2015-10-23
- 2.2.2 — 2015-10-23
- 2.2.1 — 2015-07-19
- … 34 more at https://npm.io/package/wintersmith/versions

## README

#![Wintersmith](http://wintersmith.io/images/wintersmith.svg)

Wintersmith is a simple yet flexible static site generator. It takes contents (markdown, less, scripts, etc), transforms them using plugins and outputs a static website (html, css, images, etc) that you can host anywhere.

It ships with plugins for [markdown](http://daringfireball.net/projects/markdown/) and [pug templates](https://github.com/pugjs/pug), if you need something else check the [plugin listing][plugin-listing] or [write your own][plugin-guide]!

## Resources

 * [Project site][website]
 * [API Documentation][docs]
 * [Wiki][wiki]
 * [stackoverflow tag](http://stackoverflow.com/questions/tagged/wintersmith)
 * IRC - **#wintersmith** on freenode

[website]: http://wintersmith.io "Wintersmith project website"
[docs]: http://wintersmith.io/docs "Wintersmith API Documentation"
[wiki]: https://github.com/jnordberg/wintersmith/wiki "Wintersmith wiki"
[plugin-listing]: https://github.com/jnordberg/wintersmith/wiki/Plugins "Wintersmith plugin listing"
[plugin-guide]: https://github.com/jnordberg/wintersmith/wiki/Writing-plugins "Wintersmith plugin guide"

## Quick-start

First install wintersmith using [npm](http://npmjs.org/):

```bash
$ npm install wintersmith -g
```

This will install wintersmith globally on your system so that you can access the `wintersmith` command from anywhere. Once that is complete run:

```bash
$ wintersmith new <path>
```

Where `<path>` is the location you want the site to be generated. This creates a skeleton site with a basic set of templates and some articles, while not strictly needed it's a good starting point.

Now enter the directory and start the preview server:

```bash
$ cd <path>
$ wintersmith preview
```

At this point you are ready to start customizing your site. Point your browser to `http://localhost:8080` and start editing templates and articles.

When done run:

```bash
$ wintersmith build
```

This generates your site and places it in the `build/` directory - all ready to be copied to your web server!

And remember to give the old `--help` a look :-)

## Overview

A wintersmith site is built up of three main components: contents, views and templates.

Contents is a directory where all the sites raw material goes (markdown files, images, javascript etc). This directory is then scanned to produce what's internally called a ContentTree.

The ContentTree is a nested object built up of ContentPlugins and looks something like this:

```javascript
{
  "myfile.md": {MarkdownPlugin} // plugin instance, subclass of ContentPlugin
  "some-dir/": { // another ContentTree instance
    "image.jpg": {StaticPlugin}
    "random.file": {StaticPlugin}
  }
}
```

![Wintersmith](http://wintersmith.io/images/flow.svg)

This content tree is provided in full to the views when rendering. This gives you a lot of flexibility when writing plugins, you could for example write a plugin that generates a mosaic using images located in a specific directory.

Wintersmith comes with a default Page plugin that renders markdown content using templates. This plugin takes markdown (combined with some metadata, more on this later) compiles it and provides it to a template along with the content tree and some utility functions.

This brings us to the second component, the template directory. All templates found in this directory are loaded and are also passed to the content plugins when rendering.

By default only `.pug` templates are loaded, but you can easily add template plugins to use a template engine of your choosing.

Check the `examples/` directory for some inspiration on how you can use wintersmith or the [showcase](https://github.com/jnordberg/wintersmith/wiki/Showcase) to see what others are doing.

## Configuration

Configuration can be done with command-line options, a config file or both. The config file will be looked for as `config.json` in the root of your site (you can set a custom path using `--config`).

### Options

Name         | Default         | Description
-------------|-----------------|-----------------------------------------------
contents     | `./contents`    | contents directory location
templates    | `./templates`   | templates directory location
views        | `null`          | views directory location, optional
locals       | `{}`            | global site variables, can also be a path to a json file
require      | `{}`            | modules to load and add to locals. e.g. if you want underscore as `_` you would say `{"_": "underscore"}`
plugins      | `[]`            | list of plugins to load
ignore       | `[]`            | list of files or pattern to ignore
output       | `./build`       | output directory, this is where the generated site is output when building
filenameTemplate | `:file.html`| outputs filenames and paths according to a template. ([documentation](https://github.com/jnordberg/wintersmith/wiki/Page-Plugin#filename-templating))
introCutoffs | `['<span class="more', '<h2', '<hr']` | list of strings to search for when determining if a page has an intro
baseUrl      | `/`             | base url that site lives on, e.g. `/blog/`.
hostname     | `null`          | hostname to bind preview server to, null = INADDR_ANY
port         | `8080`          | port preview server listens on

All paths can either be relative or absolute. Relative paths will be resolved from the working directory or `--chdir` if set.

## Content Plugins

ContentPlugins transform content, each item in the content tree is represented by a ContentPlugin instance. Content plugins can be created from files matching a glob pattern or by generators.

The ContentPlugin class is that all content plugins inherit from. Subclasses have to implement the `getFilename` and `getView` instance methods and the `fromFile` class method - more info in the [plugin guide][plugin-guide].

All content plugins have the following properties (a property in wintersmith is simply a shortcut to a getter. i.e. `item.filename` is the same as calling `item.getFilename()`)

Property     | Getter signature | Description
-------------|------------------|---------------------
filename     | `getFilename()`  | filename content will be rendered to
view         | `getView()`      | function used to render the plugin, e.g. the page plugin uses a view that passes the plugin and locals to a template
url          | `getUrl(base)`   | url for the content. *base* is from where this url will be resolved and defaults to `config.baseUrl`. for example you can call `content.getUrl('http://myiste.com')` to get a permalink to that content

## The Page plugin

Wintersmith ships with a page plugin. This plugin is what the markdown page and many other content plugins build upon.

### Model

The Page model (inherits from ContentPlugin)

Properties:

Name         | Description
-------------|------------
metadata     | object containing the pages metadata
title        | `metadata.title` or `Untitled`
date         | Date object created from `metadata.date` if set, unix epoch time if not
rfc822date   | a rfc-822 formatted string made from `date`
body         | markdown source
html         | parsed markdown as html


A MarkdownPage is either a markdown file with metadata on top or a json file located in the contents directory.

```markdown
---
title: My first post
date: 2012-12-12 12:12
author: John Hjort <foo@bar.com>
template: article.pug
----

# Hello friends!

Life is wonderful, isn't it?

```

or use json to simply pass metadata to a template:

```json
{
  "template": "template.pug",
  "stuff": {
  	"things": 123,
  	"moar": [1, 2, 3]
  }
}
```

Pages are by default rendered using the `template` view. This view passes the page to the template provided in the metadata. Omitting the template key or setting it to `none` will cause the page not to be rendered.

### Links

All relative links in the markdown will be resolved correctly when rendering. This means you can just place *image.png* in the same directory and simply include it in your markdown as `![my image](image.png)`

This is especially convenient when using a markdown editor (read [Mou](http://mouapp.com/) if you're on a mac).

### Metadata

Metadata is parsed using [js-yaml](https://github.com/nodeca/js-yaml) and will be accessible in the template as `page.metadata`.

There are two special metadata keys, The first one is `template` which specifies what template to render the page with. If the key is omitted or set to `none` the page will not be rendered (but still available in the content tree).

The second one is `filename` which can be used to override the output filename of the page. See [filename templating](https://github.com/jnordberg/wintersmith/wiki/Page-Plugin#filename-templating) for advanced usage.

### Templates

When a page is rendered to a template the page instance is available as `page` in the template context. The content tree is also available as `contents` and `config.locals` is the root object.

## Plugins

A plugin is a function that's called with the wintersmith environment and a callback.

Plugins are loaded by adding a "require id" to `config.plugins`. This can be a path, local- or global module.
It works just like you would expect a `require()` call to.

Plugin example:

```coffeescript
fs = require 'fs'

module.exports = (env, callback) ->

  class SimonSays extends env.ContentPlugin

    constructor: (@filepath, text) ->
      @text = "Simon says: #{ text }"

    getFilename: -> @filepath.relative # relative to content directory

    getView: -> (env, locals, contents, templates, callback) ->
      callback null, new Buffer @text

  SimonSays.fromFile = (filepath, callback) ->
    fs.readFile filepath.full, (error, buffer) ->
      if error
        callback error
      else
        callback null, new SimonSays filepath, buffer.toString()

  env.registerContentPlugin 'text', '**/*.txt', SimonSays
  callback() # tell the plugin manager we are done
```

See the [plugin guide][plugin-guide] for more info.

## Using wintersmith programmatically

example:

```javascript

var wintersmith = require('wintersmith');

// create the sites environment, can also be called with a config object. e.g.
// {contents: '/some/contents', locals: {powerLevel: 10}}, ..}
var env = wintersmith('/path/to/my/config.json');

// build site
env.build(function(error) {
  if (error) throw error;
  console.log('Done!');
});

// preview
env.preview(function(error, server) {
  if (error) throw error;
  console.log('Server running!');
});

// do something with the content tree
env.load(function(error, result) {
  if (error) throw error;
  console.log('Contents loaded!');
});

```

Check the source or [api docs][docs] for a full list of methods.

## About

Wintersmith is written by [Johan Nordberg](http://johan-nordberg.com) using [CoffeeScript](http://coffeescript.org/) and licensed under the [MIT-license](http://en.wikipedia.org/wiki/MIT_License).

The name is a nod to [blacksmith](https://github.com/flatiron/blacksmith) which inspired this project.

---
_Source: https://npm.io/package/wintersmith · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
