README.md

#

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.

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 .jade 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 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

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.

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.

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 if you're on a mac).

Metadata

Metadata is parsed using 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 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.