Skip to content
Neil Freeman edited this page Jan 9, 2016 · 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 dest. A sample Makefile with Taft might look something like this:

.PHONY: all
all: $(wildcard content/*)

# Build a single page
dest/%.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.handlebars \
             --data data/data.yaml \
             $< -o $@

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're building one file at a time. Here's a task to build all the files at once:

.PHONY: all
all:
	taft --helper helpers/helpers.js \
             --partial 'partials/*' \
             --layout 'layouts/*' \
             --default-layout myLayout.handlebars \
             --data 'data/*' \
             --dest-dir dest \
             'content/*'

When make is run here, all the content pages will be rebuilt in the dest directory.

Clone this wiki locally