• Stars
    star
    3,504
  • Rank 12,149 (Top 0.3 %)
  • Language
    CoffeeScript
  • License
    MIT License
  • Created over 12 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A flexible static site generator

#Wintersmith

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 and pug templates, if you need something else check the plugin listing or write your own!

Resources

Quick-start

First install wintersmith using npm:

$ 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:

$ 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:

$ 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:

$ 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:

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

Wintersmith

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

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.

---
title: My first post
date: 2012-12-12 12:12
author: John Hjort <[email protected]>
template: article.pug
----

# Hello friends!

Life is wonderful, isn't it?

or use json to simply pass metadata to a template:

{
  "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 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.

Plugin example:

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 for more info.

Using wintersmith programmatically

example:

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 for a full list of methods.

Contributing

To run a development that compiles the coffee script files on the fly use the ./bin/dev/cli command. The chdir -C <path> flag is handy for pointing it to a test project to experiment with.

About

Wintersmith is written by Johan Nordberg using CoffeeScript and licensed under the MIT-license.

The name is a nod to blacksmith which inspired this project.

More Repositories

1

gif.js

JavaScript GIF encoding library
JavaScript
4,580
star
2

irccloudapp

Standalone IRCCloud desktop client for OS X
Objective-C
150
star
3

wsrpc

node.js/browser protobuf rpc over binary websockets
TypeScript
101
star
4

sublime-colorpick

Color picker plugin for Sublime Text 2 and 3 (Mac OS X)
Python
96
star
5

FingerMgmt

MultitouchSupport.framework demo application
Objective-C
83
star
6

dsteem

Steem blockchain RPC client
TypeScript
82
star
7

browsernizr

Modernizr require wrapper for use with browserify
JavaScript
66
star
8

wsq

Streaming websocket task queue
CoffeeScript
53
star
9

leeroy

Docker build bot
TypeScript
35
star
10

selfsteem

Self-hosted steem blockchain powered blog
TypeScript
31
star
11

triggy

Intervalometer for WiFi enabled Canon DSLRs
Swift
28
star
12

dreamcanvas

DeepDream experiment
TypeScript
18
star
13

GLSLWASMGIF

JavaScript
16
star
14

geometry.js

JavaScript library for working with objects in a two-dimensional coordinate system.
JavaScript
16
star
15

yichan

Xiaomi Yi Camera control library
CoffeeScript
16
star
16

nsync

Bye bye bye rsync
CoffeeScript
13
star
17

yikun

Command line tool for controlling a Xiaomi Yi camera
CoffeeScript
10
star
18

glslify-bare

glslify browserify transform for .glsl files
JavaScript
9
star
19

minecraft-replicator

Self-replicating machine in Minecraft using ComputerCraft
Lua
9
star
20

wintersmith-livereload

LiveReload plugin for Wintersmith
JavaScript
9
star
21

wintersmith-plugin

Wintersmith plugin template
CoffeeScript
9
star
22

color-pick

Command line wrapper around OS X built in color picker.
Objective-C
9
star
23

steemaccount

Steem account creation tool
TypeScript
8
star
24

wintersmith-less

less plugin for wintersmith
CSS
7
star
25

wintersmith-browserify

browserify plugin for wintersmith
CoffeeScript
6
star
26

wintersmith-swig

Swig templating plugin for wintersmith
CoffeeScript
6
star
27

steembench

small tool that helps you select which steem node to use
TypeScript
5
star
28

rpcit

Command-line Steem-flavoured JSON-RPC 2.0 Client
TypeScript
5
star
29

milight-ble

Library for controlling MiLight/LimitlessLED Bluetooth RGB LED bulbs
CoffeeScript
5
star
30

wintersmith-i18n

i18n plugin for Wintersmith
JavaScript
5
star
31

svelte-qr

Crisp and fast SVG QR code generator for svelte
TypeScript
4
star
32

YACachedLayer

A caching Core Animation layer
Objective-C
4
star
33

moochart

MooTools charting library
JavaScript
3
star
34

geoface

Facebook Geolocation Chatroulette made during the Facebook Mobile Hack
3
star
35

service-template

node.js microservice template
TypeScript
3
star
36

wintersmith-redirect

Wintersmith plugin that provides url redirections where headers cannot be modified
CoffeeScript
3
star
37

gophoto

libgphoto2 bindings for go
Go
3
star
38

ninja

Slack robot
Go
2
star
39

webapp

A web application skeleton ready to start developing with coffee-script and jacker
JavaScript
2
star
40

mootools-konami

Konami Code event for MooTools
JavaScript
2
star
41

jacker

CommonJS compatible JavaScript packager for web applications
JavaScript
2
star
42

qr-svg

Lightweight SVG QR code generator in JavaScript
TypeScript
2
star
43

wintersmith-sassy

SASS plugin for wintersmith
CoffeeScript
2
star
44

wsq-server

Standalone wsq server
JavaScript
2
star
45

wintersmith-static

Static file globs for wintersmith
JavaScript
1
star
46

mapgallery

proof of concept
1
star
47

purgatory

Fast and easy html code cleaning using DOM
1
star
48

AdventOfCode2015

http://adventofcode.com
Swift
1
star
49

wintersmith-jacker

Jacker (javascript packager) plugin for wintersmith
CoffeeScript
1
star
50

nsync-sftp

sftp transport for nsync
JavaScript
1
star
51

jnordberg

1
star
52

polylactide

Template for working with polymer web components in wintersmith using browserify and stylus
HTML
1
star
53

snoopdog

Simple tracking pixels with node.js and leveldb
CoffeeScript
1
star