Skip to content
Neil Freeman edited this page Nov 5, 2015 · 5 revisions

Let's say you have the following directories:

_content # content pages with YAML front matter
  index.html
  faq.html
  page1.html

_data # data files in JSON, YAML or INI
  data.yaml 

_helpers # JS files with handlebars helpers
  helpers.js

_layouts # Handlebars templates
  myLayout.handlebars

_partials # Handlebars partials
  partials.handlebars

Now, you want your built pages to appear in a directory called build. A sample Makefile with Taft might look something like this:

.PHONY: all
all: _content/index.html _content/faq.html _content/page1.html

# Build a single page
build/%.html: _content/%.html _helpers/helpers.js _layouts/myLayout.handlebars _data/data.yaml _partials/partials.handlebars
	taft --helper _helpers/helpers.js \
             --partial '_partials/*' \
             --layout '_layouts/*' \
             --default-layout myLayout \
             --data _data/data.yaml

With this, you can write make, and your three pages will be built one at a time. If you change one of the helpers, partials or data files abd run make again, you'll get new files. If you change just '_content/ files, only the corresponding file will be rebuilt.

If you have more than a few files, this isn't a good model, since you have to manually add files to the Makefile, and building one file at a time is slow. Here's a task to build all the files at once:

.PHONY: build
build:
	taft --helper _helpers/helpers.js \
             --partial '_partials/*' \
             --layout '_layouts/*' \
             --default-layout myLayout \
             --data _data/data.yaml \
             --dest-dir build \
             '_content/*'

Clone this wiki locally