Static site generators are in fashion for good reasons. The resulting pages are easy to host, fast and extremely low on maintenance while being sufficient for many use cases.
As I learned when setting up my blog, writing a simple script myself is faster and more satisfying than learning one of the other site builders and customizing it to my needs.
This time, I only need a plain site without automatically updated timestamps or an RSS-feed, so I can go even simpler than by blog script.
Basic setup
To get the site into a working state, I require the following functionality:
- All input files reside in the
source
directory, in the same layout as I want them in the output. - During processing, add a header to all HTML files.
- Copy all other files to the
build
directory as they are.
Each of these points results in one rule in the Makefile:
# The `build` target depends on all output files in the `build` directory. It
# does not do anything by itself, but causes one of the following rules to be
# applied for each file.
build: $(patsubst source/%,build/%,$(shell find source -type f))
# For each .html file do `cat header.html $input > $output`.
build/%.html: source/%.html header.html Makefile
@mkdir -p $(dir $@)
cat header.html $< > $@
# Copy all other files without changes.
build/%: source/%
cp $< $@
With a corresponding header.html